Sys::S...uStats(3pm)

πŸ“¦
version 0.66 Β· 6 versions
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– Sys::Statistics::Linux::CpuStats β€” the perl manual page, bestie edition πŸ’–

okay so this is Sys::Statistics::Linux::CpuStats, and it lives in the User Contributed Perl Documentation section of the perl man pages (you know, the 3pm girlies). she collects linux cpu statistics and she is lowkey iconic for it. let's get into it ✨


🌸 NAME 🌸

Sys::Statistics::Linux::CpuStats β€” Collect linux cpu statistics. that's it, that's the job. she gathers the cpu tea from your machine. periodt πŸ’…


✨ SYNOPSIS ✨

the basic serve:

use Sys::Statistics::Linux::CpuStats;

my $lxs = Sys::Statistics::Linux::CpuStats->new;
$lxs->init;
sleep 1;
my $stats = $lxs->get;

Or, if you're feeling fancy with a file:

my $lxs = Sys::Statistics::Linux::CpuStats->new(initfile => $file);
$lxs->init;
my $stats = $lxs->get;

πŸ¦‹ DESCRIPTION πŸ¦‹

Sys::Statistics::Linux::CpuStats gathers cpu statistics from the virtual /proc filesystem (aka procfs). yes bestie, it's reading /proc and pulling the numbers out, that's the whole vibe.

For more information read the documentation of the front-end module Sys::Statistics::Linux. (that's the main character, this one is her supporting role 🫢)


πŸ‘‘ CPU STATISTICS πŸ‘‘

Generated by /proc/stat for each cpu (cpu0, cpu1 ...). and listen, a cpu with no number attached is the summary. the group chat total, if you will.

  • user β€” Percentage of CPU utilization at the user level.
  • nice β€” Percentage of CPU utilization at the user level with nice priority.
  • system β€” Percentage of CPU utilization at the system level.
  • idle β€” Percentage of time the CPU is in idle state.
  • total β€” Total percentage of CPU utilization.

Statistics with kernels >= 2.6. (old kernels, we don't know her πŸ™ˆ)

  • iowait β€” Percentage of time the CPU is in idle state because an I/O operation is waiting to complete.
  • irq β€” Percentage of time the CPU is servicing interrupts.
  • softirq β€” Percentage of time the CPU is servicing softirqs.
  • steal β€” Percentage of stolen CPU time, which is the time spent in other operating systems when running in a virtualized environment (>=2.6.11).

πŸ’… METHODS πŸ’…

🌈 new()

Call new() to create a new object. brand new baby object, fresh out the box ✨

my $lxs = Sys::Statistics::Linux::CpuStats->new;

Maybe you want to store/load the initial statistics to/from a file:

my $lxs = Sys::Statistics::Linux::CpuStats->new(initfile => '/tmp/cpustats.yml');

If you set initfile it's not necessary to call sleep before get(). no sleeping on the job, we love efficiency 😌

It's also possible to set the path to the proc filesystem.

 Sys::Statistics::Linux::CpuStats->new(
    files => {
        # This is the default
        path => '/proc'
        stat => 'stat',
    }
);
note that path => '/proc' and stat => 'stat' are literally marked as the default right there in the comment, so don't come for me if you change them and things get weird πŸŽ€

πŸ“ init()

Call init() to initialize the statistics.

$lxs->init;

she needs a lil setup moment before she performs, okay?

⭐ get()

Call get() to get the statistics. get() returns the statistics as a hash reference.

my $stats = $lxs->get;

hash ref, bestie. dereference accordingly πŸ’œ

🧚 raw()

Get raw values.


πŸ’€ EXPORTS πŸ’€

No exports.

not a single one. nothing to import. we keep it contained πŸ™ˆ


πŸ”₯ SEE ALSO πŸ”₯

go read that one too, it's giving lore.


😭 REPORTING BUGS 😭

Please report all bugs to <jschulz.cpan(at)bloonix.de>.

like genuinely please tell him, don't just suffer in silence 🫢


🌸 AUTHOR 🌸

Jonny Schulz <jschulz.cpan(at)bloonix.de>.


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.


and that's the whole page, no cap. this lil manpage came from perl v5.36.0, dated 2022-11-19, filed under Sys::S...uStats(3pm) in the User Contributed Perl Documentation ✨ go collect those cpu stats, queen πŸ‘‘πŸ’…

πŸ“¦ where this page comes from