[PATCH] add contrib/Openvz with perl code to monitor and graph openvz beancounters
Fabian Linzberger
e at lefant.net
Sun Jul 5 13:16:40 CEST 2009
---
contrib/Openvz/OpenVzBeancount.pm | 80 +++++++++++++++++++++++++++
contrib/Openvz/Openvz.pm | 49 +++++++++++++++++
contrib/Openvz/OpenvzFailcnt.pm | 43 +++++++++++++++
contrib/Openvz/README | 107 +++++++++++++++++++++++++++++++++++++
contrib/Openvz/my_types.db | 2 +
5 files changed, 281 insertions(+), 0 deletions(-)
create mode 100644 contrib/Openvz/OpenVzBeancount.pm
create mode 100644 contrib/Openvz/Openvz.pm
create mode 100644 contrib/Openvz/OpenvzFailcnt.pm
create mode 100644 contrib/Openvz/README
create mode 100644 contrib/Openvz/my_types.db
diff --git a/contrib/Openvz/OpenVzBeancount.pm b/contrib/Openvz/OpenVzBeancount.pm
new file mode 100644
index 0000000..f1ee0ae
--- /dev/null
+++ b/contrib/Openvz/OpenVzBeancount.pm
@@ -0,0 +1,80 @@
+package Collectd::Graph::Type::OpenVzBeancount;
+
+use strict;
+use warnings;
+use base ('Collectd::Graph::Type');
+
+use Collectd::Graph::Common (qw($ColorCanvas ident_to_filename get_faded_color));
+
+return (1);
+
+sub new
+{
+ my $pkg = shift;
+ my $obj = Collectd::Graph::Type->new (@_);
+ $obj->{'data_sources'} = [qw(held maxheld barrier limit)];
+ $obj->{'rrd_opts'} = ['-v', 'Count'];
+ $obj->{'rrd_title'} = 'Vz Beancount';
+ $obj->{'rrd_format'} = '%.2lf';
+ $obj->{'colors'} = [qw(00ff00 0000ff ff0000)];
+
+ print STDERR "Hi, this is Collectd::Graph::Type::OpenVzBeancount::new\n";
+
+ return (bless ($obj, $pkg));
+} # new
+
+sub getRRDArgs
+{
+ my $obj = shift;
+ my $index = shift;
+
+ my $ident = $obj->{'files'}[$index];
+ if (!$ident)
+ {
+ cluck ("Invalid index: $index");
+ return;
+ }
+ my $filename = ident_to_filename ($ident);
+ $filename =~ s#:#\\:#g;
+
+ my $faded_green = get_faded_color ('00ff00');
+ my $faded_red = get_faded_color ('ff0000');
+
+ return (['-t', $ident->{'type_instance'}, '-v', 'Vz beancount',
+ "DEF:held_min=${filename}:held:MIN",
+ "DEF:held_avg=${filename}:held:AVERAGE",
+ "DEF:held_max=${filename}:held:MAX",
+ "DEF:maxheld_min=${filename}:maxheld:MIN",
+ "DEF:maxheld_avg=${filename}:maxheld:AVERAGE",
+ "DEF:maxheld_max=${filename}:maxheld:MAX",
+ "DEF:barrier_min=${filename}:barrier:MIN",
+ "DEF:barrier_avg=${filename}:barrier:AVERAGE",
+ "DEF:barrier_max=${filename}:barrier:MAX",
+ "DEF:limit_min=${filename}:limit:MIN",
+ "DEF:limit_avg=${filename}:limit:AVERAGE",
+ "DEF:limit_max=${filename}:limit:MAX",
+ "AREA:maxheld_max#${faded_green}",
+ "AREA:held_min#${ColorCanvas}",
+ "LINE1:held_avg#00ff00: held",
+ "GPRINT:held_min:MIN:%.2lf Min,",
+ "GPRINT:held_avg:AVERAGE:%.2lf Avg,",
+ "GPRINT:held_max:MAX:%.2lf Max,",
+ "GPRINT:held_avg:LAST:%.2lf Last\\l",
+ "LINE1:maxheld_max#${faded_green}: maxheld",
+ "GPRINT:maxheld_min:MIN:%.2lf Min,",
+ "GPRINT:maxheld_avg:AVERAGE:%.2lf Avg,",
+ "GPRINT:maxheld_max:MAX:%.2lf Max,",
+ "GPRINT:maxheld_avg:LAST:%.2lf Last\\l",
+ "LINE1:barrier_max#${faded_red}: barrier",
+ "GPRINT:barrier_min:MIN:%.2lf Min,",
+ "GPRINT:barrier_avg:AVERAGE:%.2lf Avg,",
+ "GPRINT:barrier_max:MAX:%.2lf Max,",
+ "GPRINT:barrier_avg:LAST:%.2lf Last\\l",
+ "LINE1:limit_max#ff0000: limit",
+ "GPRINT:limit_min:MIN:%.2lf Min,",
+ "GPRINT:limit_avg:AVERAGE:%.2lf Avg,",
+ "GPRINT:limit_max:MAX:%.2lf Max,",
+ "GPRINT:limit_avg:LAST:%.2lf Last\\l"]);
+} # sub getRRDArgs
+
+# vim: set shiftwidth=2 softtabstop=2 tabstop=8 :
diff --git a/contrib/Openvz/Openvz.pm b/contrib/Openvz/Openvz.pm
new file mode 100644
index 0000000..1d9d45a
--- /dev/null
+++ b/contrib/Openvz/Openvz.pm
@@ -0,0 +1,49 @@
+package Collectd::Plugins::OpenVz;
+
+use strict;
+use warnings;
+
+use Collectd qw( :all );
+
+sub openvz_init {
+ return ( -e '/proc/user_beancounters' );
+}
+
+sub openvz_read
+{
+ #my @watched = ( 'vmguarpages', 'oomguarpages', 'privvmpages', 'kmemsize' );
+
+ while ( my $vz = </proc/bc/[1-9]*> ) {
+ $vz =~ m!^/proc/bc/(\d+)$!;
+ my $id = $1;
+
+ open( my $in, "<", "$vz/resources" ) or die "Couldn't read $vz/resources: $!";
+ RESOURCE:
+ while ( <$in> ) {
+ my $line = $_;
+ my ( undef, $resource, @values ) = split ( /\s+/, $line );
+
+# unless ( grep { "$_" eq "$resource" } @watched ) {
+# next RESOURCE;
+# }
+
+ # throw failcnt off at the end
+ pop ( @ values );
+
+ my $vl = {
+ plugin => 'openvz',
+ values => [ @values ],
+ plugin_instance => "$id",
+ type_instance => "$resource",
+ };
+ plugin_dispatch_values ('openvz_beancount', $vl);
+
+ }
+ close $in;
+ }
+
+ return 1;
+}
+
+plugin_register (TYPE_INIT, "openvz_beancount", "openvz_init");
+plugin_register (TYPE_READ, "openvz_beancount", "openvz_read");
diff --git a/contrib/Openvz/OpenvzFailcnt.pm b/contrib/Openvz/OpenvzFailcnt.pm
new file mode 100644
index 0000000..ce01965
--- /dev/null
+++ b/contrib/Openvz/OpenvzFailcnt.pm
@@ -0,0 +1,43 @@
+package Collectd::Plugins::OpenvzFailcnt;
+
+use strict;
+use warnings;
+
+use Collectd qw( :all );
+
+sub openvz_init {
+ return ( -e '/proc/user_beancounters' );
+}
+
+sub openvz_read
+{
+ while ( my $vz = </proc/bc/[1-9]*> ) {
+ $vz =~ m!^/proc/bc/(\d+)$!;
+ my $id = $1;
+
+ open( my $in, "<", "$vz/resources" ) or die "Couldn't read $vz/resources: $!";
+
+ my @values = ();
+ while ( <$in> ) {
+ my $line = $_;
+ my ( undef, $resource, @fields ) = split ( /\s+/, $line );
+
+ push (@values, $fields[4]);
+ }
+
+ my $vl = {
+ plugin => 'openvzfailcnt',
+ values => [ @values ],
+ plugin_instance => "$id",
+ type_instance => "cnt",
+ };
+ plugin_dispatch_values ('openvz_failcnt', $vl);
+
+ close $in;
+ }
+
+ return 1;
+}
+
+plugin_register (TYPE_INIT, "openvz_failcnt", "openvz_init");
+plugin_register (TYPE_READ, "openvz_failcnt", "openvz_read");
diff --git a/contrib/Openvz/README b/contrib/Openvz/README
new file mode 100644
index 0000000..ac03d52
--- /dev/null
+++ b/contrib/Openvz/README
@@ -0,0 +1,107 @@
+openvz monitoring via collectd
+==============================
+
+perl ingredients
+----------------
+
+put Openvz.pm and OpenvzFailcnt.pm somewhere in your perl load path.
+
+(i did
+sudo mkdir -p /usr/local/lib/site_perl/Collectd/Plugin/
+sudo cp Openvz.pm OpenvzFailcnt.pm /usr/local/lib/site_perl/Collectd/Plugin/
+)
+
+
+and add something like the following to your collectd.conf
+
+<Plugin perl>
+ IncludeDir "/usr/local/lib/site_perl"
+ BaseName "Collectd::Plugin"
+ LoadPlugin "Openvz"
+</Plugin>
+
+<Plugin perl>
+ IncludeDir "/usr/local/lib/site_perl"
+ BaseName "Collectd::Plugin"
+ LoadPlugin "OpenvzFailcnt"
+</Plugin>
+
+
+custom type
+-----------
+i have
+
+openvz_beancount held:GAUGE:0:U, maxheld:GAUGE:0:U, barrier:GAUGE:0:U, limit:GAUGE:0:U
+
+in /etc/collectd/my_types.db
+
+and include that via
+
+TypesDB "/usr/lib/collectd/types.db" "/etc/collectd/my_types.db"
+
+in /etc/collectd/collectd.conf (all paths from debian, adapt if needed).
+
+
+graphing via collection3 cgi
+----------------------------
+
+OpenVzBeancount.pm is supposed to go in the
+lib/Collectd/Graph/Type/OpenVzBeancount.pm directory of your
+collection3 install for nice graphs of the stats.
+
+then you can add
+
+<Type openvz_beancount>
+ Module OpenVzBeancount
+ DataSources held maxheld barrier limit
+</Type>
+<Type openvz_failcnt>
+ DataSources kmemsize lockedpages privvmpages shmpages numproc physpages vmguarpages oomguarpages numtcpsock numflock numpty numsiginfo tcpsndbuf tcprcvbuf otherso$
+</Type>
+
+to your etc/collection3.conf
+
+
+if you prefer, you can of course also use drraw.
+
+
+nagios monitoring of failcnt
+----------------------------
+
+some snippets from my nagios config for monitoring failcnt to get you
+started:
+
+define command{
+ command_name check_collectd_openvz_failcnt
+ command_line /usr/local/bin/collectd-nagios \
+ -s /var/run/collectd-unixsock -H $HOSTNAME$ \
+ -n openvzfailcnt-$ARG2$/openvz_failcnt-cnt \
+ -d kmemsize \
+ -d lockedpages \
+ -d privvmpages \
+ -d shmpages \
+ -d numproc \
+ -d physpages \
+ -d vmguarpages \
+ -d oomguarpages \
+ -d numtcpsock \
+ -d numflock \
+ -d numpty \
+ -d numsiginfo \
+ -d tcpsndbuf \
+ -d tcprcvbuf \
+ -d othersockbuf \
+ -d dgramrcvbuf \
+ -d numothersock \
+ -d dcachesize \
+ -d numfile \
+ -d numiptent \
+ -g sum -w 0:0 -c 0:0
+}
+
+define service{
+ use generic-service
+ service_description OPENVZ-FAILCNT
+ hostgroup_name OPENVZ-FAILCNT
+ check_command check_collectd_openvz_failcnt!vzid!
+}
diff --git a/contrib/Openvz/my_types.db b/contrib/Openvz/my_types.db
new file mode 100644
index 0000000..c750920
--- /dev/null
+++ b/contrib/Openvz/my_types.db
@@ -0,0 +1,2 @@
+openvz_beancount held:GAUGE:0:U, maxheld:GAUGE:0:U, barrier:GAUGE:0:U, limit:GAUGE:0:U
+openvz_failcnt kmemsize:COUNTER:0:U lockedpages:COUNTER:0:U privvmpages:COUNTER:0:U shmpages:COUNTER:0:U numproc:COUNTER:0:U physpages:COUNTER:0:U vmguarpages:COUNTER:0:U oomguarpages:COUNTER:0:U numtcpsock:COUNTER:0:U numflock:COUNTER:0:U numpty:COUNTER:0:U numsiginfo:COUNTER:0:U tcpsndbuf:COUNTER:0:U tcprcvbuf:COUNTER:0:U othersockbuf:COUNTER:0:U dgramrcvbuf:COUNTER:0:U numothersock:COUNTER:0:U dcachesize:COUNTER:0:U numfile:COUNTER:0:U numiptent:COUNTER:0:U
--
1.5.6.5
--+HP7ph2BbKc20aGI--
More information about the collectd
mailing list