1
0
Fork 0
mirror of https://github.com/munin-monitoring/contrib.git synced 2025-07-21 18:41:03 +00:00

More housekeeping.

This commit is contained in:
Diego Elio Pettenò 2012-08-06 22:20:20 -07:00
parent 038c3ce96b
commit e5ce74926d
43 changed files with 0 additions and 0 deletions

View file

@ -1,77 +0,0 @@
#!/bin/sh
#
# Script to monitor CPU usage of Xen domains
#
# Author: unknown
# Modifications: Matthias Pfafferodt, syntron@web.de, Roland Mohrbacher
# License: GPL v. 2
#
# Parameters understood:
#
# conifg (required)
# autoconf (optional - used by munin-config)
#
#%# family=auto
#%# capabilities=autoconf
# statefile: name of seen xen domains
statefile="/var/lib/munin/plugin-state/munin-plugin-xen.state"
if [ "$1" = "autoconf" ]; then
if which xm > /dev/null ; then
echo yes
exit 0
fi
echo "no (xm not found)"
exit 1
fi
if [ "$1" = "config" ]; then
if [ ! -e $statefile ]; then
touch $statefile
fi
echo 'graph_title Xen Domain Utilerisation'
echo 'graph_args --base 1000 -l 0 --upper-limit 100 --rigid'
echo 'graph_scale no'
echo 'graph_vlabel %'
echo 'graph_category xen'
echo 'graph_info This graph shows how many % of the CPU time where used by a domain'
xm list | grep -v "^Name .* Time(s)$" | \
while read name domid mem cpu state time console; do
name=`echo $name | sed -e"s/[-.]/_/g"`
TEST=`less $statefile | grep "^${name}$" | wc -l`
if [ $TEST -ne 1 ]; then
echo "$name" >> $statefile
fi
done
FIRST=1
cat $statefile | sort | \
while read name; do
echo "$name.label $name"
echo "$name.type COUNTER"
if [ $FIRST -eq 1 ]; then
echo "$name.draw AREA"
FIRST=0
else
echo "$name.draw STACK"
fi
echo "$name.min 0"
echo "$name.max 100"
echo "$name.info % of the CPU time spend for $name"
done
exit 0
fi
xm list | grep -v "^Name .* Time(s)$" | \
while read name domid mem cpu state time console; do
name=`echo $name | sed -e "s/[-.]/_/g"`
# only seconds
time=`echo $time | sed -e "s/\..//"`
# scale 60s/60s => 100%/60s
time=`echo "$time*100/60" | bc`
echo "$name.value $time"
done

View file

@ -1,129 +0,0 @@
#!/usr/bin/perl -wT
#
# Script to minitor the cpu usage of Xen domains
#
# Author: Adam Crews <doo <at> shroom <dot> com>
#
# License: GPL
# Based on the origional xen script from Matthias Pfafferodt, syntron at web.de
#
# Note: Your munin config must run this as root.
#
# Parameters
# config (required)
# autoconf (optional - used by munin-config)
#
# Changelog:
# Properly ignore the xentop output header line.
# Ward Vandewege (ward@gnu.org), 2011-04-20
#
#%# family=auto
#%# capabilities=autoconf
# Define where to find xm tools
my $XM = '/usr/sbin/xm';
my $XMTOP = '/usr/sbin/xentop';
##############
# You should not need to edit anything below here
#
use strict;
$ENV{PATH} = '/bin:/usr/bin:/usr/sbin';
my $arg; undef($arg);
if (defined($ARGV[0])) {
$arg = 'config' if ($ARGV[0] eq 'config');
$arg = 'autoconf' if ($ARGV[0] eq 'autoconf');
if ( "$arg" eq 'autoconf') {
if ( -e $XM && -e $XMTOP ) {
print "yes\n";
exit 0;
} else {
print "no ($XM and/or $XMTOP not found\n";
exit 1;
}
}
if ( "$arg" eq 'config') {
my %cnf; undef(%cnf);
%cnf = (
'graph_title' => 'Xen Domain CPU Usage',
'graph_args' => '--base 1000 -l 0 --upper-limit 100 --rigid',
'graph_vlabel' => 'Percent (%)',
'graph_category' => 'xen',
'graph_info' => 'Display the % of CPU Usage for each domain',
);
my @domains = `$XM list`;
shift(@domains); # we dont need the header line
my $cnt = "0";
foreach my $domain ( @domains ) {
my ($dom,undef) = split(/\s/, $domain, 2);
# we need to change - and . to _ or things get weird with the graphs
# some decent quoting would probably fix this, but this works for now
$dom =~ s/[-.]/_/g;
$cnf{ "$dom" . '.label' } = "$dom";
$cnf{ "$dom" . '.draw' } = 'STACK';
$cnf{ "$dom" . '.min' } = '0';
$cnf{ "$dom" . '.max' } = '100';
$cnf{ "$dom" . '.info' } = '% CPU used for ' . "$dom";
if ( "$cnt" == "0") { $cnf{$dom.'.draw'} = 'AREA'; }
$cnt++;
}
foreach my $key (sort(keys(%cnf))) {
print "$key $cnf{$key}\n";
}
exit 0;
}
}
# Nothing was passed as an argument, so let's just return the proper values
my @chunks; undef(@chunks);
{
# run the xentop command a few times because the first reading is not always accurate
local $/ = undef;
@chunks = split(/^xentop - .*$/m, `$XMTOP -b -i2 -d2`);
}
# Take only the last run of xentop
my @stats = split (/\n/,pop(@chunks));
# remove the first 4 items that are junk that we don't need.
shift(@stats);
shift(@stats);
shift(@stats);
shift(@stats);
my %vals; undef(%vals);
foreach my $domain (@stats) {
# trim the leading whitespace
$domain =~ s/^\s+//;
my @v_tmp = split(/\s+/, $domain);
next if ($v_tmp[0] eq 'NAME');
# we need to change - and . to _ or things get weird with the graphs
# some decent quoting would probably fix this, but this works for now
$v_tmp[0] =~ s/[-.]/_/g;
$vals{$v_tmp[0]}{'cpu_percent'} = $v_tmp[3];
$vals{$v_tmp[0]}{'vcpu'} = $v_tmp[8];
if ( $vals{$v_tmp[0]}{'vcpu'} =~ m/n\/a/ ) {
my $cpu = `grep -c "processor" < /proc/cpuinfo`;
if ( $cpu =~ m/^(\d+)$/ ) {
$vals{$v_tmp[0]}{'vcpu'} = $1;
}
}
}
foreach my $key (sort(keys(%vals))) {
print "$key.value " . ($vals{$key}{'cpu_percent'}/$vals{'Domain_0'}{'vcpu'}), "\n";
}

View file

@ -1,242 +0,0 @@
#! /usr/bin/perl
# -*- perl -*-
=head1 NAME
xen_multi - Munin multigraph plugin to monitor Xen domains activity
=head1 APPLICABLE SYSTEMS
This plugin should work on any system running a Xen hypervisor and where xentop
is installed. It also needs Munin 1.4.0 or higher, since it uses AREASTACK
(available from 1.3.3) and multigraph (available from 1.4.0).
=head1 CONFIGURATION
xentop requires superuser privileges, so you need to include in your
configuration:
[xen-multi]
user root
Then restart munin-node and you're done.
=head1 INTERPRETATION
This plugin produces four different graphs: CPU usage, memory usage, disk IOs
and network traffic.
In each graph, all Xen domains (including dom0) have their data stacked, giving
an overall amount of ressources used.
NOTE: xentop always reports 0 for dom0's disk IOs and network traffic, but
both graphs show its entry all the same, so each domain can keep its own color
along the different graphs.
=head2 CPU usage
This graph shows a percentage of the CPU time used by each domain.
=head2 Memory usage
This graph shows the amount of memory (in bytes) used by each domain.
=head2 Disk IOs
This graph shows the number of disk read and write operations for each domain.
=head2 Network traffic
This graph shows the amount of bits received and transmitted for each domain.
=head1 ACKNOWLEDGEMENTS
Michael Renner for the C<diskstats> plugin which I borrowed some code from.
=head1 VERSION
0.90
=head1 MAGIC MARKERS
#%# family=auto
#%# capabilities=autoconf
=head1 AUTHOR
Raphael HALIMI <raphael.halimi@gmail.com>
=head1 LICENSE
GPLv2
=cut
use strict;
use Munin::Plugin;
# autoconf - quite simple
if ($ARGV[0] eq "autoconf") {
if (`which xentop`) {
print "yes\n";
} else {
print "no (xentop not found)\n";
}
exit 0;
}
#
# Common steps for both "config" and a normal run
#
#
# trim_label
#
# Trims a given label to it's non-wrapping size
# $type = 'pos' for normal graphs and 'neg' for mirror graphs
# pos: nnn.nnU_ times 4
# neg: nnn.nnU/nnn.nnU_ times 4
sub trim_label {
my ($type, $label) = @_; my $data_characters;
my ($graph_width, $graph_border_width, $padding_characters, $pixels_per_character) = (400,97,10,6);
if ($type eq 'pos') {$data_characters = 32;} elsif ($type eq 'neg') {$data_characters = 64;} else {return $label;}
my $available_characters = abs(($graph_width+$graph_border_width)/$pixels_per_character)-$padding_characters-$data_characters;
# If the label is longer than the available space, we write as many
# characters as we can on both left and right, and two dots in the middle
if ( $available_characters < length $label ) {
my $center = ($available_characters-2)/2;
$label = substr($label,0,($center)) . '..' . substr($label,-$center);
}
return $label;
}
# Global variables
my (%domains,$domain,$munindomain,$cpusecs,$memk,$nettxk,$netrxk,$vbdrd,$vbdwr);
open (XENTOP,"xentop -b -f -i1 |") or die "Could not execute xentop, $!";
# Now we build a hash of hashes to store information
while (<XENTOP>) {
# Some cleaning first
s/^\s+//; chomp;
# Skip the headers
next if /^NAME/;
# We define only what we need
($domain,undef,$cpusecs,undef,$memk,undef,undef,undef,undef,undef,$nettxk,$netrxk,undef,undef,$vbdrd,$vbdwr,undef,undef,undef) = split(/\s+/);
# We have to store the sanitised domain name in a separate variable
$domains{$domain}{'munindomain'} = clean_fieldname($domain);
# We need the remaining data only for a normal run
if ($ARGV[0] eq "") {
$domains{$domain}{'cpusecs'} = $cpusecs;
$domains{$domain}{'mem'} = $memk;
$domains{$domain}{'nettx'} = $nettxk;
$domains{$domain}{'netrx'} = $netrxk;
$domains{$domain}{'vbdrd'} = $vbdrd;
$domains{$domain}{'vbdwr'} = $vbdwr;
}
}
#
# config - quite simple, too
#
if ($ARGV[0] eq "config") {
print "multigraph xen_cpu_time\n";
print "graph_title Xen domains CPU time\n";
print "graph_args --base 1000 -l 0\n";
print "graph_vlabel %\n";
print "graph_scale no\n";
print "graph_category xen\n";
print "graph_info This graph shows CPU time for each Xen domain.\n";
for $domain (sort(keys(%domains))) {
print "$domains{$domain}{'munindomain'}_cpu_time.label ".trim_label('pos',$domain)."\n";
print "$domains{$domain}{'munindomain'}_cpu_time.type COUNTER\n";
print "$domains{$domain}{'munindomain'}_cpu_time.cdef $domains{$domain}{'munindomain'}_cpu_time,100,*\n";
print "$domains{$domain}{'munindomain'}_cpu_time.draw AREASTACK\n";
}
print "\nmultigraph xen_mem\n";
print "graph_title Xen domains memory usage\n";
print "graph_args --base 1024 -l 0\n";
print "graph_vlabel bytes\n";
print "graph_category xen\n";
print "graph_info This graph shows memory usage for each Xen domain.\n";
for $domain (sort(keys(%domains))) {
print "$domains{$domain}{'munindomain'}_mem.label ".trim_label('pos',$domain)."\n";
print "$domains{$domain}{'munindomain'}_mem.cdef $domains{$domain}{'munindomain'}_mem,1024,*\n";
print "$domains{$domain}{'munindomain'}_mem.draw AREASTACK\n";
}
print "\nmultigraph xen_net\n";
print "graph_title Xen domains network traffic\n";
print "graph_args --base 1000\n";
print "graph_vlabel bits per \${graph_period} in (-) / out (+)\n";
print "graph_category xen\n";
print "graph_info This graph shows network traffic for each Xen domain.\n";
for $domain (sort(keys(%domains))) {
print "$domains{$domain}{'munindomain'}_netrx.label none\n";
print "$domains{$domain}{'munindomain'}_netrx.cdef $domains{$domain}{'munindomain'}_netrx,8192,*\n";
print "$domains{$domain}{'munindomain'}_netrx.type COUNTER\n";
print "$domains{$domain}{'munindomain'}_netrx.graph no\n";
print "$domains{$domain}{'munindomain'}_nettx.label ".trim_label('neg',$domain)."\n";
print "$domains{$domain}{'munindomain'}_nettx.cdef $domains{$domain}{'munindomain'}_nettx,8192,*\n";
print "$domains{$domain}{'munindomain'}_nettx.type COUNTER\n";
print "$domains{$domain}{'munindomain'}_nettx.draw AREASTACK\n";
print "$domains{$domain}{'munindomain'}_nettx.negative $domains{$domain}{'munindomain'}_netrx\n";
}
print "\nmultigraph xen_disk\n";
print "graph_title Xen domains disk IOs\n";
print "graph_args --base 1000\n";
print "graph_vlabel IOs per \${graph_period} read (-) / write (+)\n";
print "graph_category xen\n";
print "graph_info This graph shows disk IOs for each Xen domain.\n";
for $domain (sort(keys(%domains))) {
print "$domains{$domain}{'munindomain'}_vbdrd.label none\n";
print "$domains{$domain}{'munindomain'}_vbdrd.type COUNTER\n";
print "$domains{$domain}{'munindomain'}_vbdrd.graph no\n";
print "$domains{$domain}{'munindomain'}_vbdwr.label ".trim_label('neg',$domain)."\n";
print "$domains{$domain}{'munindomain'}_vbdwr.type COUNTER\n";
print "$domains{$domain}{'munindomain'}_vbdwr.draw AREASTACK\n";
print "$domains{$domain}{'munindomain'}_vbdwr.negative $domains{$domain}{'munindomain'}_vbdrd\n";
}
exit 0;
}
#
# Normal run
#
print "multigraph xen_cpu_time\n";
for $domain (sort(keys(%domains))) {
print "$domains{$domain}{'munindomain'}_cpu_time.value $domains{$domain}{'cpusecs'}\n";
}
print "\nmultigraph xen_mem\n";
for $domain (sort(keys(%domains))) {
print "$domains{$domain}{'munindomain'}_mem.value $domains{$domain}{'mem'}\n";
}
print "\nmultigraph xen_net\n";
for $domain (sort(keys(%domains))) {
print "$domains{$domain}{'munindomain'}_nettx.value $domains{$domain}{'nettx'}\n";
print "$domains{$domain}{'munindomain'}_netrx.value $domains{$domain}{'netrx'}\n";
}
print "\nmultigraph xen_disk\n";
for $domain (sort(keys(%domains))) {
print "$domains{$domain}{'munindomain'}_vbdrd.value $domains{$domain}{'vbdrd'}\n";
print "$domains{$domain}{'munindomain'}_vbdwr.value $domains{$domain}{'vbdwr'}\n";
}

View file

@ -1,189 +0,0 @@
#!/usr/bin/perl -w
#
# xen_cpu_v2.pl 1.00
# Script to minitor the CPU usage of Xen domains
# Zoltan HERPAI (c) 2009, wigyori@uid0.hu
#
# Based loosely on Adam Crews' xen_cpu script
#
# This script tries to measure the CPU usage of the Xen guests
# accurately.
# The problem with the current monitoring script is that these
# scripts use the CPU output of xentop or xm list, which might be
# inaccurate due to the resources used up at the time of the query by
# the xm or xentop command.
#
# This script stores the previous value of the CPU sec value of the given
# guests in a tempfile, then does some simple calculations to get the real
# CPU usage percentage of the guests.
#
#%# family=auto
#%# capabilities=autoconf
use strict;
use POSIX;
# Define where to find xm tools
my $XM = '/usr/sbin/xm';
my $XMTOP = '/usr/sbin/xentop';
my $curtime = time();
my $basename = `/usr/bin/basename $0`; chop ($basename);
my $TEMPFILE = "/tmp/$basename";
my $debug = 0;
##############
# You should not need to edit anything below here
#
$ENV{PATH} = '/bin:/usr/bin:/usr/sbin';
my $arg;
if ( defined($ARGV[0]) )
{
if ( $ARGV[0] eq 'config' )
{
$arg = 'config';
}
if ( $ARGV[0] eq 'autoconf' )
{
$arg = 'autoconf';
}
if ( $arg eq 'autoconf')
{
if ( -e $XM && -e $XMTOP )
{
print "yes\n";
exit 0;
}
else
{
print "no ($XM and/or $XMTOP not found\n";
exit 1;
}
}
if ( $arg eq 'config' )
{
my %cnf;
%cnf = (
'graph_title' => 'Xen Domain CPU Usage v2',
'graph_args' => '--base 1000 -l 0 --upper-limit 100 --rigid',
'graph_vlabel' => 'Percent (%)',
'graph_category' => 'xen',
'graph_info' => 'Display the % of CPU Usage for each domain',
);
my @domains = `$XM list`;
my $cnt = 0;
shift(@domains); # we dont need the header line
foreach my $domain ( @domains )
{
my ($dom,undef) = split(/\s/, $domain, 2);
$dom =~ s/[-.]/_/g;
$cnf{ "$dom" . '.label' } = "$dom";
$cnf{ "$dom" . '.draw' } = 'STACK';
$cnf{ "$dom" . '.min' } = '0';
$cnf{ "$dom" . '.max' } = '100';
$cnf{ "$dom" . '.info' } = '% CPU used for ' . "$dom";
# $cnf{ "$dom" . '.draw' } = 'AREA';
if ( $cnt == 0 )
{
$cnf{ "$dom" . '.draw' } = 'AREA';
}
$cnt++;
}
foreach my $key (sort(keys(%cnf)))
{
print "$key $cnf{$key}\n";
}
exit 0;
}
}
my @xmlist = `$XM list`;
shift (@xmlist);
my %dom; my $name; my $oldtime;
# Read old data
if ( -e $TEMPFILE )
{
open(FH, "<", $TEMPFILE) or die $!;
$oldtime = <FH>;
if ( $debug )
{
print "Oldtime: $oldtime\n";
}
while (<FH>)
{
# Get the guest name and its CPU usage, and store it in $dom
$_ =~ /(\S+)\s+\S+\s+\S+\s+\d+\s+\S+\s+(\S+)/;
$dom{$1}->{'oldtime'} = $2;
}
close FH;
}
my $diff; my $cpusum = 0;
foreach my $domain ( @xmlist )
{
# Get the domains' name and current CPU usage, store it in $dom
$domain =~ /(\S+)\s+\S+\s+\S+\s+\d+\s+\S+\s+(\S+)/;
$dom{$1}->{'newtime'} = $2;
$diff = $dom{$1}->{'newtime'} - $dom{$1}->{'oldtime'};
$diff = sprintf("%.2f", $diff);
# Calc the diff between old and new cputime, or reset the counter
if ( $diff < 0 )
{
$diff = $dom{$1}->{'newtime'};
}
$dom{$1}->{'diff'} = $diff;
# Calc a sum CPU usage
$cpusum = $cpusum + $diff;
}
my $numcpus = `$XM info |grep nr_cpus |cut -d \: -f 2`;
my $timediff = $curtime - $oldtime;
my $tcpuavail = $numcpus * $timediff;
if ( $debug )
{
print "UsedCPUtime sum: $cpusum\n";
print "CPUs: $numcpus\n";
print "Timediff: $timediff\n";
print "Total CPU time available: $tcpuavail\n";
}
my $key; my $value;
while (($key, $value) = each %dom)
{
# Calc a percentage based on the used CPU time sum
my $tmp = 0;
$tmp = ( $dom{$key}->{'diff'} / $cpusum ) * 100;
$dom{$key}->{'pc_time'} = sprintf("%.2f", $tmp);
# Calc a percentage based on the _total_ available CPU time
$tmp = 0;
$tmp = ( $dom{$key}->{'diff'} / $tcpuavail ) * 100;
$dom{$key}->{'pc_tcpu'} = sprintf("%.2f", $tmp);
if ( $debug )
{
print "$key newtime: ".$dom{$key}->{'newtime'}.", oldtime: ".$dom{$key}->{'oldtime'}.", diff: ".$dom{$key}->{'diff'}.", pc_bytime ".$dom{$key}->{'pc_time'}.", pc_bytcpu ".$dom{$key}->{'pc_tcpu'}."\n";
}
print "$key.value ".$dom{$key}->{'pc_tcpu'}."\n";
}
# We'll need to log out the current "xm list" output, and the current time also.
open(FH, ">", $TEMPFILE) or die $!;
print FH $curtime."\n";
print FH @xmlist;
close FH;

View file

@ -1,67 +0,0 @@
#!/bin/sh
#
# Script to monitor memory status of the xen host
#
# Written by immerda project (admin(_at_)immerda.ch)
# 2007
# License: GPL
#
# Parameters understood:
#
# config (required)
# autoconf (optional - used by munin-config)
#
XM='/usr/sbin/xm'
if [ "$1" = "autoconf" ]; then
if [ -e $XM ]; then
echo yes
exit 0
fi
echo "no (xm not found)"
exit 1
fi
if [ "$1" = "config" ]; then
echo 'graph_title Xen Memory'
echo 'graph_args --base 1000 -l 0'
echo 'graph_scale no'
echo 'graph_vlabel MB'
echo 'graph_category xen'
echo 'graph_info This graph shows of many mS wall time where used by a domain'
# xm info | while read name bla value; do echo "$name $value"; done
$XM info | while read name bla value; do
#total_memory 2047
#free_memory 1476
name=`echo $name | sed -e"s/-/_/"`
if [ "$name" = "total_memory" ]; then
echo "$name.label $name"
echo "$name.type GAUGE"
echo "$name.min 0"
echo "$name.info total memory"
fi
if [ "$name" = "free_memory" ]; then
echo "$name.label $name"
echo "$name.type GAUGE"
echo "$name.draw AREA"
# echo "$name.draw STACK"
echo "$name.min 0"
echo "$name.info free memory"
fi
done
exit 0
fi
$XM info | while read name bla value; do
name=`echo $name | sed -e"s/-/_/"`
if [ "$name" = "total_memory" ]; then
echo "$name.value $value"
fi
if [ "$name" = "free_memory" ]; then
echo "$name.value $value"
fi
done

View file

@ -1,59 +0,0 @@
#!/bin/sh
# Author: mario manno <projects@manno.name>
# Description: measure traffic for one xen host
# Get xen host name from symlink
#
#%# family=auto
#%# capabilities=autoconf suggest
DOMAIN=$( basename $0 | sed 's/^xen_traffic_//g' )
NAME=$( echo $DOMAIN | sed -e's/-/_/g' )
if [ "$1" = "autoconf" ]; then
if which xm > /dev/null ; then
echo yes
else
echo "no (xm not found)"
exit 1
fi
if [ -r /proc/net/dev ]; then
echo yes
else
echo "no (/proc/net/dev not found)"
exit 1
fi
exit 0
fi
if [ "$1" = "suggest" ]; then
xm list | awk '{print $1}' | egrep -v "^(Name|Domain-0)"
exit 0
fi
if [ "$1" = "config" ]; then
echo "graph_title Xen Traffic for $NAME"
echo 'graph_vlabel bits in (-) / out (+) per ${graph_period}'
echo 'graph_args --base 1024 -l 0'
echo 'graph_category xen'
echo 'out.label sent'
echo 'out.type DERIVE'
echo 'out.min 0'
echo 'out.cdef out,8,*'
echo 'in.label received'
echo 'in.type DERIVE'
echo 'in.min 0'
echo 'in.cdef in,8,*'
exit 0
fi
dev=$( xm network-list $DOMAIN | egrep "^[0-9]+" | sed 's@^.*vif/\([0-9]*\)/\([0-9]*\).*$@vif\1.\2@')
awk -v interface="$dev" \
'BEGIN { gsub(/\./, "\\.", interface) } \
$1 ~ "^" interface ":" {
split($0, a, /: */); $0 = a[2]; \
print "in.value " $1 "\nout.value " $9 \
}' \
/proc/net/dev

View file

@ -1,70 +0,0 @@
#!/bin/sh
# Author: mario manno <projects@manno.name>
# Description: measure traffic for all xen hosts
#
# Changelog:
# Also handle domUs with named network interfaces.
# Ward Vandewege (ward@gnu.org), 2011-04-20
#
#%# family=auto
#%# capabilities=autoconf
if [ "$1" = "autoconf" ]; then
if which xm > /dev/null ; then
echo yes
else
echo "no (xm not found)"
exit 1
fi
if [ -r /proc/net/dev ]; then
echo yes
else
echo "no (/proc/net/dev not found)"
exit 1
fi
exit 0
fi
if [ "$1" = "config" ]; then
echo 'graph_title Xen Traffic'
echo 'graph_vlabel bits received (-) / sent (+) per ${graph_period}'
echo 'graph_args --base 1024 -l 0'
echo 'graph_category xen'
DOMAINS=$(xm list | awk '{print $1}' | egrep -v "^(Name|Domain-0)")
for dom in $DOMAINS; do
name=$( echo $dom | tr .- __ )
#echo $name"UP.label $name"
#echo $name"DOWN.label $name"
echo $name'Down.label received'
echo $name'Down.type COUNTER'
echo $name'Down.graph no'
echo "${name}Down.cdef ${name}Down,8,*"
echo "${name}Up.label ${name}"
echo $name'Up.type COUNTER'
echo "${name}Up.negative ${name}Down"
echo "${name}Up.cdef ${name}Up,8,*"
done
exit 0
fi
DOMAINS=$(xm list | awk '{print $1}' | egrep -v "^(Name|Domain-0)")
for dom in $DOMAINS; do
dev=$( xm list $dom --long | awk '/vifname / { print $2 }' | sed 's/)//' )
if [ "$dev" == "" ]; then
dev=$( xm network-list $dom |\
egrep "^[0-9]+" | sed 's@^.*vif/\([0-9]*\)/\([0-9]*\).*$@vif\1.\2@')
fi
name=$( echo $dom | tr .- __ )
#awk -v name="$name" -v interface="$dev" -F'[: \t]+' \
#'{ sub(/^ */,""); if ($1 == interface) \
#print name"DOWN.value "$2"\n"name"UP.value "$10; }' /proc/net/dev
awk -v name="$name" -v interface="$dev" \
'BEGIN { gsub(/\./, "\\.", interface) } \
$1 ~ "^" interface ":" {
split($0, a, /: */); $0 = a[2]; \
print name"Down.value " $1 "\n"name"Up.value " $9 \
}' \
/proc/net/dev
done

View file

@ -1,115 +0,0 @@
#!/usr/bin/perl
#
# 2007-06-01 Zoltan HERPAI <wigyori@uid0.hu>
#
# Credits goes for:
# Adam Crews for his xen_cpu plugin
# Mario Manno for his xen_traffic_all plugin
#
# Script to monitor the I/O usage of Xen domains
# Version 0.1
#
#%# family=auto
#%# capabilities=autoconf
# Location of xm tools
$XM = '/usr/sbin/xm';
$XMTOP = '/usr/sbin/xentop';
# ah, parameters coming in
if ( defined($ARGV[0]))
{
if ($ARGV[0] eq 'config') { $arg = 'config'; }
if ($ARGV[0] eq 'autoconf') { $arg = 'autoconf'; }
if ( $arg eq 'autoconf' )
{
if ( -e $XM && -e $XMTOP )
{
print "yes\n";
exit 0;
}
else
{
print "no ($XM and/or $XMTOP not found\n";
exit 0;
}
}
if ( $arg eq 'config' )
{
%cnf = (
'graph_title' => 'Xen Domain I/O usage',
'graph_args' => '--base 1024 -l 0',
'graph_vlabel' => 'read (-), write (+)',
'graph_category' => 'xen',
'graph_info' => 'Display the I/O operations for each domain',
);
@domains = `$XM list`;
shift(@domains); # we don't need the header line
foreach $domain ( @domains )
{
($dom, undef) = split(/\s/, $domain);
$dom =~ s/[-.]/_/g;
$cnf{ $dom.'RD' . '.label' } = 'read';
$cnf{ $dom.'RD' . '.type' } = 'COUNTER';
$cnf{ $dom.'RD' . '.graph' } = 'no';
$cnf{ $dom.'RD' . '.cdef' } = $dom.'RD,8,*';
$cnf{ $dom.'WR' . '.label' } = $dom;
$cnf{ $dom.'WR' . '.type' } = 'COUNTER';
$cnf{ $dom.'WR' . '.negative' } = $dom.'RD';
$cnf{ $dom.'WR' . '.cdef' } = $dom.'WR,8,*';
if ( "$cnt" == "0" )
{
$cnf { "$dom" . '.draw' } = 'AREA';
}
$cnt++;
}
foreach $key ( sort(keys(%cnf)) )
{
print "$key $cnf{$key}\n";
}
exit 0;
}
}
# No args, get rolling
{
local $/ = undef;
@chunks = split(/^xentop - .*$/m, `$XMTOP -b -i1`);
}
@stats = split (/\n/, pop(@chunks));
shift(@stats);
shift(@stats);
shift(@stats);
shift(@stats);
foreach $domain (@stats)
{
$domain =~ s/^\s+//;
@tmp = split(/\s+/, $domain);
$domname = $tmp[0];
$domname =~ s/[-.]/_/g;
$vbdrd = $tmp[14];
$vbdwr = $tmp[15];
$vals{$domname."RD"}{'value'} = $vbdrd;
$vals{$domname."WR"}{'value'} = $vbdwr;
}
foreach $key ( sort(keys(%vals)) )
{
print "$key.value " . ($vals{$key}{'value'}) . "\n";
}