-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathCPUSummary.pm
More file actions
27 lines (22 loc) · 763 Bytes
/
CPUSummary.pm
File metadata and controls
27 lines (22 loc) · 763 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package Collectd::Plugin::CPUSummary;
use Collectd qw(:all);
use Sys::CPU;
#
# Add the following line to /usr/share/collectd/types.db:
# cpusummary user:COUNTER:U:U,nice:COUNTER:U:U,system:COUNTER:U:U,idle:COUNTER:U:U,iowait:COUNTER:U:U,irq:COUNTER:U:U,softirq:COUNTER:U:U,cpucount:GAUGE:U:U
#
plugin_register (TYPE_READ, 'cpusummary', 'my_read');
my $cpus = Sys::CPU::cpu_count();
sub my_read
{
open(F,"/proc/stat");
my $line = <F>;
close(F);
chomp($line);
my $vl = {};
$vl->{'plugin'} = 'cpusummary';
$vl->{'type'} = 'cpusummary';
$vl->{'values'} = [ (map { sprintf("%d",$_/$cpus); } (split(/\s+/,$line))[1..7]), $cpus ];
plugin_dispatch_values($vl);
return 1;
}