NAME
Sys::Monitor::Lite - Lightweight system monitoring toolkit with JSON/YAML output
SYNOPSIS
use Sys::Monitor::Lite qw(collect_all to_json);
print Sys::Monitor::Lite::to_json(Sys::Monitor::Lite::collect_all());
DESCRIPTION
A minimal system monitor that outputs structured JSON, YAML, or Prometheus text exposition for easy automation and integration with jq-lite, yq, Prometheus scrape targets, or other tools that consume structured logs.
FUNCTIONS
collect_all
my $data = Sys::Monitor::Lite::collect_all();
Collects all available metrics and returns a hash reference keyed by metric name. This is a convenience wrapper around "collect" with no arguments.
collect
my $subset = Sys::Monitor::Lite::collect(['cpu', 'mem']);
Collects the metrics listed in the array reference (or list). Unknown metrics are ignored. The returned value matches the structure of "collect_all" but contains only the requested keys.
available_metrics
my @names = Sys::Monitor::Lite::available_metrics();
Returns a sorted list of metric names that the module can collect.
metrics_from_thresholds
my @metrics = Sys::Monitor::Lite::metrics_from_thresholds(
['mem.used_pct>80'],
['load.1min>2'],
);
Parses threshold expressions and returns the top-level metrics (e.g. mem, load) that they reference. This is useful for preloading only the data needed for threshold checks.
evaluate_thresholds
my $result = Sys::Monitor::Lite::evaluate_thresholds(
$data,
warn => ['mem.used_pct>80'],
crit => ['mem.used_pct>90'],
);
Evaluates warning/critical threshold expressions against a collected metrics hashref and returns a structure containing status (0/1/2), human-readable label, and a formatted message suitable for CLI output.
to_json
my $json = Sys::Monitor::Lite::to_json($data, pretty => 1);
Serialises the supplied data structure to a JSON string using JSON::PP. Pass pretty => 1 to enable human-readable output.
to_yaml
my $yaml = Sys::Monitor::Lite::to_yaml($data);
Serialises the supplied data structure to a YAML string using a minimal built-in emitter.
to_prometheus
my $text = Sys::Monitor::Lite::to_prometheus($data, prefix => 'sysmon_');
Serialises the supplied data structure into Prometheus exposition format, converting keys to snake_case gauge metrics. Pass prefix to prepend a metric namespace (e.g. sysmon_), labels to include fixed labels, and timestamp => 1 to append the sample timestamp to each metric line.
EXPORT
This module does not export any symbols by default. Functions can be called with their fully-qualified names, e.g. Sys::Monitor::Lite::collect_all().
AUTHOR
Shingo Kawamura <pannakoota1@gmail.com>
COPYRIGHT AND LICENSE
This software is copyright (c) 2025 by Shingo Kawamura.
This is free software; you can redistribute it and/or modify it under the same terms as the MIT license included with this distribution.