mirror of
https://github.com/munin-monitoring/contrib.git
synced 2025-07-24 18:07:20 +00:00
remove plugins included in the main munin distribution
This commit is contained in:
parent
a9cd70c4ce
commit
8e3033a0fa
13 changed files with 0 additions and 2027 deletions
|
@ -1,146 +0,0 @@
|
|||
#! /usr/bin/perl -w
|
||||
|
||||
=head1 NAME
|
||||
|
||||
buddyinfo - Plugin to monitor memory fragmentation on Linux systems.
|
||||
|
||||
=head1 APPLICABLE SYSTEMS
|
||||
|
||||
Linux 2.6
|
||||
|
||||
=head1 CONFIGURATION
|
||||
|
||||
None needed.
|
||||
|
||||
=head1 INTERPRETATION
|
||||
|
||||
Linux manages virtual memory on a page granularity. There are some operations
|
||||
however that require physically contiguous pages to be allocated by the kernel.
|
||||
Such allocations may fail if the memory gets fragmented and even though there
|
||||
are enough pages free, but they are not contiguous.
|
||||
|
||||
This plugin monitors the amount of contiguous areas, called higher order pages.
|
||||
The order means the exponent of two of the size of the area, so order 2 means
|
||||
2^2 = 4 pages.
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
See C<Documentation/filesystems/proc.txt> in the Linux source tree for the
|
||||
description of the buddyinfo file.
|
||||
|
||||
=head1 MAGIC MARKERS
|
||||
|
||||
#%# family=manual
|
||||
#%# capabilities=autoconf
|
||||
|
||||
=head1 AUTHOR
|
||||
|
||||
Gábor Gombás <gombasg@sztaki.hu>
|
||||
|
||||
=head1 LICENSE
|
||||
|
||||
GPLv2 or later
|
||||
|
||||
=cut
|
||||
|
||||
use strict;
|
||||
use Munin::Plugin;
|
||||
use POSIX;
|
||||
use Carp;
|
||||
|
||||
need_multigraph();
|
||||
|
||||
if ($ARGV[0] and $ARGV[0] eq 'autoconf') {
|
||||
if (-f "/proc/buddyinfo") {
|
||||
print "yes\n";
|
||||
}
|
||||
else {
|
||||
print "no (/proc/buddyinfo is missing)\n";
|
||||
}
|
||||
exit 0;
|
||||
}
|
||||
|
||||
# The most common page size is 4k, but it is not universal
|
||||
my $pagesize = POSIX::sysconf(&POSIX::_SC_PAGESIZE) / 1024;
|
||||
|
||||
my $zones = {};
|
||||
|
||||
open(FH, '< /proc/buddyinfo')
|
||||
or croak "Failed to open '/proc/buddyinfo': $!";
|
||||
while (my $line = <FH>) {
|
||||
chomp $line;
|
||||
|
||||
$line =~ m/Node (\d+), zone\s+(\S+)\s+(\S.*)$/;
|
||||
my $name = "Node $1, zone $2";
|
||||
my @cnt = split(/ +/, $3);
|
||||
$zones->{$name} = \@cnt;
|
||||
}
|
||||
close FH;
|
||||
|
||||
my $totals = [];
|
||||
foreach my $zone (keys %$zones) {
|
||||
for my $i (0 .. $#{$zones->{$zone}}) {
|
||||
$totals->[$i] += $zones->{$zone}->[$i]
|
||||
}
|
||||
}
|
||||
|
||||
sub do_config {
|
||||
print "multigraph buddyinfo\n";
|
||||
print "graph_title Memory fragmentation\n";
|
||||
print "graph_args --base 1024 --lower-limit 0\n";
|
||||
print "graph_vlabel pages free\n";
|
||||
print "graph_category system\n";
|
||||
print "graph_info This graph shows the number of free pages of different size\n";
|
||||
print "graph_order " . join(' ', map { "order$_" } (0 .. $#{$totals})) . "\n";
|
||||
for my $i (0 .. $#{$totals}) {
|
||||
print "order$i.label Order $i\n";
|
||||
print "order$i.info Number of order $i (" . ($pagesize * 2 ** $i) . " KiB) pages\n";
|
||||
print "order$i.type GAUGE\n";
|
||||
print "order$i.draw LINE2\n";
|
||||
print "order$i.min 0\n";
|
||||
}
|
||||
for my $zone (sort keys %$zones) {
|
||||
my $zoneid = $zone;
|
||||
$zoneid = clean_fieldname($zone);
|
||||
|
||||
print "multigraph buddyinfo.$zoneid\n";
|
||||
print "graph_title Memory fragmentation in $zone\n";
|
||||
print "graph_args --base 1024 --lower-limit 0\n";
|
||||
print "graph_vlabel pages free\n";
|
||||
print "graph_category system\n";
|
||||
print "graph_info This graph shows the number of free pages in $zone\n";
|
||||
print "graph_order " .
|
||||
join(' ', map { "order$_" } (0 .. $#{$zones->{$zone}})) . "\n";
|
||||
for my $i (0 .. $#{$zones->{$zone}}) {
|
||||
print "order$i.label Order $i\n";
|
||||
print "order$i.info Number of order $i (" .
|
||||
($pagesize * 2 ** $i) . " KiB) pages\n";
|
||||
print "order$i.type GAUGE\n";
|
||||
print "order$i.draw LINE2\n";
|
||||
print "order$i.min 0\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sub do_fetch {
|
||||
print "multigraph buddyinfo\n";
|
||||
for my $i (0 .. $#{$totals}) {
|
||||
print "order$i.value " . $totals->[$i] . "\n";
|
||||
}
|
||||
for my $zone (sort keys %$zones) {
|
||||
my $zoneid = $zone;
|
||||
$zoneid =~ tr/ ,/__/;
|
||||
|
||||
print "multigraph buddyinfo.$zoneid\n";
|
||||
for my $i (0 .. $#{$zones->{$zone}}) {
|
||||
print "order$i.value " . $zones->{$zone}->[$i] . "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($ARGV[0] and $ARGV[0] eq 'config') {
|
||||
do_config();
|
||||
exit 0;
|
||||
}
|
||||
|
||||
do_fetch();
|
|
@ -1,974 +0,0 @@
|
|||
#!/usr/bin/perl -w
|
||||
# -*- perl -*-
|
||||
|
||||
=head1 NAME
|
||||
|
||||
cpu - Plugin to monitor CPU usage and frequencies.
|
||||
|
||||
=head1 APPLICABLE SYSTEMS
|
||||
|
||||
All Linux systems, but read below section
|
||||
|
||||
=head1 CONFIGURATION
|
||||
|
||||
The plugin automatically selects which graphics drawing.
|
||||
Charts related to the frequencies of processors depends on the settings of the kernel:
|
||||
Power management and ACPI options -> CPU Frequency scaling -> CPU frequency translation statistics -> Advanced statistics
|
||||
|
||||
=head2 WARNING AND CRITICAL SETTINGS
|
||||
|
||||
You can set warning and critical levels for each of the data
|
||||
series the plugin reports. The following environment variables are
|
||||
used as default for all fields:
|
||||
|
||||
env.warning
|
||||
env.critical
|
||||
|
||||
But each field (system user nice etc...) can be controlled separately:
|
||||
For example:
|
||||
|
||||
env.system_warning 70
|
||||
env.user_warning 70
|
||||
env.idle_critical 1
|
||||
|
||||
Also each field of each cpu can be controlled separately
|
||||
For example:
|
||||
|
||||
env.cpu1_system_warning 70
|
||||
env.cpu0_user_warning 70
|
||||
env.cpu0_idle_critical 1
|
||||
|
||||
Algoritm is easy: for example current graph limit is env.cpu0_idle_critical if defined env.cpu0_idle_critical or env.idle_critical if defined env.idle_critical
|
||||
or env.critical if defined env.critical. Or no limit
|
||||
|
||||
=head1 INTERPRETATION
|
||||
|
||||
The plugin shows each cpu usage in percent, shows the CPU frequency,
|
||||
frequency shift frequencies, the percentage of use of frequencies
|
||||
|
||||
=head1 MAGIC MARKERS
|
||||
|
||||
#%# family=auto
|
||||
#%# capabilities=autoconf
|
||||
|
||||
|
||||
=head1 VERSION
|
||||
|
||||
2.0
|
||||
|
||||
=head1 BUGS
|
||||
|
||||
none known
|
||||
|
||||
=head1 AUTHOR
|
||||
|
||||
Gorlow Maxim aka Sheridan <sheridan@sheridan-home.ru> (email and jabber)
|
||||
|
||||
=head1 LICENSE
|
||||
|
||||
GPLv2
|
||||
|
||||
=cut
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use Munin::Plugin;
|
||||
use Data::Dumper;
|
||||
my @cnames = qw(user nice system idle iowait irq softirq steal guest);
|
||||
my $stat_file = "/proc/stat";
|
||||
my $freq_path = "/sys/devices/system/cpu";
|
||||
my $limits = {};
|
||||
my $cpuinfo = {}; $cpuinfo->{'cpu_count'} = 0;
|
||||
my @stat_file_content = ();
|
||||
my $freq_mul = 1000; # CPU frequency multiplier from kHz to Hz
|
||||
|
||||
|
||||
|
||||
my $graphs =
|
||||
{
|
||||
'cpu_utilisation' => # multigraph
|
||||
{
|
||||
'title' => 'CPU:t: utilisation',
|
||||
'args' => '--base 1000 -r --lower-limit 0 --upper-limit 100',
|
||||
'vlabel' => '%',
|
||||
'scale' => 'no',
|
||||
'info' => 'This graph shows how CPU:t: time is spent :i:'
|
||||
},
|
||||
'cpu_all' => # single
|
||||
{
|
||||
'title' => 'All CPU utilisation',
|
||||
'args' => '--base 1000 -r --lower-limit 0 --upper-limit 100',
|
||||
'vlabel' => '%',
|
||||
'scale' => 'no',
|
||||
'info' => 'This graph shows how CPU time is spent on each processor',
|
||||
'category' => 'cpu'
|
||||
},
|
||||
'cpu_freq_trans' => # multi
|
||||
{
|
||||
'title' => 'CPU frequency transitions',
|
||||
'args' => '--base 1000',
|
||||
'vlabel' => 'count',
|
||||
'scale' => 'no',
|
||||
'info' => 'This graph shows CPU transitions of each processor',
|
||||
},
|
||||
'cpu_freq' => # child of cpu_freq_trans
|
||||
{
|
||||
'title' => 'CPU:t: frequency (total)',
|
||||
'args' => '--base 1000 -r --lower-limit 0 --upper-limit 100',
|
||||
'vlabel' => '% of total',
|
||||
'info' => 'This graph shows CPU:t: frequency :i:',
|
||||
'category' => 'cpu'
|
||||
},
|
||||
'cpu_freq_ps' => # child of cpu_freq_trans
|
||||
{
|
||||
'title' => 'CPU:t: frequency (per secund)',
|
||||
'args' => '--base 1000 -r --lower-limit 0 --upper-limit 100',
|
||||
'vlabel' => '% per secund',
|
||||
'info' => 'This graph shows CPU:t: frequency per secund from last update :i:',
|
||||
'category' => 'cpu'
|
||||
},
|
||||
'cpu_freq_trans_table' => # child of cpu_freq_trans
|
||||
{
|
||||
'title' => 'CPU:t: frequency switches (total)',
|
||||
'args' => '--base 1000 -r --lower-limit 0 --upper-limit 100',
|
||||
'vlabel' => '% of total',
|
||||
'scale' => 'no',
|
||||
'info' => 'This graph shows CPU:t: frequency switches :i:',
|
||||
},
|
||||
'cpu_freq_trans_table_ps' => # child of cpu_freq_trans
|
||||
{
|
||||
'title' => 'CPU:t: frequency switches (per secund)',
|
||||
'args' => '--base 1000 -r --lower-limit 0 --upper-limit 100',
|
||||
'vlabel' => '% per secund',
|
||||
'scale' => 'no',
|
||||
'info' => 'This graph shows CPU:t: frequency switches per secund from last update :i:',
|
||||
}
|
||||
};
|
||||
|
||||
my $transparent = 'CC';
|
||||
my $fields =
|
||||
{
|
||||
'user' =>
|
||||
{
|
||||
'label' => 'User',
|
||||
'info' => 'Normal processes executing in user mode',
|
||||
'type' => 'GAUGE',
|
||||
'draw' => 'AREASTACK',
|
||||
'min' => 0,
|
||||
'max' => 100
|
||||
},
|
||||
'nice' =>
|
||||
{
|
||||
'label' => 'Nice',
|
||||
'info' => 'Niced processes executing in user mode',
|
||||
'type' => 'GAUGE',
|
||||
'draw' => 'AREASTACK',
|
||||
'min' => 0,
|
||||
'max' => 100
|
||||
},
|
||||
'system' =>
|
||||
{
|
||||
'label' => 'System',
|
||||
'info' => 'Processes executing in kernel mode',
|
||||
'type' => 'GAUGE',
|
||||
'draw' => 'AREASTACK',
|
||||
'min' => 0,
|
||||
'max' => 100
|
||||
},
|
||||
'idle' =>
|
||||
{
|
||||
'label' => 'Idle',
|
||||
'info' => 'Twiddling thumbs',
|
||||
'type' => 'GAUGE',
|
||||
'draw' => 'AREASTACK',
|
||||
'colour'=> 'FFFFDD'.$transparent,
|
||||
'min' => 0,
|
||||
'max' => 100
|
||||
},
|
||||
'iowait' =>
|
||||
{
|
||||
'label' => 'I/O wait',
|
||||
'info' => 'Waiting for I/O to complete',
|
||||
'type' => 'GAUGE',
|
||||
'draw' => 'AREASTACK',
|
||||
'min' => 0,
|
||||
'max' => 100
|
||||
},
|
||||
'irq' =>
|
||||
{
|
||||
'label' => 'IRQ',
|
||||
'info' => 'Servicing interrupts',
|
||||
'type' => 'GAUGE',
|
||||
'draw' => 'AREASTACK',
|
||||
'min' => 0,
|
||||
'max' => 100
|
||||
},
|
||||
'softirq' =>
|
||||
{
|
||||
'label' => 'Software IRQ',
|
||||
'info' => 'Servicing software interrupts',
|
||||
'type' => 'GAUGE',
|
||||
'draw' => 'AREASTACK',
|
||||
'min' => 0,
|
||||
'max' => 100
|
||||
},
|
||||
'steal' =>
|
||||
{
|
||||
'label' => 'Steal',
|
||||
'info' => 'Involuntary wait',
|
||||
'type' => 'GAUGE',
|
||||
'draw' => 'AREASTACK',
|
||||
'min' => 0,
|
||||
'max' => 100
|
||||
},
|
||||
'guest' =>
|
||||
{
|
||||
'label' => 'Guest',
|
||||
'info' => 'Running a guest',
|
||||
'type' => 'GAUGE',
|
||||
'draw' => 'AREASTACK',
|
||||
'min' => 0,
|
||||
'max' => 100
|
||||
},
|
||||
'cpu_util' =>
|
||||
{
|
||||
'label' => ':t:',
|
||||
'info' => ':t: utilisation',
|
||||
'type' => 'GAUGE',
|
||||
'draw' => 'LINE0.5',
|
||||
'min' => 0,
|
||||
'max' => 100
|
||||
},
|
||||
'freq_percent' =>
|
||||
{
|
||||
'label' => 'CPU:t: frequency',
|
||||
'info' => 'CPU:t: frequency percent',
|
||||
'type' => 'GAUGE',
|
||||
'draw' => 'LINE0.5',
|
||||
'min' => 0,
|
||||
'max' => 100
|
||||
},
|
||||
'freq_hz' =>
|
||||
{
|
||||
'label' => ':t:',
|
||||
'info' => 'CPU :t: frequency',
|
||||
'type' => 'GAUGE',
|
||||
'draw' => 'AREASTACK',
|
||||
'min' => 0,
|
||||
'max' => 100
|
||||
},
|
||||
'freq_trans' =>
|
||||
{
|
||||
'label' => ':t:',
|
||||
'info' => ':t: frequency transitions',
|
||||
'type' => 'GAUGE',
|
||||
'draw' => 'LINE0.5',
|
||||
'min' => 0
|
||||
},
|
||||
'freq_trans_table' =>
|
||||
{
|
||||
'label' => ':t:',
|
||||
'info' => ':t: frequency switch',
|
||||
'type' => 'GAUGE',
|
||||
'draw' => 'AREASTACK',
|
||||
'min' => 0,
|
||||
'max' => 100
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
# ----------------- main ----------------
|
||||
load_cpuinfo();
|
||||
need_multigraph();
|
||||
remove_unavialabled_counters();
|
||||
|
||||
if (defined($ARGV[0]) and ($ARGV[0] eq 'autoconf'))
|
||||
{
|
||||
printf("%s\n", -e $stat_file ? "yes" : "no (stats not exists)");
|
||||
exit (0);
|
||||
}
|
||||
|
||||
if (defined($ARGV[0]) and ($ARGV[0] eq 'config'))
|
||||
{
|
||||
print_config();
|
||||
exit (0);
|
||||
}
|
||||
|
||||
print_values();
|
||||
#print Dumper prepare_graphs_fields();
|
||||
exit(0);
|
||||
|
||||
# ----------------- sub's ----------------
|
||||
|
||||
# ----------------------- trim whitespace at begin and end of string ------------
|
||||
sub trim
|
||||
{
|
||||
my($string)=@_;
|
||||
for ($string) { s/^\s+//; s/\s+$//; }
|
||||
return $string;
|
||||
}
|
||||
|
||||
|
||||
my $items_exists = {};
|
||||
sub check_exists
|
||||
{
|
||||
my ($t, $cpu_num) = @_[0..1];
|
||||
if (defined($cpu_num))
|
||||
{
|
||||
unless (exists($items_exists->{$t}{$cpu_num}))
|
||||
{
|
||||
if ($t eq 'freq_hz') { $items_exists->{$t}{$cpu_num} = ( -e sprintf("%s/cpu%s/cpufreq/scaling_min_freq" , $freq_path, $cpu_num) and
|
||||
-e sprintf("%s/cpu%s/cpufreq/scaling_cur_freq" , $freq_path, $cpu_num) and
|
||||
-e sprintf("%s/cpu%s/cpufreq/scaling_max_freq" , $freq_path, $cpu_num)); }
|
||||
elsif ($t eq 'freq_trans') { $items_exists->{$t}{$cpu_num} = -e sprintf("%s/cpu%s/cpufreq/stats/time_in_state", $freq_path, $cpu_num); }
|
||||
elsif ($t eq 'freq_times') { $items_exists->{$t}{$cpu_num} = -e sprintf("%s/cpu%s/cpufreq/stats/total_trans" , $freq_path, $cpu_num); }
|
||||
elsif ($t eq 'freq_ttable') { $items_exists->{$t}{$cpu_num} = -e sprintf("%s/cpu%s/cpufreq/stats/trans_table" , $freq_path, $cpu_num); }
|
||||
}
|
||||
return $items_exists->{$t}{$cpu_num};
|
||||
}
|
||||
else
|
||||
{
|
||||
unless(exists($items_exists->{$t}{'total'}))
|
||||
{
|
||||
my $c = 0;
|
||||
for (my $i=0; $i < $cpuinfo->{'cpu_count'}; $i++) { $c++ if (check_exists($t, $i)); }
|
||||
$items_exists->{$t}{'total'} = $c > 0;
|
||||
}
|
||||
return $items_exists->{$t}{'total'};
|
||||
}
|
||||
}
|
||||
|
||||
# ------------------------- remove unavialable fields from graph --------------------------
|
||||
sub remove_unavialabled_counters
|
||||
{
|
||||
my @cpu = split(/\s+/, (grep(/cpu\s/, get_stat_file_content()))[0]);
|
||||
my $counters_count = scalar(@cpu) - 3;
|
||||
@cnames = @cnames[0..$counters_count];
|
||||
}
|
||||
|
||||
# ----------------------- get sysfs file content ----------------
|
||||
my $fcontents = {};
|
||||
sub get_sys_file_content
|
||||
{
|
||||
my $file = $_[0];
|
||||
return 'nan' if (-z $file);
|
||||
unless (exists($fcontents->{$file}))
|
||||
{
|
||||
open (FH, '<', $file) or die "$! $file \n";
|
||||
$fcontents->{$file} = <FH>;
|
||||
close (FH);
|
||||
chomp $fcontents->{$file};
|
||||
}
|
||||
return $fcontents->{$file};
|
||||
}
|
||||
|
||||
# -------------------------- loading cpu info ---------------------------------
|
||||
sub load_cpuinfo
|
||||
{
|
||||
my $file = "/proc/cpuinfo";
|
||||
open (FH, '<', $file) or die "$! $file \n";
|
||||
my $cpu_num = -1;
|
||||
for my $line (<FH>)
|
||||
{
|
||||
chomp $line;
|
||||
$cpu_num++ if $line =~ m/^processor\s+:/;
|
||||
$cpuinfo->{$cpu_num}{'name'} = trim((split(/:/,$line))[1]) if $line =~ m/^model name\s+:/;
|
||||
$cpuinfo->{$cpu_num}{'bogomips'} = trim((split(/:/,$line))[1]) if $line =~ m/^bogomips\s+:/;
|
||||
if (not exists($cpuinfo->{$cpu_num}{'info'}) and exists($cpuinfo->{$cpu_num}{'name'}) and exists($cpuinfo->{$cpu_num}{'bogomips'}))
|
||||
{
|
||||
$cpuinfo->{$cpu_num}{'info'} = sprintf("[%s (%s bogomips)]", $cpuinfo->{$cpu_num}{'name'}, $cpuinfo->{$cpu_num}{'bogomips'}) ;
|
||||
}
|
||||
}
|
||||
close (FH);
|
||||
$cpuinfo->{'cpu_count'} = $cpu_num+1;
|
||||
}
|
||||
|
||||
|
||||
# -------------------------- loading stat file lines ---------------------------------
|
||||
sub get_stat_file_content
|
||||
{
|
||||
if(scalar(@stat_file_content) == 0)
|
||||
{
|
||||
open (FH, '<', $stat_file) or die "$! $stat_file \n";
|
||||
for (<FH>)
|
||||
{
|
||||
next unless $_ =~ m/cpu/;
|
||||
chomp $_;
|
||||
push(@stat_file_content, $_);
|
||||
}
|
||||
close (FH);
|
||||
}
|
||||
return @stat_file_content;
|
||||
}
|
||||
|
||||
# -------------------------------- replacing strings ------------------------
|
||||
sub replace_template
|
||||
{
|
||||
my ($string, $needle, $replacement) = @_[0..2];
|
||||
$string =~ s/$needle/$replacement/g;
|
||||
return $string;
|
||||
}
|
||||
|
||||
sub replace_templates
|
||||
{
|
||||
my ($src, $replacement_t, $replacement_i) = @_[0..2];
|
||||
my $dst = {};
|
||||
for my $key ( keys %{$src} )
|
||||
{
|
||||
$dst->{$key} = $src->{$key};
|
||||
if($key =~ m/label|info|title/) { $dst->{$key} = replace_template($dst->{$key}, ':t:', $replacement_t); }
|
||||
if($key =~ m/info|title/) { $dst->{$key} = replace_template($dst->{$key}, ':i:', $replacement_i); }
|
||||
}
|
||||
return $dst;
|
||||
}
|
||||
|
||||
sub append_order
|
||||
{
|
||||
my ($pg, $graph_name, $field_name) = @_[0..2];
|
||||
$pg->{$graph_name}{'graph'}{'order'} = exists($pg->{$graph_name}{'graph'}{'order'}) ? sprintf("%s %s", $pg->{$graph_name}{'graph'}{'order'}, $field_name) : $field_name;
|
||||
}
|
||||
|
||||
sub append_field
|
||||
{
|
||||
my ($pg, $graph_name, $field_name, $field_src, $replacement_t, $replacement_i) = @_[0..5];
|
||||
$pg->{$graph_name}{'fields'}{$field_name} = replace_templates($fields->{$field_src}, $replacement_t, $replacement_i);
|
||||
append_order($pg, $graph_name, $field_name);
|
||||
}
|
||||
|
||||
sub append_graph
|
||||
{
|
||||
my ($pg, $graph_name, $category, $graph_src, $replacement_t, $replacement_i) = @_[0..5];
|
||||
$pg->{$graph_name}{'graph'} = replace_templates($graphs->{$graph_src}, $replacement_t, $replacement_i);
|
||||
$pg->{$graph_name}{'graph'}{'category'} = $category;
|
||||
}
|
||||
|
||||
# ---------------------------------------- preparing data for graphs ------------------------------------
|
||||
sub prepare_graphs_fields
|
||||
{
|
||||
my $pg = {};
|
||||
# ------------------ cpu_utilisation -----------------------------------
|
||||
# ---------- general ----------------------
|
||||
append_graph($pg, 'cpu_utilisation', 'cpu', 'cpu_utilisation', '', '');
|
||||
for my $cname (@cnames) { append_field($pg, 'cpu_utilisation', $cname, $cname, '', ''); append_utilisation_limits($pg, 'cpu_utilisation', $cname, undef); }
|
||||
if(check_exists('freq_hz')) { for (my $i = 0; $i < $cpuinfo->{'cpu_count'}; $i++) { append_field($pg, 'cpu_utilisation', sprintf("fp_%s", $i), 'freq_percent', $i, ''); } }
|
||||
# ---------------- childs -------------------
|
||||
if ($cpuinfo->{'cpu_count'} > 1)
|
||||
{
|
||||
for (my $i=0; $i < $cpuinfo->{'cpu_count'}; $i++)
|
||||
{
|
||||
my $graph_name = sprintf("cpu_utilisation.cpu%s", $i);
|
||||
append_graph($pg, $graph_name, sprintf("CPU %s", $i), 'cpu_utilisation', $i, $cpuinfo->{$i}{'info'});
|
||||
for my $cname (@cnames) { append_field($pg, $graph_name, $cname, $cname, '', ''); append_utilisation_limits($pg, $graph_name, $cname, $i); }
|
||||
if(check_exists('freq_hz', $i)) { append_field($pg, $graph_name, 'fp', 'freq_percent', '', ''); }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
# --------------- cpu_frequency --------------------------------------------
|
||||
if(check_exists('freq_trans'))
|
||||
{
|
||||
# ------------ general --------------------
|
||||
# - cpu frequency transitions -
|
||||
append_graph($pg, 'cpu_frequency', 'cpu', 'cpu_freq_trans', '', '');
|
||||
for (my $i = 0; $i < $cpuinfo->{'cpu_count'}; $i++) { if (check_exists('freq_trans', $i)) { append_field($pg, 'cpu_frequency', sprintf("cpu_%s", $i), 'freq_trans', sprintf("CPU%s", $i), ''); } }
|
||||
append_field($pg, 'cpu_frequency', 'total', 'freq_trans', 'Total', '');
|
||||
# ---------------- childs -------------------
|
||||
if(check_exists('freq_times'))
|
||||
{
|
||||
my $frequences = get_frequency_times();
|
||||
for (my $i=0; $i < $cpuinfo->{'cpu_count'}; $i++)
|
||||
{
|
||||
if(check_exists('freq_times', $i))
|
||||
{
|
||||
# - cpu frequencyes -
|
||||
my $graph_name = sprintf("cpu_frequency.percent_cpu%s", $i);
|
||||
append_graph($pg, $graph_name, sprintf("CPU %s", $i), 'cpu_freq', $i, $cpuinfo->{$i}{'info'});
|
||||
for my $freq (@{$frequences->{'names'}{$i}}) { append_field($pg, $graph_name, sprintf("hz_%s", $freq), 'freq_hz', scaleNumber($freq, 'Hz'), ''); }
|
||||
# - cpu frequencyes per secund -
|
||||
$graph_name = sprintf("cpu_frequency.percent_ps_cpu%s", $i);
|
||||
append_graph($pg, $graph_name, sprintf("CPU %s", $i), 'cpu_freq_ps', $i, $cpuinfo->{$i}{'info'});
|
||||
for my $freq (@{$frequences->{'names'}{$i}}) { append_field($pg, $graph_name, sprintf("hz_%s", $freq), 'freq_hz', scaleNumber($freq, 'Hz'), ''); }
|
||||
}
|
||||
}
|
||||
}
|
||||
if(check_exists('freq_ttable'))
|
||||
{
|
||||
my $f_table = get_frequency_trans_table();
|
||||
for (my $i=0; $i < $cpuinfo->{'cpu_count'}; $i++)
|
||||
{
|
||||
if(check_exists('freq_ttable', $i))
|
||||
{
|
||||
# - cpu frequencyes table -
|
||||
my $graph_name = sprintf("cpu_frequency.trans_table_cpu%s", $i);
|
||||
append_graph($pg, $graph_name, sprintf("CPU %s", $i), 'cpu_freq_trans_table', $i, $cpuinfo->{$i}{'info'});
|
||||
for my $from (sort keys %{$f_table->{'values'}{$i}})
|
||||
{
|
||||
for my $to (sort keys %{$f_table->{'values'}{$i}{$from}})
|
||||
{
|
||||
next if ($from eq $to);
|
||||
append_field($pg, $graph_name, sprintf("f_%s_t_%s", $from, $to), 'freq_trans_table', sprintf(". %9s -> %s", scaleNumber($from, 'Hz'), scaleNumber($to, 'Hz')), '');
|
||||
}
|
||||
}
|
||||
# - cpu frequencyes table per secund -
|
||||
$graph_name = sprintf("cpu_frequency.trans_table_ps_cpu%s", $i);
|
||||
append_graph($pg, $graph_name, sprintf("CPU %s", $i), 'cpu_freq_trans_table_ps', $i, $cpuinfo->{$i}{'info'});
|
||||
for my $from (sort keys %{$f_table->{'values'}{$i}})
|
||||
{
|
||||
for my $to (sort keys %{$f_table->{'values'}{$i}{$from}})
|
||||
{
|
||||
next if ($from eq $to);
|
||||
append_field($pg, $graph_name, sprintf("f_%s_t_%s", $from, $to), 'freq_trans_table', sprintf(". %9s -> %s", scaleNumber($from, 'Hz'), scaleNumber($to, 'Hz')), '');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
# --------------- cpu_all -----------------------------------------
|
||||
if ($cpuinfo->{'cpu_count'} > 1)
|
||||
{
|
||||
append_graph($pg, 'cpu_all', 'cpu', 'cpu_all', '', '');
|
||||
for (my $i = 0; $i < $cpuinfo->{'cpu_count'}; $i++) { append_field($pg, 'cpu_all', sprintf("cpu_%s", $i), 'cpu_util', sprintf("CPU%s", $i)); }
|
||||
append_field($pg, 'cpu_all', 'total', 'cpu_util', 'Combined');
|
||||
}
|
||||
return $pg;
|
||||
}
|
||||
|
||||
|
||||
# ------------------------------------ printing limits (for utilisation graphs) ----------------
|
||||
sub append_utilisation_limits
|
||||
{
|
||||
my ($pg, $graph_name, $cname, $i) = @_[0..3];
|
||||
for my $type (qw(warning critical))
|
||||
{
|
||||
my $field = sprintf("%s_%s", $cname, $type);
|
||||
my $cpu_field = defined($i) ? sprintf("cpu%s_%s_%s", $i, $cname, $type) : undef;
|
||||
my $limit = (defined($i) and defined($limits->{'utilisation'}{$cpu_field})) ?
|
||||
$limits->{'utilisation'}{$cpu_field} :
|
||||
(
|
||||
defined($limits->{'utilisation'}{$field}) ?
|
||||
$limits->{'utilisation'}{$field} :
|
||||
(
|
||||
defined($limits->{'utilisation'}{$type}) ?
|
||||
$limits->{'utilisation'}{$type} :
|
||||
undef
|
||||
)
|
||||
);
|
||||
if(defined($limit)) { $pg->{$graph_name}{'fields'}{$cname}{$type} = $limit; }
|
||||
}
|
||||
}
|
||||
|
||||
# ---------------- loading limits -------------
|
||||
sub load_limits
|
||||
{
|
||||
$limits->{'utilisation'}{'warning'} = $ENV{warning} || undef;
|
||||
$limits->{'utilisation'}{'critical'} = $ENV{critical} || undef;
|
||||
for my $cname (@cnames)
|
||||
{
|
||||
for my $t (qw(warning critical))
|
||||
{
|
||||
my $name = sprintf("%s_%s", $cname, $t);
|
||||
$limits->{'utilisation'}{$name} = $ENV{$name} || undef;
|
||||
for (my $i = 0; $i <= $cpuinfo->{'cpu_count'}; $i++)
|
||||
{
|
||||
$name = sprintf("cpu%s_%s_%s",$i, $cname, $t);
|
||||
$limits->{'utilisation'}{$name} = $ENV{$name} || undef;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# --------------------------------- graph configs ----------------------------
|
||||
sub print_config
|
||||
{
|
||||
load_limits();
|
||||
my $config = prepare_graphs_fields();
|
||||
for my $g (sort keys %{$config})
|
||||
{
|
||||
printf("multigraph %s\n", $g);
|
||||
for my $go (sort keys %{$config->{$g}{'graph'}}) { printf("graph_%s %s\n", $go, $config->{$g}{'graph'}{$go}); }
|
||||
for my $f (sort keys %{$config->{$g}{'fields'}}) { for my $fo (sort keys %{$config->{$g}{'fields'}{$f}}) { printf("%s.%s %s\n", $f, $fo, $config->{$g}{'fields'}{$f}{$fo}); } }
|
||||
print "\n";
|
||||
}
|
||||
}
|
||||
|
||||
# ----------------------------------- saving state data using munin --------------------
|
||||
sub save_state_data
|
||||
{
|
||||
my $data = $_[0];
|
||||
my $d = Data::Dumper->new([$data]);
|
||||
$d->Indent(0);
|
||||
save_state($d->Dump);
|
||||
}
|
||||
|
||||
# -------------------------------- loading previous state data using munin -------------------
|
||||
sub restore_state_data
|
||||
{
|
||||
my $VAR1;
|
||||
my $states = (restore_state())[0];
|
||||
eval $states if defined $states;
|
||||
return $VAR1;
|
||||
}
|
||||
|
||||
sub load_stats
|
||||
{
|
||||
my $stats = {};
|
||||
# need to store --------------------
|
||||
$stats->{'timestamp'} = time();
|
||||
$stats->{'cpu_util'} = get_cpu_utilisation_stats() ;
|
||||
$stats->{'f_trans'} = get_frequency_transitions() if check_exists('freq_trans') ;
|
||||
$stats->{'f_times'} = get_frequency_times() if check_exists('freq_times') ;
|
||||
$stats->{'f_ttable'} = get_frequency_trans_table() if check_exists('freq_ttable');
|
||||
|
||||
save_state_data($stats);
|
||||
|
||||
# no need to store --------------------
|
||||
$stats->{'f_minmax'} = get_cpu_curr_max_freqences() if check_exists('freq_hz') ;
|
||||
|
||||
|
||||
#print Dumper $stats;
|
||||
return $stats;
|
||||
}
|
||||
|
||||
# ---------------------------------- loading cpu stats from loaded lines ------------------------
|
||||
sub get_cpu_utilisation_stats
|
||||
{
|
||||
my $stats = {};
|
||||
for (my $i = 0; $i <= $cpuinfo->{'cpu_count'}; $i++)
|
||||
{
|
||||
my $rx = $i == $cpuinfo->{'cpu_count'} ? 'cpu' : sprintf ("cpu%s", $i);
|
||||
my $cn = $i == $cpuinfo->{'cpu_count'} ? 'total' : $i;
|
||||
my @tmp = split(/\s+/, (grep(/$rx\s/, get_stat_file_content()))[0]);
|
||||
my $j = 1;
|
||||
for my $cname (@cnames)
|
||||
{
|
||||
$stats->{$cn}{$cname} = $tmp[$j];
|
||||
$j++;
|
||||
}
|
||||
}
|
||||
return $stats;
|
||||
}
|
||||
# ------------------ loading frequency transitions for each cpu ----------------------------
|
||||
sub get_frequency_transitions
|
||||
{
|
||||
my $stats = {};
|
||||
for (my $i = 0; $i < $cpuinfo->{'cpu_count'}; $i++)
|
||||
{
|
||||
next unless (check_exists('freq_trans', $i));
|
||||
$stats->{$i} = get_sys_file_content(sprintf("%s/cpu%s/cpufreq/stats/total_trans", $freq_path, $i));
|
||||
}
|
||||
return $stats;
|
||||
}
|
||||
|
||||
# ------------------ loading frequency times for each cpu ----------------------------
|
||||
sub get_frequency_times
|
||||
{
|
||||
my $stat = {};
|
||||
for (my $i = 0; $i < $cpuinfo->{'cpu_count'}; $i++)
|
||||
{
|
||||
next unless (check_exists('freq_times', $i));
|
||||
my $total = 0;
|
||||
my $file = sprintf("%s/cpu%s/cpufreq/stats/time_in_state", $freq_path, $i);
|
||||
open (FH, '<', $file) or die "$! $file \n";
|
||||
for my $line (<FH>)
|
||||
{
|
||||
chomp $line;
|
||||
my ($hz, $count) = split(/\s+/, $line);
|
||||
$hz = $hz*$freq_mul;
|
||||
$stat->{'values'}{$i}{$hz} = $count;
|
||||
push(@{$stat->{'names'}{$i}}, $hz);
|
||||
$total += $count;
|
||||
}
|
||||
close (FH);
|
||||
$stat->{'total'}{$i} = $total;
|
||||
}
|
||||
return $stat;
|
||||
}
|
||||
|
||||
# ------------------ loading current and max frequency for each cpu ----------------------------
|
||||
sub get_cpu_curr_max_freqences
|
||||
{
|
||||
my $freq = {};
|
||||
for (my $i = 0; $i < $cpuinfo->{'cpu_count'}; $i++)
|
||||
{
|
||||
next unless (check_exists('freq_hz', $i));
|
||||
my $cpu_path = sprintf("%s/cpu%s/cpufreq", $freq_path, $i);
|
||||
$freq->{'cur'}{$i} = get_sys_file_content(sprintf("%s/scaling_cur_freq", $cpu_path))*$freq_mul;
|
||||
$freq->{'max'}{$i} = get_sys_file_content(sprintf("%s/scaling_max_freq", $cpu_path))*$freq_mul;
|
||||
$freq->{'min'}{$i} = get_sys_file_content(sprintf("%s/scaling_min_freq", $cpu_path))*$freq_mul;
|
||||
}
|
||||
return $freq;
|
||||
}
|
||||
|
||||
sub get_frequency_trans_table
|
||||
{
|
||||
my $tbl = {};
|
||||
for (my $i = 0; $i < $cpuinfo->{'cpu_count'}; $i++)
|
||||
{
|
||||
next unless (check_exists('freq_ttable', $i));
|
||||
my @frequences;
|
||||
my $fcount = 0;
|
||||
my $total = 0;
|
||||
my $file = sprintf("%s/cpu%s/cpufreq/stats/trans_table", $freq_path, $i);
|
||||
open (FH, '<', $file) or die "$! $file \n";
|
||||
for my $line (<FH>)
|
||||
{
|
||||
chomp $line;
|
||||
my ($left, $right) = split(/:/, $line);
|
||||
next if($left =~ m/From/);
|
||||
if($left =~ m/\d+/)
|
||||
{
|
||||
my $frequence = trim($left)*$freq_mul;
|
||||
my @counters = split(/\s+/, trim($right));
|
||||
for (my $j = 0; $j<$fcount; $j++)
|
||||
{
|
||||
$tbl->{'values'}{$i}{$frequence}{$frequences[$j]*$freq_mul} = $counters[$j];
|
||||
$total += $counters[$j];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@frequences = split(/\s+/, trim($right));
|
||||
$fcount = scalar(@frequences);
|
||||
}
|
||||
}
|
||||
$tbl->{'total'}{$i} = $total;
|
||||
close (FH);
|
||||
}
|
||||
return $tbl;
|
||||
}
|
||||
|
||||
sub one_second_part
|
||||
{
|
||||
my ($curr, $prev, $timediff) = @_[0..2];
|
||||
#print "$prev, $curr, $timediff\n";
|
||||
return 'NaN' if ($curr < $prev or $timediff < 0);
|
||||
return $curr - $prev if $timediff == 0;
|
||||
return ($curr - $prev)/$timediff;
|
||||
}
|
||||
|
||||
sub divide
|
||||
{
|
||||
my ($divider, $divident) = @_[0..1];
|
||||
return 'NaN' if $divident == 0;
|
||||
return $divider/$divident;
|
||||
}
|
||||
|
||||
# -------------------------------- calculating fields values ------------------------------
|
||||
sub calculate
|
||||
{
|
||||
my ($pstats, $cstats) = @_[0..1];
|
||||
my $result = {};
|
||||
my $timediff = $cstats->{'timestamp'} - $pstats->{'timestamp'};
|
||||
# --- cpu utilisation ----
|
||||
for my $cpu (keys %{$cstats->{'cpu_util'}})
|
||||
{
|
||||
# ------ calculating 1%
|
||||
$result->{'cpu_util'}{'1%'}{$cpu} = 0;
|
||||
for my $cname (@cnames)
|
||||
{
|
||||
$result->{'cpu_util'}{'diff'}{$cpu}{$cname} = one_second_part($cstats->{'cpu_util'}{$cpu}{$cname}, $pstats->{'cpu_util'}{$cpu}{$cname}, $timediff);
|
||||
$result->{'cpu_util'}{'1%'}{$cpu} += $result->{'cpu_util'}{'diff'}{$cpu}{$cname} if $result->{'cpu_util'}{'diff'}{$cpu}{$cname} ne 'NaN';
|
||||
}
|
||||
$result->{'cpu_util'}{'1%'}{$cpu} = $result->{'cpu_util'}{'1%'}{$cpu}/100;
|
||||
# ------ calculating used percents
|
||||
$result->{'cpu_util'}{'used'}{$cpu} = 0;
|
||||
for my $cname (@cnames)
|
||||
{
|
||||
$result->{'cpu_util'}{'%'}{$cpu}{$cname} = divide($result->{'cpu_util'}{'diff'}{$cpu}{$cname}, $result->{'cpu_util'}{'1%'}{$cpu});
|
||||
next if $cname eq 'idle';
|
||||
$result->{'cpu_util'}{'used'}{$cpu} += $result->{'cpu_util'}{'%'}{$cpu}{$cname} if $result->{'cpu_util'}{'%'}{$cpu}{$cname} ne 'NaN';
|
||||
}
|
||||
}
|
||||
# ------ freq min max ----
|
||||
if (check_exists('freq_hz'))
|
||||
{
|
||||
for (my $i = 0; $i < $cpuinfo->{'cpu_count'}; $i++)
|
||||
{
|
||||
$result->{'f_minmax'}{'%'}{$i} = divide($cstats->{'f_minmax'}{'cur'}{$i} - $cstats->{'f_minmax'}{'min'}{$i},
|
||||
(($cstats->{'f_minmax'}{'max'}{$i} - $cstats->{'f_minmax'}{'min'}{$i}) / 100 )) if (check_exists('freq_hz', $i));
|
||||
}
|
||||
}
|
||||
# ---- freq trans ----
|
||||
if (check_exists('freq_trans'))
|
||||
{
|
||||
$result->{'f_trans'}{'total'} = 0;
|
||||
for (my $i = 0; $i < $cpuinfo->{'cpu_count'}; $i++)
|
||||
{
|
||||
if(check_exists('freq_trans', $i))
|
||||
{
|
||||
$result->{'f_trans'}{$i} = one_second_part($cstats->{'f_trans'}{$i}, $pstats->{'f_trans'}{$i}, $timediff);
|
||||
$result->{'f_trans'}{'total'} += $result->{'f_trans'}{$i} if $result->{'f_trans'}{$i} ne 'NaN';
|
||||
}
|
||||
}
|
||||
}
|
||||
# -- freq times ---
|
||||
if (check_exists('freq_times'))
|
||||
{
|
||||
for (my $i = 0; $i < $cpuinfo->{'cpu_count'}; $i++)
|
||||
{
|
||||
if (check_exists('freq_times', $i))
|
||||
{
|
||||
my $oneprc = $cstats->{'f_times'}{'total'}{$i}/100;
|
||||
my $ps_total = 0;
|
||||
for my $hz (@{$cstats->{'f_times'}{'names'}{$i}})
|
||||
{
|
||||
$result->{'f_times'}{$i}{$hz} = divide($cstats->{'f_times'}{'values'}{$i}{$hz}, $oneprc);
|
||||
$cstats->{'f_times'}{'%_ps'}{$i}{$hz} = one_second_part($cstats->{'f_times'}{'values'}{$i}{$hz}, $pstats->{'f_times'}{'values'}{$i}{$hz}, $timediff);
|
||||
$ps_total += $cstats->{'f_times'}{'%_ps'}{$i}{$hz};
|
||||
}
|
||||
$ps_total = $ps_total/100;
|
||||
for my $hz (@{$cstats->{'f_times'}{'names'}{$i}})
|
||||
{
|
||||
$result->{'f_times_ps'}{$i}{$hz} = divide($cstats->{'f_times'}{'%_ps'}{$i}{$hz}, $ps_total);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
# ------- freq trans table ---
|
||||
if (check_exists('freq_ttable'))
|
||||
{
|
||||
for (my $i = 0; $i < $cpuinfo->{'cpu_count'}; $i++)
|
||||
{
|
||||
if (check_exists('freq_ttable', $i))
|
||||
{
|
||||
my $oneprc = $cstats->{'f_ttable'}{'total'}{$i}/100;
|
||||
my $ps_total = 0;
|
||||
for my $from (keys %{$cstats->{'f_ttable'}{'values'}{$i}})
|
||||
{
|
||||
for my $to (keys %{$cstats->{'f_ttable'}{'values'}{$i}{$from}})
|
||||
{
|
||||
next if ($from eq $to);
|
||||
$result->{'f_ttable'}{$i}{$from}{$to} = divide($cstats->{'f_ttable'}{'values'}{$i}{$from}{$to}, $oneprc);
|
||||
$cstats->{'f_ttable'}{'%_ps'}{$i}{$from}{$to} = one_second_part($cstats->{'f_ttable'}{'values'}{$i}{$from}{$to}, $pstats->{'f_ttable'}{'values'}{$i}{$from}{$to}, $timediff);
|
||||
$ps_total += $cstats->{'f_ttable'}{'%_ps'}{$i}{$from}{$to};
|
||||
}
|
||||
}
|
||||
$ps_total = $ps_total/100;
|
||||
for my $from (keys %{$cstats->{'f_ttable'}{'values'}{$i}})
|
||||
{
|
||||
for my $to (keys %{$cstats->{'f_ttable'}{'values'}{$i}{$from}})
|
||||
{
|
||||
next if ($from eq $to);
|
||||
$result->{'f_ttable_ps'}{$i}{$from}{$to} = divide($cstats->{'f_ttable'}{'%_ps'}{$i}{$from}{$to}, $ps_total);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#print Dumper $result;
|
||||
return $result;
|
||||
}
|
||||
|
||||
# ---------------------------------------- preparing values ------------------------------------
|
||||
sub prepare_graphs_values
|
||||
{
|
||||
my ($data) = $_[0];
|
||||
my $pg = {};
|
||||
# ------------------ cpu_utilisation -----------------------------------
|
||||
# ---------- general ----------------------
|
||||
for my $cname (@cnames) { $pg->{'cpu_utilisation'}{$cname} = $data->{'cpu_util'}{'%'}{'total'}{$cname}; }
|
||||
if(check_exists('freq_hz')) { for (my $i = 0; $i < $cpuinfo->{'cpu_count'}; $i++) { $pg->{'cpu_utilisation'}{sprintf("fp_%s", $i)} = $data->{'f_minmax'}{'%'}{$i}; } }
|
||||
# ---------------- childs -------------------
|
||||
if ($cpuinfo->{'cpu_count'} > 1)
|
||||
{
|
||||
for (my $i=0; $i < $cpuinfo->{'cpu_count'}; $i++)
|
||||
{
|
||||
my $graph_name = sprintf("cpu_utilisation.cpu%s", $i);
|
||||
for my $cname (@cnames) { $pg->{$graph_name}{$cname} = $data->{'cpu_util'}{'%'}{$i}{$cname}; }
|
||||
if(check_exists('freq_hz', $i)) { $pg->{$graph_name}{'fp'} = $data->{'f_minmax'}{'%'}{$i}; }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
# --------------- cpu_frequency --------------------------------------------
|
||||
if(check_exists('freq_trans'))
|
||||
{
|
||||
# ------------ general --------------------
|
||||
for (my $i = 0; $i < $cpuinfo->{'cpu_count'}; $i++) { $pg->{'cpu_frequency'}{sprintf("cpu_%s", $i)} = $data->{'f_trans'}{$i} if (check_exists('freq_trans', $i)); }
|
||||
$pg->{'cpu_frequency'}{'total'} = $data->{'f_trans'}{'total'};
|
||||
# ---------------- childs -------------------
|
||||
if(check_exists('freq_times'))
|
||||
{
|
||||
for (my $i=0; $i < $cpuinfo->{'cpu_count'}; $i++)
|
||||
{
|
||||
if(check_exists('freq_times', $i))
|
||||
{
|
||||
my $graph_name = sprintf("cpu_frequency.percent_cpu%s", $i);
|
||||
for my $freq (keys %{$data->{'f_times'}{$i}}) { $pg->{$graph_name}{sprintf("hz_%s", $freq)} = $data->{'f_times'}{$i}{$freq}; }
|
||||
$graph_name = sprintf("cpu_frequency.percent_ps_cpu%s", $i);
|
||||
for my $freq (keys %{$data->{'f_times_ps'}{$i}}) { $pg->{$graph_name}{sprintf("hz_%s", $freq)} = $data->{'f_times_ps'}{$i}{$freq}; }
|
||||
}
|
||||
}
|
||||
}
|
||||
if(check_exists('freq_ttable'))
|
||||
{
|
||||
for (my $i=0; $i < $cpuinfo->{'cpu_count'}; $i++)
|
||||
{
|
||||
if(check_exists('freq_ttable', $i))
|
||||
{
|
||||
my $graph_name = sprintf("cpu_frequency.trans_table_cpu%s", $i);
|
||||
for my $from (keys %{$data->{'f_ttable'}{$i}})
|
||||
{
|
||||
for my $to (keys %{$data->{'f_ttable'}{$i}{$from}})
|
||||
{
|
||||
$pg->{$graph_name}{sprintf("f_%s_t_%s", $from, $to)} = $data->{'f_ttable'}{$i}{$from}{$to};
|
||||
}
|
||||
}
|
||||
$graph_name = sprintf("cpu_frequency.trans_table_ps_cpu%s", $i);
|
||||
for my $from (keys %{$data->{'f_ttable_ps'}{$i}})
|
||||
{
|
||||
for my $to (keys %{$data->{'f_ttable_ps'}{$i}{$from}})
|
||||
{
|
||||
$pg->{$graph_name}{sprintf("f_%s_t_%s", $from, $to)} = $data->{'f_ttable_ps'}{$i}{$from}{$to};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# --------------- cpu_all --------------------------------------------
|
||||
if ($cpuinfo->{'cpu_count'} > 1)
|
||||
{
|
||||
for (my $i = 0; $i < $cpuinfo->{'cpu_count'}; $i++) { $pg->{'cpu_all'}{sprintf("cpu_%s", $i)} = $data->{'cpu_util'}{'used'}{$i}; }
|
||||
$pg->{'cpu_all'}{'total'} = $data->{'cpu_util'}{'used'}{'total'};
|
||||
}
|
||||
return $pg;
|
||||
}
|
||||
|
||||
|
||||
|
||||
# -------------------------------- printing values -----------------------------------
|
||||
sub print_values
|
||||
{
|
||||
my $pstats = restore_state_data();
|
||||
my $cstats = load_stats();
|
||||
if (exists ($pstats->{'timestamp'}))
|
||||
{
|
||||
my $values = prepare_graphs_values(calculate($pstats, $cstats));
|
||||
#print Dumper $values;
|
||||
for my $g (sort keys %{$values})
|
||||
{
|
||||
printf("multigraph %s\n", $g);
|
||||
for my $f (sort keys %{$values->{$g}}) { printf("%s.value %s\n", $f, $values->{$g}{$f}); }
|
||||
print "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
__END__
|
||||
|
||||
- user: normal processes executing in user mode
|
||||
- nice: niced processes executing in user mode
|
||||
- system: processes executing in kernel mode
|
||||
- idle: twiddling thumbs
|
||||
- iowait: waiting for I/O to complete
|
||||
- irq: servicing interrupts
|
||||
- softirq: servicing softirqs
|
||||
- steal: involuntary wait
|
||||
- guest: running a guest
|
|
@ -1,135 +0,0 @@
|
|||
#!/bin/sh
|
||||
#
|
||||
# Copyright (C) 2006 Holger Levsen
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; version 2 dated June,
|
||||
# 1991.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
#
|
||||
# Configuration variables
|
||||
# vservers - specify the vservers to include in the graph (default: all)
|
||||
# limits - if true, turn on limit graphing (default: false)
|
||||
#
|
||||
# NOTE: If no configuration variables are set, the defaults will be used
|
||||
|
||||
# Example /etc/munin/plugin-conf.d/munin-node
|
||||
#
|
||||
# The first group monitors the vservers named "vserver1 vserver2
|
||||
# vserver3 vserver4" and looks to see if the resource limit has been
|
||||
# breached, if so it sends a message to nagios via send_nsca, and
|
||||
# sends an email to notify that this has happened.
|
||||
#
|
||||
# The second monitors the vservers "vserver5 vserver6 vserver7" and
|
||||
# has no limit notifications turned on.
|
||||
#
|
||||
# The third monitors all vservers on the system, in one graph, and it has
|
||||
# no limit notifications defined.
|
||||
#
|
||||
# You can use any combination of these to fit your needs.
|
||||
#
|
||||
#
|
||||
# [vsrmem_group1]
|
||||
# user root
|
||||
# env.vservers vserver1 vserver2 vserver3 vserver4
|
||||
# env.limits 1
|
||||
# contacts nagios email
|
||||
# contact.nagios.command /usr/bin/send_nsca -H your.nagios-host.here -c /etc/send_nsca.cfg
|
||||
# contact.email.command mail -s "Munin-notification for ${var:group} :: ${var:host}" your@email.address.here
|
||||
#
|
||||
# [vsrmem_group2]
|
||||
# user root
|
||||
# env.vservers vserver5 vserver6 vserver7
|
||||
# env.limits 0
|
||||
#
|
||||
# [vserver_rmemory]
|
||||
# user root
|
||||
#
|
||||
# Graph Vserver RSS usage and limits
|
||||
#
|
||||
# Changelog
|
||||
# version 0.1 - 2006 April xx - Holger Levsen
|
||||
# - initial author
|
||||
# version 0.2 - 2006 April 24 - Micah Anderson <micah@riseup.net>
|
||||
# - Add dynamic arch page size determination
|
||||
# - Some cleanup and clarification
|
||||
# version 0.3 - 2006 May 3 - Micah Anderson <micah@riseup.net>
|
||||
# - Add ability to group vservers via environment vars
|
||||
# - Fix missing close quotes and standardize indents
|
||||
# - Add limit notification
|
||||
# - Update documentation to include info on groups and limits
|
||||
# version 0.4 - 2006 Jun 22 - Micah Anderson <micah@riseup.net>
|
||||
# - Fix error that results if NodeName is set to include a domain name
|
||||
|
||||
#scriptname=`basename $0`
|
||||
#vsname=`echo $scriptname | perl -ne '/^vserver_proc_VM_(.*)/ and print $1'`
|
||||
|
||||
#if [ "$1" = "suggest" ]; then
|
||||
# ls -1 /etc/vservers
|
||||
# exit 0
|
||||
#elif [ -z "$vsname" ]; then
|
||||
# echo "Must be used with a vserver name; try '$0 suggest'" >&2
|
||||
# exit 2
|
||||
#fi
|
||||
|
||||
#xid=`cat /etc/vservers/$vsname/context`
|
||||
|
||||
if [ "$1" = "config" ]; then
|
||||
echo "graph_title CPU time by Process"
|
||||
echo 'graph_args --base 1000 -l 0'
|
||||
echo 'graph_vlabel seconds'
|
||||
echo 'graph_category system'
|
||||
echo "graph_info Shows CPU time used by each process name"
|
||||
|
||||
# ps -eo time,comm h | perl -e '
|
||||
ps -eo pid,time,comm | perl -e '
|
||||
$junk = <>;
|
||||
while (<>)
|
||||
{
|
||||
@a = split;
|
||||
$proc = $a[2];
|
||||
$var = $proc;
|
||||
$var =~ s|/.*||;
|
||||
$var =~ s|\.$||;
|
||||
$var =~ tr|a-zA-Z0-9|_|c;
|
||||
$procs{$var} = $proc;
|
||||
}
|
||||
my $stack = 0;
|
||||
sub draw() { return $stack++ ? "STACK" : "AREA" }
|
||||
print map
|
||||
{
|
||||
"$_.label $procs{$_}\n" .
|
||||
"$_.min 0\n" .
|
||||
"$_.type DERIVE\n" .
|
||||
"$_.draw " . draw() . "\n"
|
||||
}
|
||||
sort keys %procs;
|
||||
'
|
||||
exit 0
|
||||
else
|
||||
# ps -eo time,comm h | perl -e '
|
||||
ps -eo pid,time,comm | perl -e '
|
||||
$junk = <>;
|
||||
while (<>)
|
||||
{
|
||||
@a = split;
|
||||
$cpu = $a[1];
|
||||
$var = $a[2];
|
||||
$var =~ s|/.*||;
|
||||
$var =~ s|\.$||;
|
||||
$var =~ tr|a-zA-Z0-9|_|c;
|
||||
@b = split /:/, $cpu;
|
||||
$cpu = (($b[0] * 60) + $b[1]) * 60 + $b[2];
|
||||
$total{$var} += $cpu;
|
||||
}
|
||||
print map {"$_.value $total{$_}\n"} sort keys %total'
|
||||
fi
|
|
@ -1,55 +0,0 @@
|
|||
#!/bin/sh
|
||||
#
|
||||
# Plugin to monitor CPU speed on system that allow to reduce it for power saving
|
||||
#
|
||||
# probably only useful on laptops if you configure it to lower CPU frequency for
|
||||
# less power consumptoin. This plugin works by reading from the /sys file system.
|
||||
#
|
||||
# by dominik dot stadler at gmx.at
|
||||
#
|
||||
# Magic markers (optional - only used by munin-config and some
|
||||
# installation scripts):
|
||||
#
|
||||
#%# family=auto
|
||||
#%# capabilities=autoconf
|
||||
|
||||
if [ "$1" = "autoconf" ]; then
|
||||
if [ -r /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq ]; then
|
||||
echo yes
|
||||
exit 0
|
||||
else
|
||||
echo no
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
if [ "$1" = "config" ]; then
|
||||
echo 'graph_title CPU speed'
|
||||
echo 'graph_args --base 1000 -l 0'
|
||||
echo 'graph_vlabel speed'
|
||||
# echo 'graph_scale no'
|
||||
echo 'graph_category system'
|
||||
echo 'graph_info This graph shows the speed of the system fan.'
|
||||
echo 'maxspeed.label maxspeed'
|
||||
echo 'maxspeed.info The maximum speed of the CPU.'
|
||||
echo 'minspeed.label minspeed'
|
||||
echo 'minspeed.info The minimum speed of the CPU.'
|
||||
echo 'cpuspeed.label speed'
|
||||
echo 'cpuspeed.info The current speed of the CPU.'
|
||||
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo -n "maxspeed.value "
|
||||
cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq
|
||||
echo -n "minspeed.value "
|
||||
cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_min_freq
|
||||
echo -n "cpuspeed.value "
|
||||
|
||||
# cpuinfo_cur_freq is not readable for user munin, therefore using scaling_cur_freq for now, should
|
||||
# be equal information, see http://wiki.ubuntuusers.de/Prozessortaktung
|
||||
# We could also configure this plugin to require root access, but I like it better this way.
|
||||
#cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_cur_freq
|
||||
cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq
|
||||
|
|
@ -1,144 +0,0 @@
|
|||
#!/bin/sh
|
||||
#
|
||||
# Plugin to measure average CPU frequency for each CPU/core.
|
||||
#
|
||||
# Contributed by Mark Edwards
|
||||
#
|
||||
# Usage: Place in /etc/munin/plugins (or link it there using ln -s)
|
||||
#
|
||||
# Parameters understood:
|
||||
#
|
||||
# config (required)
|
||||
# autoconf (optional - used by munin-config)
|
||||
#
|
||||
# $Log$
|
||||
#
|
||||
# Revision 0.2 2010/01/04 16:37:00 medwards
|
||||
# Minor bugfixes in config section
|
||||
#
|
||||
# Revision 0.1 2010/01/04 16:13:00 medwards
|
||||
# First version
|
||||
#
|
||||
#
|
||||
#
|
||||
# Magic markers - optional - used by installation scripts and
|
||||
# munin-config:
|
||||
#
|
||||
#%# family=auto
|
||||
#%# capabilities=autoconf
|
||||
|
||||
if [ "$1" = "autoconf" ]; then
|
||||
if [ -r /sys/devices/system/cpu/cpu0/cpufreq/stats/time_in_state ]; then
|
||||
echo yes
|
||||
exit 0
|
||||
else
|
||||
echo no
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
cpu_count=`grep -c "^processor" /proc/cpuinfo`
|
||||
|
||||
if [ "$1" = "config" ]; then
|
||||
|
||||
echo 'graph_title Average CPU Frequency'
|
||||
up_lim=`cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq`
|
||||
low_lim=`cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq`
|
||||
up_lim=`expr $up_lim \* 1000` # Convert to Hz
|
||||
low_lim=`expr $low_lim \* 1000` # Convert to Hz
|
||||
echo "graph_args -u $up_lim -l $low_lim -r --base 1000"
|
||||
echo 'graph_vlabel Hz'
|
||||
echo 'graph_category system'
|
||||
cpu=0
|
||||
while [ $cpu -lt $cpu_count ]
|
||||
do
|
||||
echo "cpu_$cpu.label CPU $cpu"
|
||||
echo "cpu_$cpu.type GAUGE"
|
||||
echo "cpu_$cpu.info Hz"
|
||||
cpu=`expr $cpu + 1`
|
||||
done
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Run measurements
|
||||
cpu=0
|
||||
while [ $cpu -lt $cpu_count ]
|
||||
do
|
||||
|
||||
time_in_state=`cat /sys/devices/system/cpu/cpu$cpu/cpufreq/stats/time_in_state`
|
||||
|
||||
# Check/create statefile(s)
|
||||
statefile="/var/lib/munin/plugin-state/cpufreq-avg_cpu$cpu.state"
|
||||
if [ ! -r "$statefile" ]
|
||||
then
|
||||
echo "$time_in_state" > $statefile
|
||||
if [ "$?" -ne "0" ]
|
||||
then
|
||||
exit ${1}
|
||||
else
|
||||
cpu=`expr $cpu + 1`
|
||||
continue
|
||||
fi
|
||||
fi
|
||||
state=`cat $statefile`
|
||||
|
||||
# Calculated total time since last state
|
||||
total_time=0
|
||||
total_time=$(
|
||||
echo "$time_in_state" | {
|
||||
i=0
|
||||
while read line
|
||||
do
|
||||
this_freq=`echo $line | awk '{ print $1; }'`
|
||||
this_time=`echo $line | awk '{ print $2; }'`
|
||||
this_time_state=`echo "$state" | grep $this_freq | awk '{ print $2; }'`
|
||||
if [ $this_time -ge $this_time_state ] # Only measure if state is valid
|
||||
then
|
||||
time_diff=`expr $this_time - $this_time_state` # Calculate time since last state
|
||||
total_time=`expr $total_time + $time_diff`
|
||||
fi
|
||||
i=`expr $i + 1`
|
||||
done
|
||||
echo $total_time
|
||||
}
|
||||
)
|
||||
|
||||
# Measure average CPU frequency if total time calculation was successful
|
||||
|
||||
frequency=0
|
||||
frequency=$(
|
||||
echo "$time_in_state" | {
|
||||
i=0
|
||||
while read line
|
||||
do
|
||||
this_freq=`echo $line | awk '{ print $1; }'`
|
||||
this_time=`echo $line | awk '{ print $2; }'`
|
||||
this_time_state=`echo "$state" | grep $this_freq | awk '{ print $2; }'`
|
||||
this_freq=`expr $this_freq \* 1000` # Convert to Hz
|
||||
this_time=`expr $this_time - $this_time_state` # Calculate time since last state
|
||||
if [ $total_time -gt 0 ]
|
||||
then
|
||||
calc=`echo "($this_time / $total_time) * $this_freq" | bc -l`
|
||||
frequency=`echo "$frequency + $calc" | bc -l`
|
||||
fi
|
||||
i=`expr $i + 1`
|
||||
done
|
||||
echo $frequency
|
||||
}
|
||||
)
|
||||
|
||||
# Round result to an integer and return it
|
||||
frequency=`echo "scale=0 ; ($frequency+0.5)/1" | bc -l`
|
||||
if [ $frequency -gt 0 ]
|
||||
then
|
||||
echo "cpu_$cpu.value $frequency"
|
||||
fi
|
||||
|
||||
# Update statefile
|
||||
echo "$time_in_state" > $statefile
|
||||
|
||||
cpu=`expr $cpu + 1`
|
||||
|
||||
done
|
||||
|
||||
exit 0
|
|
@ -1,100 +0,0 @@
|
|||
#!/bin/bash
|
||||
#
|
||||
# Plugin to measure CPU frequency via cpufreq-info binary.
|
||||
# This makes the plugin run on linux machines only.
|
||||
# However the same goes for using sysfs directly.
|
||||
#
|
||||
# Contributed by Jo Schulze
|
||||
#
|
||||
# Config variables:
|
||||
#
|
||||
#
|
||||
# Requires:
|
||||
# cpufrequtils http://www.kernel.org/pub/linux/utils/kernel/cpufreq/cpufrequtils.html
|
||||
#
|
||||
# @remarks
|
||||
# jo20061130 using cpufreq-info should simplify the whole thing
|
||||
# jo20061202 tested on AMD K8 X2, intel Core 2 Duo
|
||||
#
|
||||
# $Log$
|
||||
#
|
||||
# Magic markers - optional - used by installation scripts and
|
||||
# munin-config:
|
||||
#
|
||||
#%# family=manual
|
||||
#%# capabilities=autoconf
|
||||
|
||||
LC_ALL="C"
|
||||
|
||||
CINFOBIN="/usr/bin/cpufreq-info"
|
||||
|
||||
nCPU=$(grep -c "^processor" /proc/cpuinfo)
|
||||
|
||||
function getFreq ()
|
||||
{
|
||||
i=0
|
||||
while ((i < nCPU)); do
|
||||
affc=`$CINFOBIN -a -c $i`
|
||||
internal=`echo $affc | tr ' ' '_'`
|
||||
cpus=( $affc )
|
||||
n=${#cpus[@]}
|
||||
|
||||
freq=`$CINFOBIN -f -c $i`
|
||||
echo "freq_$internal.value $freq"
|
||||
|
||||
((i += n))
|
||||
done
|
||||
}
|
||||
|
||||
function getAvail ()
|
||||
{
|
||||
i=0
|
||||
while ((i < nCPU)); do
|
||||
affc=`$CINFOBIN -a -c $i`
|
||||
internal=`echo $affc | tr ' ' '_'`
|
||||
label=`echo $affc | tr ' ' ','`
|
||||
cpus=( $affc )
|
||||
n=${#cpus[@]}
|
||||
|
||||
echo "freq_$internal.label CPU $i (Core $label)"
|
||||
echo "freq_$internal.type GAUGE"
|
||||
echo "freq_$internal.info Hz"
|
||||
|
||||
((i += n))
|
||||
done
|
||||
}
|
||||
|
||||
function config ()
|
||||
{
|
||||
cat <<CONFIGTXT
|
||||
graph_title CPU frequency(s)
|
||||
graph_args --base 1000 -l 0
|
||||
graph_vlabel Hz
|
||||
graph_category system
|
||||
graph_info This graph shows the CPU frequency(s).
|
||||
CONFIGTXT
|
||||
getAvail
|
||||
}
|
||||
|
||||
function autoconf ()
|
||||
{
|
||||
if [ -x $CINFOBIN ]; then
|
||||
echo "yes"
|
||||
else
|
||||
echo "no"
|
||||
fi
|
||||
exit 0
|
||||
}
|
||||
|
||||
case $1 in
|
||||
"autoconf")
|
||||
autoconf
|
||||
;;
|
||||
"config")
|
||||
config
|
||||
;;
|
||||
*)
|
||||
getFreq
|
||||
;;
|
||||
esac
|
||||
|
|
@ -1,193 +0,0 @@
|
|||
#!/usr/bin/perl -w
|
||||
#
|
||||
# munin plugin for monitoring cpu frequency
|
||||
# Since multiple cpus on one graph doesn't really work, this plugin links to a cpu, i.e. cpufreq_cpu0
|
||||
#
|
||||
# written by BenV / JuNe
|
||||
# email: benv-munin@junerules.com
|
||||
#
|
||||
# Version: 0.1
|
||||
#
|
||||
# Requires:
|
||||
# Storable (saving state)
|
||||
#
|
||||
# Parameters:
|
||||
#
|
||||
# config required
|
||||
#
|
||||
# Configurable variables
|
||||
# statedir location where the state file is saved. Defaults to /var/lib/munin/plugin-state.
|
||||
# statefile name that's appended to statedir as filename for saving state. Defaults to "cpufreq_$cpu.state"
|
||||
#
|
||||
#%# family=auto
|
||||
#%# capabilities=autoconf suggest
|
||||
|
||||
use strict;
|
||||
|
||||
if ($ARGV[0] and $ARGV[0] eq "autoconf" ) {
|
||||
# Check required perl modules
|
||||
unless (eval "require Storable")
|
||||
{
|
||||
print "No (Missing Storable)\n";
|
||||
exit 1;
|
||||
}
|
||||
# Check for required proc/sys files
|
||||
if (-d "/sys/devices/system/cpu/cpu0/cpufreq")
|
||||
{
|
||||
print "Yes\n";
|
||||
exit 0;
|
||||
}
|
||||
print "No (Couldn't find /sys/devices/system/cpu/cpu0/cpufreq dir)";
|
||||
exit 1;
|
||||
}
|
||||
|
||||
if ($ARGV[0] and $ARGV[0] eq 'suggest' ) {
|
||||
foreach my $d (</sys/devices/system/cpu/cpu[0-9]*/cpufreq/>)
|
||||
{
|
||||
$d =~ /(cpu[0-9]+)/i;
|
||||
print "$1\n";
|
||||
}
|
||||
exit 0;
|
||||
}
|
||||
|
||||
if (eval "require Storable")
|
||||
{
|
||||
Storable->import(qw /lock_store lock_nstore lock_retrieve/);
|
||||
}
|
||||
else
|
||||
{
|
||||
die "Sorry, you don't have Storable. (update your perl!)\n";
|
||||
}
|
||||
|
||||
# Let's see what is requested.
|
||||
my $target;
|
||||
if ($0 =~ /_(cpu\d+)$/i)
|
||||
{
|
||||
$target = $1;
|
||||
}
|
||||
else
|
||||
{
|
||||
die "Error: we need to know what cpu you want, so link this plugin as cpufreq_cpu0 orso.";
|
||||
}
|
||||
|
||||
my $statedir = $ENV{"statedir"} || "/var/lib/munin/plugin-state/";
|
||||
my $statefile = $statedir.($ENV{"statefile"} || "/cpufreq_$target.state");
|
||||
$statefile = glob($statefile); # Make it saner, remove tildes. Not foolproof though ;)
|
||||
|
||||
my $cpufreq;
|
||||
|
||||
eval { $cpufreq = lock_retrieve($statefile); };
|
||||
unless(defined($cpufreq))
|
||||
{
|
||||
print STDERR "Couldn't read state file! (ignore this error on first run)\n";
|
||||
$cpufreq = {};
|
||||
}
|
||||
|
||||
my $cpufreq_now = {};
|
||||
foreach my $d (</sys/devices/system/cpu/$target/cpufreq/stats/>)
|
||||
{
|
||||
unless(open(TIS, "<", "$d"."/time_in_state"))
|
||||
{
|
||||
die "Could not open ${d}/time_in_state: $!\n";
|
||||
}
|
||||
$d =~ /(cpu[0-9]+)/i;
|
||||
my $cpu = $1;
|
||||
while(<TIS>)
|
||||
{
|
||||
if (/^(\d+)\s(\d+)/)
|
||||
{
|
||||
$cpufreq_now->{$cpu}{$1} = $2;
|
||||
$cpufreq_now->{total}{$cpu} = 0 unless(defined($cpufreq_now->{$cpu}));
|
||||
$cpufreq_now->{total}{$cpu} += $2;
|
||||
}
|
||||
}
|
||||
close(TIS);
|
||||
}
|
||||
|
||||
# Let's figure out the percentages.
|
||||
my %freq_p;
|
||||
my $cpu = $target;
|
||||
foreach my $freq (keys %{$cpufreq_now->{$cpu}})
|
||||
{
|
||||
my $new = $cpufreq_now->{$cpu}{$freq};
|
||||
my $old = (defined($cpufreq->{$cpu}{$freq})?$cpufreq->{$cpu}{$freq}:0); # If no old data, we average everything.
|
||||
my $total = $cpufreq_now->{total}{$cpu};
|
||||
$total -= $cpufreq->{total}{$cpu} if (defined($cpufreq->{total}{$cpu}));
|
||||
if (defined($total) && $total > 0)
|
||||
{
|
||||
my $p = ($new - $old) / $total;
|
||||
$freq_p{$cpu}{$freq} = $p * 100.0;
|
||||
$freq_p{avg}{$cpu} += $p * $freq; # Average speed, weighted average
|
||||
}
|
||||
else
|
||||
{
|
||||
$freq_p{$cpu}{$freq} = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if ( $ARGV[0] and $ARGV[0] eq "config" )
|
||||
{
|
||||
print "graph_title Cpu frequency usage of $target\n";
|
||||
print "graph_args --base 1000 -l 0\n";
|
||||
print "graph_vlabel CPU Frequency %\n";
|
||||
print "graph_category System\n";
|
||||
print "graph_info This graph shows information about the cpu frequency scaling of your CPU(s)\n";
|
||||
|
||||
my $count = 0;
|
||||
my ($r,$g,$blue) = (0,255,0);
|
||||
my $range = scalar(keys(%{$freq_p{$cpu}}));
|
||||
my $step = (255+255) / ($range - 1);
|
||||
# In order to let color work, let's go from green to yellow to red -- 00FF00 to FFFF00 to FF0000. 256 and 256 steps.
|
||||
foreach my $freq (sort { $a <=> $b } keys %{$freq_p{$cpu}})
|
||||
{
|
||||
printf "freq_%d.label %s\n", $freq, "$freq KHz";
|
||||
printf "freq_%d.info %s\n", $freq, "Time $cpu spent (percentage) running on $freq KHz";
|
||||
printf "freq_%d.type GAUGE\n", $freq;
|
||||
printf "freq_%d.draw %s\n", $freq, ($count++?"STACK":"AREA");
|
||||
printf "freq_%d.colour %02X%02X%02X\n", $freq, $r,$g,$blue;
|
||||
# Update color
|
||||
my $s = $step;
|
||||
if ($r < 255)
|
||||
{
|
||||
$r += $s;
|
||||
if ($r > 255)
|
||||
{
|
||||
$s = $r - 255;
|
||||
$r = 255;
|
||||
$g -= $s;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$g -= $step;
|
||||
$g = 0 if ($g < 0);
|
||||
}
|
||||
}
|
||||
printf "cpuspeed_avg.label %s\n", "Average speed of cpu $cpu";
|
||||
printf "cpuspeed_avg.info %s\n", "Average speed of cpu $cpu scaled to a percentage";
|
||||
printf "cpuspeed_avg.GAUGE\n";
|
||||
printf "cpuspeed_avg.LINE2\n";
|
||||
printf "cpuspeed_avg.colour 0000FF\n";
|
||||
exit 0;
|
||||
}
|
||||
|
||||
# Print requested garbage.
|
||||
foreach my $freq (sort { $a <=> $b } keys %{$freq_p{$cpu}})
|
||||
{
|
||||
printf "freq_%d.value %s\n", $freq, $freq_p{$cpu}{$freq};
|
||||
}
|
||||
# Average speed should be as a percentage as well. So divide it by the max freq.
|
||||
my $max_freq = (sort { $a <=> $b } keys %{$freq_p{$cpu}})[-1];
|
||||
if (defined($max_freq) && $max_freq > 0)
|
||||
{
|
||||
printf "cpuspeed_avg.value %d\n", $freq_p{avg}{$cpu} / $max_freq * 100;
|
||||
}
|
||||
|
||||
# Save state!
|
||||
eval { lock_nstore($cpufreq_now, $statefile) };
|
||||
if ($@)
|
||||
{
|
||||
print STDERR "[$0] Error writing state file!\n";
|
||||
}
|
||||
|
||||
exit 0;
|
|
@ -1,34 +0,0 @@
|
|||
#!/bin/bash
|
||||
#
|
||||
# Munin-plugin to monitor the CPU temperature using mbmon
|
||||
#
|
||||
# Used the plugin-frame from "cpuload" by Bjørn Ruberg, published under the GNU GPL
|
||||
#
|
||||
# Plugin monitors the cpu-frequency for both cores of my AMD 64-X2-3600+. Works fine running Debian
|
||||
# GNU/Linux 4.0 (Etch). I do not know any perl and will not proceed in developing this plugin any further.
|
||||
# If you wish to, feel free to do so yourself. If I am able to, I will help with any problems, contact me
|
||||
# via Mail (x-stars <at> gmx.de) or through the Debian-German-User-Mailing-List.
|
||||
#
|
||||
# Frank-Michael Schulze, 21-09-2007
|
||||
# Licensed under: GNU GPL
|
||||
|
||||
|
||||
|
||||
|
||||
if [ "$1" = "config" ]; then
|
||||
echo "graph_title CPU speed"
|
||||
echo 'graph_category system'
|
||||
echo "graph_info This graph shows the cpu-speed for each core, as reported by the kernel"
|
||||
echo 'core0.label Core 0 speed in MHz'
|
||||
echo 'core1.label Core 1 speed in MHz'
|
||||
echo "core0.info Core 0 speed in MHz"
|
||||
echo "core1.info Core 1 speed in MHz"
|
||||
echo "core0.type GAUGE"
|
||||
echo "core1.type GAUGE"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo -n "core0.value "
|
||||
cat /proc/cpuinfo | grep MHz | head -n 1 | cut -c 12- | awk '{ sum += $1 } END { print sum }'
|
||||
echo -n "core1.value "
|
||||
cat /proc/cpuinfo | grep MHz | tail -n 1 | cut -c 12- | awk '{ sum += $1 } END { print sum }'
|
|
@ -1,45 +0,0 @@
|
|||
#!/bin/bash
|
||||
#
|
||||
# Munin-plugin to monitor the cpu speeds of all available cpus
|
||||
#
|
||||
# Armin Haaf, 4-11-2007
|
||||
# Licensed under: GNU GPL
|
||||
|
||||
MAX_CORES=1024
|
||||
|
||||
|
||||
if [ "$1" = "config" ]; then
|
||||
echo "graph_title CPU speed"
|
||||
echo 'graph_category system'
|
||||
echo "graph_info This graph shows the cpu-speed for each core, as reported by the kernel"
|
||||
|
||||
i=0
|
||||
while [ $i -lt $MAX_CORES ]
|
||||
do
|
||||
MODEL=`cat /proc/cpuinfo | grep -A 6 "processor.*:.*$i" | grep "model name"`
|
||||
if [ $? -ne 0 ]
|
||||
then
|
||||
break
|
||||
fi
|
||||
MODEL=`echo $MODEL | cut -c 12-`
|
||||
echo "core$i.label Core $i speed in MHz"
|
||||
echo "core$i.info Core $i speed in MHz $MODEL"
|
||||
echo "core$i.type GAUGE"
|
||||
i=$[$i+1]
|
||||
done
|
||||
exit 0
|
||||
fi
|
||||
|
||||
i=0
|
||||
while true
|
||||
do
|
||||
cat /proc/cpuinfo | grep -A 6 "processor.*:.*$i" > /dev/null
|
||||
if [ $? -ne 0 ]
|
||||
then
|
||||
break
|
||||
fi
|
||||
echo -n "core$i.value "
|
||||
cat /proc/cpuinfo | grep -A 6 "processor.*:.*$i" | grep "cpu MHz" | cut -c 12- | cut -f 1 -d .
|
||||
i=$[$i+1]
|
||||
done
|
||||
|
|
@ -1,60 +0,0 @@
|
|||
#!/bin/sh
|
||||
#
|
||||
# Plugin to graph cpu speed on FreeBSD
|
||||
#
|
||||
# Parameters:
|
||||
#
|
||||
# sysctl - Override path to sysctl program
|
||||
#
|
||||
#%# family=auto
|
||||
#%# capabilities=autoconf
|
||||
|
||||
sysctl=${sysctl:-/sbin/sysctl}
|
||||
|
||||
if [ "$1" = "autoconf" ]; then
|
||||
if [ -x ${sysctl} ]; then
|
||||
${sysctl} dev.cpu.0.freq 2>/dev/null | grep 'dev' >/dev/null 2>/dev/null
|
||||
if [ "$?" = "0" ]; then
|
||||
echo yes
|
||||
exit 0
|
||||
fi
|
||||
echo "no (dev.cpu.0.freq not found)"
|
||||
exit 1
|
||||
else
|
||||
echo "no (sysctl binary not found)"
|
||||
exit 2
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "$1" = "config" ]; then
|
||||
|
||||
echo 'graph_title CPU speed'
|
||||
echo 'graph_args --base 1000 -l 0'
|
||||
echo 'graph_vlabel speed in MHz'
|
||||
echo 'graph_category system'
|
||||
echo 'graph_scale no'
|
||||
echo 'graph_info Current CPU speed in MHz. Available levels for the CPU:' `$sysctl -n dev.cpu.0.freq_levels|sed 's!/[0-9]*!!g;s! !, !g'` 'MHz'
|
||||
|
||||
echo cpu0.label cpu0
|
||||
echo cpu0.info `$sysctl -n hw.model` Speed
|
||||
|
||||
exit 0
|
||||
fi
|
||||
|
||||
file=/usr/local/var/munin/plugin-state/cpuspeed
|
||||
|
||||
echo -n "cpu0.value "
|
||||
if find $file -mtime -300s 2>/dev/null|grep -Fq $file ; then
|
||||
head -1 $file
|
||||
else
|
||||
$sysctl -n dev.cpu.0.freq
|
||||
fi
|
||||
|
||||
# Get/cache cpuspeed "later".
|
||||
export sysctl file
|
||||
sh -c '(
|
||||
rand=$(dd if=/dev/urandom bs=1 count=1 2>/dev/null|od -A n -D)
|
||||
rand=$(expr $rand \* 60 / 256 + 25)
|
||||
sleep $rand
|
||||
$sysctl -n dev.cpu.0.freq > $file
|
||||
)&' >/dev/null 2>&1
|
|
@ -1,50 +0,0 @@
|
|||
#!/bin/sh
|
||||
#
|
||||
# Plugin to get system uptime and kernel age
|
||||
#
|
||||
# Magic markers - optional - used by installation scripts and
|
||||
# munin-config:
|
||||
#
|
||||
#%# family=manual
|
||||
#%# capabilities=autoconf
|
||||
|
||||
if [ "$1" = "autoconf" ]; then
|
||||
echo "yes"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [ "$1" = "config" ]; then
|
||||
|
||||
cat <<EOT
|
||||
graph_title Uptime
|
||||
graph_args --base 1000 -l 0
|
||||
graph_vlabel days
|
||||
graph_category System
|
||||
compile.label kernel age
|
||||
compile.type GAUGE
|
||||
compile.min 0
|
||||
compile.max 1000
|
||||
compile.draw AREA
|
||||
uptime.label uptime
|
||||
uptime.type GAUGE
|
||||
uptime.min 0
|
||||
uptime.max 1000
|
||||
uptime.draw AREA
|
||||
EOT
|
||||
exit 0
|
||||
fi
|
||||
|
||||
LANG=C
|
||||
(
|
||||
/bin/date -j +'%s'
|
||||
/bin/date -jf '%a %b %d %T %Z %Y' \
|
||||
"`/sbin/sysctl kern.version | /usr/bin/sed -Ee '2,9d;s/^kern.version: [^:]+: //'`" +'%s'
|
||||
/sbin/sysctl kern.boottime | /usr/bin/sed -Ee 's/.* sec = ([0-9+].*)\,.*/\1/'
|
||||
) | /usr/bin/awk '
|
||||
BEGIN {
|
||||
getline; now=$0;
|
||||
getline; compile=$0
|
||||
getline; boot=$0;
|
||||
printf "compile.value %.3f\n", (now-compile)/86400
|
||||
printf "uptime.value %.3f\n", (now-boot)/86400
|
||||
}'
|
|
@ -1,30 +0,0 @@
|
|||
#!/bin/sh
|
||||
|
||||
#Plugin created by:
|
||||
# Stephen Hodgson
|
||||
# Malone College - CPSC
|
||||
|
||||
#This script is provided as-is with no warranty or guarantee of any kind.
|
||||
|
||||
#-This simple plugin figures out how many users are logged into the linux box and writes it to a simple Gauge-style graph.
|
||||
#-The plugin takes advantage of the linux 'who' command.
|
||||
# -The who command is cut into the first field (to the first space).
|
||||
# -This is the username field.
|
||||
# -Unfortunately this will log multiples for the same user if multiple terminals are open.
|
||||
# -Then we need to sort the results since uniq only deals with unique elements next in line to each other.
|
||||
# -We find the uniqe usernames logged on.
|
||||
# -Then wc -l counts how many lines (users) we're left with.
|
||||
|
||||
|
||||
if [ "$1" = "config" ]; then
|
||||
echo 'graph_title Users Online'
|
||||
echo 'graph_args --base 1000 -l 0 '
|
||||
echo 'graph_vlabel Number of users'
|
||||
echo 'graph_category system'
|
||||
echo 'users.label users'
|
||||
echo 'graph_args --base 1000 -l 0'
|
||||
echo 'graph_scale no'
|
||||
exit 0
|
||||
fi
|
||||
echo -n "users.value "
|
||||
echo `who | cut -f -1 -d ' ' | sort | uniq | wc -l`
|
|
@ -1,61 +0,0 @@
|
|||
#!/usr/bin/perl -w
|
||||
|
||||
#Plugin created by:
|
||||
# Stephen Hodgson
|
||||
# Malone College - CPSC
|
||||
# ported to perl and extended by Thomas Gutzler, 2008 (thomas.gutzler@gmail.com)
|
||||
|
||||
# Feel free to modify this plugin, but if you do, be kind and email it back to me. I'm all for improvements that anyone can make.
|
||||
|
||||
# - This simple plugin figures out how many users are logged into the linux box
|
||||
# - The plugin takes advantage of the linux 'who' command.
|
||||
# - The who command is used to list all login names and number of users logged on.
|
||||
# - This information is used to output to values:
|
||||
# 1. total amount of users logged in
|
||||
# 2. amount of unique users logged in
|
||||
|
||||
# Even though this plugin should run without configuration, it is possible to tell it the location of the who command
|
||||
# Configuration example
|
||||
# [usersv2]
|
||||
# env.who_cmd /usr/bin/who
|
||||
|
||||
#%# family=auto
|
||||
#%# capabilities=autoconf
|
||||
|
||||
use strict;
|
||||
|
||||
my $who_cmd = exists $ENV{who_cmd} ? $ENV{who_cmd} : 'who';
|
||||
|
||||
if ((exists $ARGV[0]) && ($ARGV[0] eq "autoconf")) {
|
||||
my @who = ("$who_cmd -q >/dev/null 2>&1");
|
||||
my $ret = system(@who);
|
||||
if ($ret == 0) {
|
||||
print "yes\n";
|
||||
exit 0;
|
||||
} else {
|
||||
print "no\n";
|
||||
exit 1;
|
||||
}
|
||||
}
|
||||
|
||||
if ((exists $ARGV[0]) && ($ARGV[0] eq "config")) {
|
||||
print "graph_title Users Online\n";
|
||||
print "graph_args --base 1000 -l 0\n";
|
||||
print "graph_scale no\n";
|
||||
print "graph_vlabel Number of users\n";
|
||||
print "graph_category system\n";
|
||||
print "graph_info This graph shows the amount of (unique) users logged in\n";
|
||||
print "users.label total users\n";
|
||||
print "users.info something like who | wc -l\n";
|
||||
print "uusers.label unique users\n";
|
||||
print "uusers.info something like who | cut -f -1 -d ' ' | sort | uniq | wc -l\n";
|
||||
exit 0;
|
||||
}
|
||||
|
||||
my @who = split(/\s+/, `$who_cmd -q | head -1`);
|
||||
print "users.value ".scalar(@who)."\n";
|
||||
|
||||
my %who;
|
||||
$who{$_} = 1 foreach (@who);
|
||||
print "uusers.value ".scalar(keys %who)."\n";
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue