diff options
Diffstat (limited to 'src/pmdas/kvm')
-rw-r--r-- | src/pmdas/kvm/GNUmakefile | 56 | ||||
-rwxr-xr-x | src/pmdas/kvm/Install | 40 | ||||
-rwxr-xr-x | src/pmdas/kvm/Remove | 25 | ||||
-rw-r--r-- | src/pmdas/kvm/pmdakvm.pl | 122 |
4 files changed, 243 insertions, 0 deletions
diff --git a/src/pmdas/kvm/GNUmakefile b/src/pmdas/kvm/GNUmakefile new file mode 100644 index 0000000..6fd0b6a --- /dev/null +++ b/src/pmdas/kvm/GNUmakefile @@ -0,0 +1,56 @@ +#!gmake +# +# Copyright (c) 2008 Aconex. All Rights Reserved. +# +# 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; either version 2 of the License, or (at your +# option) any later version. +# +# 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., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +# + +TOPDIR = ../../.. +include $(TOPDIR)/src/include/builddefs + +IAM = kvm +PMDADIR = $(PCP_PMDAS_DIR)/$(IAM) +LSRCFILES = Install Remove pmda$(IAM).pl +LDIRT = domain.h root pmns *.log $(MAN_PAGES) + +ifneq ($(POD2MAN),) +MAN_SECTION = 1 +MAN_PAGES = pmda$(IAM).$(MAN_SECTION) +MAN_DEST = $(PCP_MAN_DIR)/man$(MAN_SECTION) +endif + +default: check_domain $(MAN_PAGES) + +pmda$(IAM).1: pmda$(IAM).pl + $(POD_MAKERULE) + +include $(BUILDRULES) + +ifeq "$(TARGET_OS)" "linux" +install: default + $(INSTALL) -m 755 -d $(PMDADIR) + $(INSTALL) -m 755 Install Remove $(PMDADIR) + $(INSTALL) -m 644 pmda$(IAM).pl $(PMDADIR)/pmda$(IAM).pl + @$(INSTALL_MAN) +else +install: +endif + +default_pcp : default + +install_pcp : install + +check_domain: ../../pmns/stdpmid + $(DOMAIN_PERLRULE) diff --git a/src/pmdas/kvm/Install b/src/pmdas/kvm/Install new file mode 100755 index 0000000..3317662 --- /dev/null +++ b/src/pmdas/kvm/Install @@ -0,0 +1,40 @@ +#! /bin/sh +# +# Copyright (c) 2008 Aconex. All Rights Reserved. +# +# 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; either version 2 of the License, or (at your +# option) any later version. +# +# 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. +# +# Install the KVM PMDA +# + +. $PCP_DIR/etc/pcp.env +. $PCP_SHARE_DIR/lib/pmdaproc.sh + +iam=kvm +perl_opt=true +daemon_opt=false +forced_restart=true + +if ! test -d /sys/kernel/debug; then + echo "DEBUGFS not enabled in your kernel" + exit 1 +fi +if ! test -d /sys/kernel/debug/kvm; then + echo "KVM statistics unavailable (load kvm module and mount debugfs)" + exit 1 +fi +if ! test -r /sys/kernel/debug/kvm; then + forced_restart=true +fi + +pmdaSetup +pmdaInstall +exit 0 diff --git a/src/pmdas/kvm/Remove b/src/pmdas/kvm/Remove new file mode 100755 index 0000000..1032be0 --- /dev/null +++ b/src/pmdas/kvm/Remove @@ -0,0 +1,25 @@ +#! /bin/sh +# +# Copyright (c) 2008 Aconex. All Rights Reserved. +# +# 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; either version 2 of the License, or (at your +# option) any later version. +# +# 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. +# +# Remove the KVM PMDA +# + +. $PCP_DIR/etc/pcp.env +. $PCP_SHARE_DIR/lib/pmdaproc.sh + +iam=kvm + +pmdaSetup +pmdaRemove +exit 0 diff --git a/src/pmdas/kvm/pmdakvm.pl b/src/pmdas/kvm/pmdakvm.pl new file mode 100644 index 0000000..6eb7419 --- /dev/null +++ b/src/pmdas/kvm/pmdakvm.pl @@ -0,0 +1,122 @@ +# +# Copyright (c) 2012 Red Hat. +# Copyright (c) 2008 Aconex. All Rights Reserved. +# +# 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; either version 2 of the License, or (at your +# option) any later version. +# +# 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. +# + +use strict; +use warnings; +use PCP::PMDA; + +use vars qw( $pmda ); +my $kvm_path = '/sys/kernel/debug/kvm'; + +sub kvm_fetch_callback +{ + my ($cluster, $item, $inst) = @_; + my $metric_name = pmda_pmid_name($cluster, $item); + my ($path, $value, $fh); + + # $pmda->log("kvm_fetch_callback $metric_name $cluster:$item ($inst)\n"); + + if ($inst != PM_IN_NULL) { return (PM_ERR_INST, 0); } + if (!defined($metric_name)) { return (PM_ERR_PMID, 0); } + $path = $metric_name; + $path =~ s/^kvm\./$kvm_path\//; + open($fh, $path) || return (PM_ERR_APPVERSION, 0); + $value = <$fh>; + close $fh; + + if (!defined($value)) { return (PM_ERR_APPVERSION, 0); } + return ($value, 1); +} + +$pmda = PCP::PMDA->new('kvm', 95); +$pmda->connect_pmcd; + +# May need to be root to read the directory $kvm_path (/sys/kernel/debug/kvm) +# and so +# (a) do not use $pmda->set_user('pcp') below, and +# (b) need forced_restart=true in the Install script so pmcd is restarted +# and we're running as root at this point (SIGHUP pmcd once it has +# changed to user "pcp" is not going to work for PMDA installation) +# +my $pmid = 0; +opendir(DIR, $kvm_path) || $pmda->err("pmdakvm failed to open $kvm_path: $!"); +my @metrics = grep { + unless (/^\./) { + $pmda->add_metric(pmda_pmid(0,$pmid++), PM_TYPE_U64, PM_INDOM_NULL, + PM_SEM_COUNTER, pmda_units(0,0,1,0,0,PM_COUNT_ONE), + "kvm.$_", '', ''); + # $pmda->log("pmdakvm added metric kvm.$_\n"); + } +} readdir(DIR); +closedir DIR; + +$pmda->set_fetch_callback(\&kvm_fetch_callback); +# Careful with permissions - may need to be root to read /sys/kernel/debug/kvm +# see note above. +#$pmda->set_user('pcp') if -r $kvm_path; +$pmda->run; + +=pod + +=head1 NAME + +pmdakvm - Linux virtualisation performance metrics domain agent (PMDA) + +=head1 DESCRIPTION + +B<pmdakvm> is a Performance Metrics Domain Agent (PMDA) which exports +metric values from the Linux KVM virtualisation subsystem. + +Unlike many PMDAs it dynamically enumerates its metric hierarchy, +based entirely on the contents of /sys/kernel/debug/kvm. + +=head1 INSTALLATION + +If you want access to the names and values for the kvm performance +metrics, do the following as root: + + # cd $PCP_PMDAS_DIR/kvm + # ./Install + +If you want to undo the installation, do the following as root: + + # cd $PCP_PMDAS_DIR/kvm + # ./Remove + +B<pmdakvm> is launched by pmcd(1) and should never be executed +directly. The Install and Remove scripts notify pmcd(1) when +the agent is installed or removed. + +=head1 FILES + +=over + +=item $PCP_PMDAS_DIR/kvm/Install + +installation script for the B<pmdakvm> agent + +=item $PCP_PMDAS_DIR/kvm/Remove + +undo installation script for the B<pmdakvm> agent + +=item $PCP_LOG_DIR/pmcd/kvm.log + +default log file for error messages from B<pmdakvm> + +=back + +=head1 SEE ALSO + +pmcd(1) and kvm(1). |