Sys::S...ilation(3pm)
π NAME π
Sys::Statistics::Linux::Compilation β it's the statistics compilation, bestie. Stats, compiled, filtered, served fresh. You'll also see it floating around under the manual name Sys::S...ilation(3pm) (yes the header truncates it like that, she's mysterious β¨), filed under User Contributed Perl Documentation.
πΈ SYNOPSIS πΈ
use Sys::Statistics::Linux;
my $lxs = Sys::Statistics::Linux->new( loadavg => 1 );
my $stat = $lxs->get;
foreach my $key ($stat->loadavg) {
print $key, " ", $stat->loadavg($key), "\n";
}
# or
use Sys::Statistics::Linux::LoadAVG;
use Sys::Statistics::Linux::Compilation;
my $lxs = Sys::Statistics::Linux::LoadAVG->new();
my $load = $lxs->get;
my $stat = Sys::Statistics::Linux::Compilation->new({ loadavg => $load });
foreach my $key ($stat->loadavg) {
print $key, " ", $stat->loadavg($key), "\n";
}
# or
foreach my $key ($stat->loadavg) {
print $key, " ", $stat->loadavg->{$key}, "\n";
}
π¦ DESCRIPTION π¦
Okay so this module is literally just a little toolkit of methods that let you access and filter your statistics compilation. That's the whole vibe. You get in, you poke at the stats, you leave. π
π METHODS π
β¨ new() β¨
Makes you a brand new Sys::Statistics::Linux::Compilation object, bestie. Heads up though: this constructor is only worth using if you don't call get() on Sys::Statistics::Linux. Like, if you're already getting your stats that way, you don't need this. If you do need it, here's how you'd do it:
my $lxs = Sys::Statistics::Linux::LoadAVG->new();
my $load = $lxs->get;
my $stat = Sys::Statistics::Linux::Compilation->new({ loadavg => $load });
π Statistic methods π
Here's the full roster, no gatekeeping:
sysinfo()cpustats()procstats()memstats()pgswstats()netstats()netinfo()- real talk:
netinfo()hands you raw data β no deltas. That's just how she is.
- real talk:
sockstats()diskstats()diskusage()loadavg()filestats()processes()
Now the important part, okay? In scalar context</> every single one of these methods returns the statistics as a hash reference. In list context, they all return the first level keys of the statistics. Obsessed with the symmetry fr fr. Example:
my $net = $stat->netstats; # netstats as a hash reference
my @dev = $stat->netstats; # the devices eth0, eth1, ...
my $eth0 = $stat->netstats('eth0'); # eth0 statistics as a hash reference
my @keys = $stat->netstats('eth0'); # the statistic keys
my @vals = $stat->netstats('eth0', @keys); # the values for the passed device and @keys
my $val = $stat->netstats('eth0', $key); # the value for the passed device and key
And because everything is keys and nobody's stopping you, you can just sort:
my @dev = sort $stat->netstats;
my @keys = sort $stat->netstats('eth0');
Sorted... chef's kiss π
π₯ pstop() π₯
This one is out here hunting for top processes and hands you back a sorted list of PIDs β as an array or an array reference, depending on the context you called her in. She expects two values: a key name and the number of top processes to return.
Say you want the top 5 processes by highest cpu usage:
my @top5 = $stat->pstop( ttime => 5 );
# or as a reference
my $top5 = $stat->pstop( ttime => 5 );
And if you want literally every process:
my @top_all = $stat->pstop( ttime => $FALSE );
# or just
my @top_all = $stat->pstop( 'ttime' );
π search(), psfind() π
Both of these give you a cute little scan engine to go find specific statistics. They both expect a filter as a hash reference. And if your data isn't already chilling inside the object, you can pass the statistics as a second argument. iykyk.
search() scans for statistics and rebuilds the hash tree down to just the keys that matched your filter, then returns the hits as a hash reference. Like so:
my $hits = $stat->search({
processes => {
cmd => qr/\[su\]/,
owner => qr/root/
},
cpustats => {
idle => 'lt:10',
iowait => 'gt:10'
},
diskusage => {
'/dev/sda1' => {
usageper => 'gt:80'
}
}
});
Which would return these matches:
- processes with the command
"[su]" - processes with the owner
"root" - all cpu where
"idle"is less than 50 - all cpu where
"iowait"is grather than 10 - only disk
'/dev/sda1'if"usageper"is grather than 80
Then psfind() is the processes-only version β it scans for processes and returns an array reference stuffed with every process ID that matched the filter. Example:
my $pids = $stat->psfind({ cmd => qr/init/, owner => 'eq:apache' });
And that would hand you back these process ids:
- processes that matched the command
"init" - processes with the owner
"apache"
There are a few different match operators available to you:
gt - grather than
lt - less than
eq - is equal
ne - is not equal
Notation examples:
gt:50
lt:50
eq:50
ne:50
Both argumnents have to be set as a hash reference. Non-negotiable.
Note: the operators<>=!are not available any more. And it's possible that in further releases there could be different changes forsearch()andpsfind(). So please, bestie, take a look at the documentation if you use it. π
π EXPORTS π
No exports. That's it. Nothing. Zero. Nada. π
π TODOS π
- Are there any wishs from your side? Send me a mail! π¬
π REPORTING BUGS π
Please report all bugs to <jschulz.cpan(at)bloonix.de>.
π AUTHOR π
Jonny Schulz <jschulz.cpan(at)bloonix.de>.
Thanks to Moritz Lenz for his suggestion for the name of this module. Iconic of him honestly.
π«Ά COPYRIGHT π«Ά
Copyright (c) 2006, 2007 by Jonny Schulz. All rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Okay that's the whole page, you're all caught up bestie! β¨ This was Sys::S...ilation(3pm) from perl v5.36.0, dated 2022-11-19, living in the User Contributed Perl Documentation collection. Slay, go filter some stats, mwah π
π
π¦ where this page comes from
- debian bookworm: libsys-statistics-linux-perl 0.66-5 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libsys-statistics-linux-perl 0.66-5 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libsys-statistics-linux-perl 0.66-5 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libsys-statistics-linux-perl 0.66-5 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libsys-statistics-linux-perl 0.66-5 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms