From c91621a0953d97a83f62205519524708c279a24e Mon Sep 17 00:00:00 2001 From: "Christian G. Warden" Date: Thu, 2 Feb 2012 18:19:33 -0800 Subject: Fix munin.conf for squeeze and later Debian releases Add support for lsbdistcodename-specific munin.conf.header files. Create squeeze munin.conf.header file which contains the new htmldir setting, /var/cache/munin/www, and symlink wheezy and sid to it. --- files/config/host/munin.conf.header.Debian.sid | 1 + files/config/host/munin.conf.header.Debian.squeeze | 75 ++++++++++++++++++++++ files/config/host/munin.conf.header.Debian.wheezy | 1 + 3 files changed, 77 insertions(+) create mode 120000 files/config/host/munin.conf.header.Debian.sid create mode 100644 files/config/host/munin.conf.header.Debian.squeeze create mode 120000 files/config/host/munin.conf.header.Debian.wheezy (limited to 'files') diff --git a/files/config/host/munin.conf.header.Debian.sid b/files/config/host/munin.conf.header.Debian.sid new file mode 120000 index 0000000..5fa2037 --- /dev/null +++ b/files/config/host/munin.conf.header.Debian.sid @@ -0,0 +1 @@ +munin.conf.header.Debian.squeeze \ No newline at end of file diff --git a/files/config/host/munin.conf.header.Debian.squeeze b/files/config/host/munin.conf.header.Debian.squeeze new file mode 100644 index 0000000..771d50d --- /dev/null +++ b/files/config/host/munin.conf.header.Debian.squeeze @@ -0,0 +1,75 @@ +# Example configuration file for Munin, generated by 'make build' + +# The next three variables specifies where the location of the RRD +# databases, the HTML output, and the logs, severally. They all +# must be writable by the user running munin-cron. +dbdir /var/lib/munin +htmldir /var/cache/munin/www +logdir /var/log/munin +rundir /var/run/munin + +# Where to look for the HTML templates +tmpldir /etc/munin/templates + +# Make graphs show values per minute instead of per second +#graph_period minute + +# Drop somejuser@fnord.comm and anotheruser@blibb.comm an email everytime +# something changes (OK -> WARNING, CRITICAL -> OK, etc) +#contact.someuser.command mail -s "Munin notification" somejuser@fnord.comm +#contact.anotheruser.command mail -s "Munin notification" anotheruser@blibb.comm +# +# For those with Nagios, the following might come in handy. In addition, +# the services must be defined in the Nagios server as well. +#contact.nagios.command /usr/sbin/send_nsca -H nagios.host.com -c /etc/send_nsca.cfg + +#contacts me +#contact.me.command mail -s "Munin notification ${var:group} :: ${var:host} :: ${var:graph_title}" root +#contact.me.always_send warning critical + +# a simple host tree +#[localhost] +# address 127.0.0.1 +# use_node_name yes + +# +# A more complex example of a host tree +# +## First our "normal" host. +# [fii.foo.com] +# address foo +# +## Then our other host... +# [fay.foo.com] +# address fay +# +## Then we want totals... +# [foo.com;Totals] #Force it into the "foo.com"-domain... +# update no # Turn off data-fetching for this "host". +# +# # The graph "load1". We want to see the loads of both machines... +# # "fii=fii.foo.com:load.load" means "label=machine:graph.field" +# load1.graph_title Loads side by side +# load1.graph_order fii=fii.foo.com:load.load fay=fay.foo.com:load.load +# +# # The graph "load2". Now we want them stacked on top of each other. +# load2.graph_title Loads on top of each other +# load2.dummy_field.stack fii=fii.foo.com:load.load fay=fay.foo.com:load.load +# load2.dummy_field.draw AREA # We want area instead the default LINE2. +# load2.dummy_field.label dummy # This is needed. Silly, really. +# +# # The graph "load3". Now we want them summarised into one field +# load3.graph_title Loads summarised +# load3.combined_loads.sum fii.foo.com:load.load fay.foo.com:load.load +# load3.combined_loads.label Combined loads # Must be set, as this is +# # not a dummy field! +# +## ...and on a side note, I want them listen in another order (default is +## alphabetically) +# +# # Since [foo.com] would be interpreted as a host in the domain "com", we +# # specify that this is a domain by adding a semicolon. +# [foo.com;] +# node_order Totals fii.foo.com fay.foo.com +# + diff --git a/files/config/host/munin.conf.header.Debian.wheezy b/files/config/host/munin.conf.header.Debian.wheezy new file mode 120000 index 0000000..5fa2037 --- /dev/null +++ b/files/config/host/munin.conf.header.Debian.wheezy @@ -0,0 +1 @@ +munin.conf.header.Debian.squeeze \ No newline at end of file -- cgit v1.2.3 From 9fd1de5acd9064a0d67ca9d2c13a829a3f628f39 Mon Sep 17 00:00:00 2001 From: mh Date: Tue, 5 Jun 2012 19:39:49 -0300 Subject: new style for 2.7 --- files/config/host/munin.conf.header.Debian.sid | 76 ++++++++++++++++++++++- files/config/host/munin.conf.header.Debian.wheezy | 76 ++++++++++++++++++++++- 2 files changed, 150 insertions(+), 2 deletions(-) mode change 120000 => 100644 files/config/host/munin.conf.header.Debian.sid mode change 120000 => 100644 files/config/host/munin.conf.header.Debian.wheezy (limited to 'files') diff --git a/files/config/host/munin.conf.header.Debian.sid b/files/config/host/munin.conf.header.Debian.sid deleted file mode 120000 index 5fa2037..0000000 --- a/files/config/host/munin.conf.header.Debian.sid +++ /dev/null @@ -1 +0,0 @@ -munin.conf.header.Debian.squeeze \ No newline at end of file diff --git a/files/config/host/munin.conf.header.Debian.sid b/files/config/host/munin.conf.header.Debian.sid new file mode 100644 index 0000000..771d50d --- /dev/null +++ b/files/config/host/munin.conf.header.Debian.sid @@ -0,0 +1,75 @@ +# Example configuration file for Munin, generated by 'make build' + +# The next three variables specifies where the location of the RRD +# databases, the HTML output, and the logs, severally. They all +# must be writable by the user running munin-cron. +dbdir /var/lib/munin +htmldir /var/cache/munin/www +logdir /var/log/munin +rundir /var/run/munin + +# Where to look for the HTML templates +tmpldir /etc/munin/templates + +# Make graphs show values per minute instead of per second +#graph_period minute + +# Drop somejuser@fnord.comm and anotheruser@blibb.comm an email everytime +# something changes (OK -> WARNING, CRITICAL -> OK, etc) +#contact.someuser.command mail -s "Munin notification" somejuser@fnord.comm +#contact.anotheruser.command mail -s "Munin notification" anotheruser@blibb.comm +# +# For those with Nagios, the following might come in handy. In addition, +# the services must be defined in the Nagios server as well. +#contact.nagios.command /usr/sbin/send_nsca -H nagios.host.com -c /etc/send_nsca.cfg + +#contacts me +#contact.me.command mail -s "Munin notification ${var:group} :: ${var:host} :: ${var:graph_title}" root +#contact.me.always_send warning critical + +# a simple host tree +#[localhost] +# address 127.0.0.1 +# use_node_name yes + +# +# A more complex example of a host tree +# +## First our "normal" host. +# [fii.foo.com] +# address foo +# +## Then our other host... +# [fay.foo.com] +# address fay +# +## Then we want totals... +# [foo.com;Totals] #Force it into the "foo.com"-domain... +# update no # Turn off data-fetching for this "host". +# +# # The graph "load1". We want to see the loads of both machines... +# # "fii=fii.foo.com:load.load" means "label=machine:graph.field" +# load1.graph_title Loads side by side +# load1.graph_order fii=fii.foo.com:load.load fay=fay.foo.com:load.load +# +# # The graph "load2". Now we want them stacked on top of each other. +# load2.graph_title Loads on top of each other +# load2.dummy_field.stack fii=fii.foo.com:load.load fay=fay.foo.com:load.load +# load2.dummy_field.draw AREA # We want area instead the default LINE2. +# load2.dummy_field.label dummy # This is needed. Silly, really. +# +# # The graph "load3". Now we want them summarised into one field +# load3.graph_title Loads summarised +# load3.combined_loads.sum fii.foo.com:load.load fay.foo.com:load.load +# load3.combined_loads.label Combined loads # Must be set, as this is +# # not a dummy field! +# +## ...and on a side note, I want them listen in another order (default is +## alphabetically) +# +# # Since [foo.com] would be interpreted as a host in the domain "com", we +# # specify that this is a domain by adding a semicolon. +# [foo.com;] +# node_order Totals fii.foo.com fay.foo.com +# + diff --git a/files/config/host/munin.conf.header.Debian.wheezy b/files/config/host/munin.conf.header.Debian.wheezy deleted file mode 120000 index 5fa2037..0000000 --- a/files/config/host/munin.conf.header.Debian.wheezy +++ /dev/null @@ -1 +0,0 @@ -munin.conf.header.Debian.squeeze \ No newline at end of file diff --git a/files/config/host/munin.conf.header.Debian.wheezy b/files/config/host/munin.conf.header.Debian.wheezy new file mode 100644 index 0000000..771d50d --- /dev/null +++ b/files/config/host/munin.conf.header.Debian.wheezy @@ -0,0 +1,75 @@ +# Example configuration file for Munin, generated by 'make build' + +# The next three variables specifies where the location of the RRD +# databases, the HTML output, and the logs, severally. They all +# must be writable by the user running munin-cron. +dbdir /var/lib/munin +htmldir /var/cache/munin/www +logdir /var/log/munin +rundir /var/run/munin + +# Where to look for the HTML templates +tmpldir /etc/munin/templates + +# Make graphs show values per minute instead of per second +#graph_period minute + +# Drop somejuser@fnord.comm and anotheruser@blibb.comm an email everytime +# something changes (OK -> WARNING, CRITICAL -> OK, etc) +#contact.someuser.command mail -s "Munin notification" somejuser@fnord.comm +#contact.anotheruser.command mail -s "Munin notification" anotheruser@blibb.comm +# +# For those with Nagios, the following might come in handy. In addition, +# the services must be defined in the Nagios server as well. +#contact.nagios.command /usr/sbin/send_nsca -H nagios.host.com -c /etc/send_nsca.cfg + +#contacts me +#contact.me.command mail -s "Munin notification ${var:group} :: ${var:host} :: ${var:graph_title}" root +#contact.me.always_send warning critical + +# a simple host tree +#[localhost] +# address 127.0.0.1 +# use_node_name yes + +# +# A more complex example of a host tree +# +## First our "normal" host. +# [fii.foo.com] +# address foo +# +## Then our other host... +# [fay.foo.com] +# address fay +# +## Then we want totals... +# [foo.com;Totals] #Force it into the "foo.com"-domain... +# update no # Turn off data-fetching for this "host". +# +# # The graph "load1". We want to see the loads of both machines... +# # "fii=fii.foo.com:load.load" means "label=machine:graph.field" +# load1.graph_title Loads side by side +# load1.graph_order fii=fii.foo.com:load.load fay=fay.foo.com:load.load +# +# # The graph "load2". Now we want them stacked on top of each other. +# load2.graph_title Loads on top of each other +# load2.dummy_field.stack fii=fii.foo.com:load.load fay=fay.foo.com:load.load +# load2.dummy_field.draw AREA # We want area instead the default LINE2. +# load2.dummy_field.label dummy # This is needed. Silly, really. +# +# # The graph "load3". Now we want them summarised into one field +# load3.graph_title Loads summarised +# load3.combined_loads.sum fii.foo.com:load.load fay.foo.com:load.load +# load3.combined_loads.label Combined loads # Must be set, as this is +# # not a dummy field! +# +## ...and on a side note, I want them listen in another order (default is +## alphabetically) +# +# # Since [foo.com] would be interpreted as a host in the domain "com", we +# # specify that this is a domain by adding a semicolon. +# [foo.com;] +# node_order Totals fii.foo.com fay.foo.com +# + -- cgit v1.2.3 From 405cd4fcc4639e4c9f204bcebf852aeaf6a1b129 Mon Sep 17 00:00:00 2001 From: mh Date: Wed, 12 Sep 2012 13:04:33 +0200 Subject: add kvm plugins --- files/plugins/kvm_cpu | 101 +++++++++++++++++++++++++++++++++++ files/plugins/kvm_io | 110 ++++++++++++++++++++++++++++++++++++++ files/plugins/kvm_mem | 107 +++++++++++++++++++++++++++++++++++++ files/plugins/kvm_net | 143 ++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 461 insertions(+) create mode 100644 files/plugins/kvm_cpu create mode 100644 files/plugins/kvm_io create mode 100644 files/plugins/kvm_mem create mode 100644 files/plugins/kvm_net (limited to 'files') diff --git a/files/plugins/kvm_cpu b/files/plugins/kvm_cpu new file mode 100644 index 0000000..f48d9f0 --- /dev/null +++ b/files/plugins/kvm_cpu @@ -0,0 +1,101 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +# vim: set fileencoding=utf-8 +# +# Munin plugin to show CPU used by vm +# +# Copyright Maxence Dunnewind, Rodolphe Quiédeville +# +# License : GPLv3 +# +# parsed environment variables: +# vmsuffix: part of vm name to be removed +# +#%# capabilities=autoconf +#%# family=contrib + +import re, os, sys +from subprocess import Popen, PIPE + +def config(vm_names): + ''' Print the plugin's config + @param vm_names : a list of "cleaned" vms' name + ''' + percent = len(filter(lambda x: x[0:3] == 'cpu' and x[3] != ' ', open('/proc/stat', 'r').readlines())) * 100 + + base_config = """graph_title KVM Virtual Machine CPU usage +graph_vlabel %% +graph_category KVM +graph_scale no +graph_period second +graph_info This graph shows the current CPU used by virtual machines +graph_args --base 1000 -r --lower-limit 0 --upper-limit %d""" % percent + print base_config + draw = "AREA" + for vm in vm_names: + print "%s_cpu.label %s" % (vm, vm) + print "%s_cpu.min 0" % vm + print "%s_cpu.type DERIVE" % vm + print "%s_cpu.draw %s" % (vm, draw) + print "%s_cpu.info percent of cpu time used by virtual machine" % vm + draw = "STACK" + + +def clean_vm_name(vm_name): + ''' Replace all special chars + @param vm_name : a vm's name + @return cleaned vm's name + ''' + + # suffix part defined in conf + suffix = os.getenv('vmsuffix') + if suffix: + vm_name = re.sub(suffix,'',vm_name) + + return re.sub(r"[^a-zA-Z0-9_]", "_", vm_name) + +def detect_kvm(): + ''' Check if kvm is installed + ''' + kvm = Popen("which kvm", shell=True, stdout=PIPE) + kvm.communicate() + return not bool(kvm.returncode) + +def find_vm_names(pids): + '''Find and clean vm names from pids + @return a dictionnary of {pids : cleaned vm name} + ''' + result = {} + for pid in pids: + cmdline = open("/proc/%s/cmdline" % pid, "r") + result[pid] = clean_vm_name(re.sub(r"^.*-name\x00([a-zA-Z0-9.-]*)\x00\-.*$",r"\1", cmdline.readline())) + return result + +def list_pids(): + ''' Find the pid of kvm processes + @return a list of pids from running kvm + ''' + pid = Popen("pidof qemu-kvm kvm", shell=True, stdout=PIPE) + return pid.communicate()[0].split() + +def fetch(vms): + ''' Fetch values for a list of pids + @param dictionnary {kvm_pid: cleaned vm name} + ''' + for ( pid, name ) in vms.iteritems(): + ( user, system ) = open("/proc/%s/stat" % pid, 'r').readline().split(' ')[13:15] + print '%s_cpu.value %d' % ( name, int(user) + int(system) ) + +if __name__ == "__main__": + if len(sys.argv) > 1: + if sys.argv[1] in ['autoconf', 'detect']: + if detect_kvm(): + print "yes" + else: + print "no" + elif sys.argv[1] == "config": + config(find_vm_names(list_pids()).values()) + else: + fetch(find_vm_names(list_pids())) + else: + fetch(find_vm_names(list_pids())) diff --git a/files/plugins/kvm_io b/files/plugins/kvm_io new file mode 100644 index 0000000..602b2ca --- /dev/null +++ b/files/plugins/kvm_io @@ -0,0 +1,110 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +# vim: set fileencoding=utf-8 +# +# Munin plugin to show io by vm +# +# Copyright Maxence Dunnewind, Rodolphe Quiédeville +# +# License : GPLv3 +# +# parsed environment variables: +# vmsuffix: part of vm name to be removed +# +#%# capabilities=autoconf +#%# family=contrib + +import re, os, sys +from subprocess import Popen, PIPE + +def config(vm_names): + ''' Print the plugin's config + @param vm_names : a list of "cleaned" vms' name + ''' + base_config = """graph_title KVM Virtual Machine IO usage +graph_vlabel Bytes read(-)/written(+) per second +graph_category KVM +graph_info This graph shows the block device I/O used of virtual machines +graph_args --base 1024 + """ + print base_config + + for vm in vm_names: + print "%s_read.label %s" % (vm, vm) + print "%s_read.type COUNTER" % vm + print "%s_read.min 0" % vm + print "%s_read.draw LINE1" % vm + print "%s_read.info I/O used by virtual machine %s" % (vm, vm) + print "%s_write.label %s" % (vm, vm) + print "%s_write.type COUNTER" % vm + print "%s_write.min 0" % vm + print "%s_write.draw LINE1" % vm + print "%s_write.negative %s_read" % (vm, vm) + print "%s_write.info I/O used by virtual machine %s" % (vm, vm) + +def clean_vm_name(vm_name): + ''' Replace all special chars + @param vm_name : a vm's name + @return cleaned vm's name + ''' + # suffix part defined in conf + suffix = os.getenv('vmsuffix') + if suffix: + vm_name = re.sub(suffix,'',vm_name) + + return re.sub(r"[^a-zA-Z0-9_]", "_", vm_name) + +def fetch(vms): + ''' Fetch values for a list of pids + @param dictionnary {kvm_pid: cleaned vm name} + ''' + res = {} + for pid in vms: + f = open("/proc/%s/io" % pid, "r") + for line in f.readlines(): + if "read_bytes" in line: + read = line.split()[1] + print "%s_read.value %s" % (vms[pid], read) + if "write_bytes" in line: + write = line.split()[1] + print "%s_write.value %s" % (vms[pid], write) + break + f.close() + +def detect_kvm(): + ''' Check if kvm is installed + ''' + kvm = Popen("which kvm", shell=True, stdout=PIPE) + kvm.communicate() + return not bool(kvm.returncode) + +def find_vm_names(pids): + '''Find and clean vm names from pids + @return a dictionnary of {pids : cleaned vm name} + ''' + result = {} + for pid in pids: + cmdline = open("/proc/%s/cmdline" % pid, "r") + result[pid] = clean_vm_name(re.sub(r"^.*-name\x00([a-zA-Z0-9.-]*)\x00\-.*$",r"\1", cmdline.readline())) + return result + +def list_pids(): + ''' Find the pid of kvm processes + @return a list of pids from running kvm + ''' + pid = Popen("pidof qemu-kvm kvm", shell=True, stdout=PIPE) + return pid.communicate()[0].split() + +if __name__ == "__main__": + if len(sys.argv) > 1: + if sys.argv[1] in ['autoconf', 'detect']: + if detect_kvm(): + print "yes" + else: + print "no" + elif sys.argv[1] == "config": + config(find_vm_names(list_pids()).values()) + else: + fetch(find_vm_names(list_pids())) + else: + fetch(find_vm_names(list_pids())) diff --git a/files/plugins/kvm_mem b/files/plugins/kvm_mem new file mode 100644 index 0000000..c64d8ce --- /dev/null +++ b/files/plugins/kvm_mem @@ -0,0 +1,107 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +# vim: set fileencoding=utf-8 +# +# Munin plugin to show amount of memory used by vm +# +# Copyright Maxence Dunnewind, Rodolphe Quiédeville, Adrien Pujol +# +# License : GPLv3 +# +# parsed environment variables: +# vmsuffix: part of vm name to be removed +# +#%# capabilities=autoconf +#%# family=contrib + +import re, os, sys +from subprocess import Popen, PIPE + +def config(vm_names): + ''' Print the plugin's config + @param vm_names : a list of "cleaned" vms' name + ''' + base_config = """graph_title KVM Virtual Machine Memory usage +graph_vlabel Bytes +graph_category KVM +graph_info This graph shows the current amount of memory used by virtual machines +graph_args --base 1024 + """ + print base_config + draw = "AREA" + for vm in vm_names: + print "%s_mem.label %s" % (vm, vm) + print "%s_mem.type GAUGE" % vm + if draw == 'AREA': + print "%s_mem.min 0" % vm + print "%s_mem.draw %s" % (vm, draw) + print "%s_mem.info memory used by virtual machine %s" % (vm, vm) + draw = "STACK" + + +def clean_vm_name(vm_name): + ''' Replace all special chars + @param vm_name : a vm's name + @return cleaned vm's name + ''' + # suffix part defined in conf + suffix = os.getenv('vmsuffix') + if suffix: + vm_name = re.sub(suffix,'',vm_name) + + return re.sub(r"[^a-zA-Z0-9_]", "_", vm_name) + +def fetch(vms): + ''' Fetch values for a list of pids + @param dictionnary {kvm_pid: cleaned vm name} + ''' + res = {} + for pid in vms: + try: + cmdline = open("/proc/%s/cmdline" % pid, "r") + amount = re.sub(r"^.*-m\x00(.*)\x00-smp.*$",r"\1", cmdline.readline()) + ammount = int(amount) * 1024 * 1024 + print "%s_mem.value %s" % (vms[pid], ammount) + except: + cmdline = open("/proc/%s/cmdline" % pid, "r") + amount = re.sub(r"^.*-m\x00(\d+).*$",r"\1", cmdline.readline()) + ammount = int(amount) * 1024 * 1024 + print "%s_mem.value %s" % (vms[pid], ammount) + +def detect_kvm(): + ''' Check if kvm is installed + ''' + kvm = Popen("which kvm", shell=True, stdout=PIPE) + kvm.communicate() + return not bool(kvm.returncode) + +def find_vm_names(pids): + '''Find and clean vm names from pids + @return a dictionnary of {pids : cleaned vm name} + ''' + result = {} + for pid in pids: + cmdline = open("/proc/%s/cmdline" % pid, "r") + result[pid] = clean_vm_name(re.sub(r"^.*-name\x00([a-zA-Z0-9.-]*)\x00\-.*$",r"\1", cmdline.readline())) + return result + +def list_pids(): + ''' Find the pid of kvm processes + @return a list of pids from running kvm + ''' + pid = Popen("pidof qemu-kvm kvm", shell=True, stdout=PIPE) + return pid.communicate()[0].split() + +if __name__ == "__main__": + if len(sys.argv) > 1: + if sys.argv[1] in ['autoconf', 'detect']: + if detect_kvm(): + print "yes" + else: + print "no" + elif sys.argv[1] == "config": + config(find_vm_names(list_pids()).values()) + else: + fetch(find_vm_names(list_pids())) + else: + fetch(find_vm_names(list_pids())) diff --git a/files/plugins/kvm_net b/files/plugins/kvm_net new file mode 100644 index 0000000..6da0d90 --- /dev/null +++ b/files/plugins/kvm_net @@ -0,0 +1,143 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +# vim: set fileencoding=utf-8 +# +# Munin plugin to show the network I/O per vm +# On redhat based systems +# +# Copyright Igor Borodikhin +# Copyright Peter Meier +# +# License : GPLv3 +# +# +# parsed environment variables: +# vmsuffix: part of vm name to be removed +# +#%# capabilities=autoconf +#%# family=contrib + +import re, os, sys +from subprocess import Popen, PIPE + +def config(vm_names): + ''' Print the plugin's config + @param vm_names : a list of "cleaned" vms' name + ''' + base_config = """graph_title KVM Network I/O +graph_vlabel Bytes rx(-)/tx(+) per second +graph_category KVM +graph_info This graph shows the network I/O of the virtual machines +graph_args --base 1024 + """ + print base_config + for vm in vm_names: + print "%s_in.label %s" % (vm, vm) + print "%s_in.type COUNTER" % vm + print "%s_in.min 0" % vm + print "%s_in.draw LINE2" % vm + print "%s_out.negative %s_in" % (vm, vm) + print "%s_out.label %s" % (vm, vm) + print "%s_out.type COUNTER" % vm + print "%s_out.min 0" % vm + print "%s_out.draw LINE2" % vm + +def clean_vm_name(vm_name): + ''' Replace all special chars + @param vm_name : a vm's name + @return cleaned vm's name + ''' + # suffix part defined in conf + suffix = os.getenv('vmsuffix') + if suffix: + vm_name = re.sub(suffix,'',vm_name) + + return re.sub(r"[^a-zA-Z0-9_]", "_", vm_name) + +def fetch(vms): + ''' Fetch values for a list of pids + @param dictionnary {kvm_pid: cleaned vm name} + ''' + res = {} + macs_to_inf = find_macs_to_inf() + interfaces = {} + for e in Popen('cat /proc/net/dev | awk \'{ print $1 ":" $9 }\'', shell=True, stdout=PIPE).communicate()[0].split('\n'): + s = e.split(':') + if len(s) == 3: + interfaces[s[0]] = (s[1],s[2]) + for pid in vms: + macs = get_vm_macs(pid) + for mac in macs: + inf = macs_to_inf[mac] + values = interfaces[inf] + if len(values) == 2: + print "%s_%s_in.value %s" % (vms[pid], inf, values[0]) + print "%s_%s_out.value %s" % (vms[pid], inf, values[1]) + +def detect_kvm(): + ''' Check if kvm is installed + ''' + kvm = Popen("which kvm", shell=True, stdout=PIPE) + kvm.communicate() + return not bool(kvm.returncode) + +def find_vm_names(pids): + '''Find and clean vm names from pids + @return a dictionnary of {pids : cleaned vm name} + ''' + result = {} + for pid in pids: + cmdline = open("/proc/%s/cmdline" % pid, "r") + result[pid] = clean_vm_name(re.sub(r"^.*-name\x00([a-zA-Z0-9.-]*)\x00\-.*$",r"\1", cmdline.readline())) + return result + +def get_vm_macs(pid): + '''Find macs for a pid + @return the mac addresses for a specified pid + ''' + cmdline = open("/proc/%s/cmdline" % pid, "r") + line = cmdline.readline() + # macs are fe:... on the host + macs = [ re.sub(r"^\d{2}",'fe',p.split('=')[1]) for p in line.split(",") if re.match(r"^mac(addr)?=",p) ] + return macs + +def list_pids(): + ''' Find the pid of kvm processes + @return a list of pids from running kvm + ''' + pid = Popen("pidof qemu-kvm kvm", shell=True, stdout=PIPE) + return pid.communicate()[0].split() + +def find_macs_to_inf(): + ''' Find interfaces for vms + @return a dictionary of macs to inf + ''' + result = {} + inf = "" + kvm = Popen("ip a | grep -E -A 1 '(tap|vnet)' | awk '{print $2}' | grep -v '^$'", shell=True, stdout=PIPE) + res = kvm.communicate()[0].split('\n') + for line in res: + if len(line) > 0: + if re.match(r"^tap.*", line): + inf = re.sub(r"(tap[^:]+):", r"\1", line) + elif re.match(r"^vnet.*", line): + inf = re.sub(r"(vnet[^:]+):", r"\1", line) + else: + result[line] = inf + + return result + +if __name__ == "__main__": + if len(sys.argv) > 1: + if sys.argv[1] in ['autoconf', 'detect']: + if detect_kvm(): + print "yes" + else: + print "no" + elif sys.argv[1] == "config": + config(find_vm_names(list_pids()).values()) + else: + fetch(find_vm_names(list_pids())) + else: + fetch(find_vm_names(list_pids())) + -- cgit v1.2.3 From f85fe9d9b94a1f30dda6637722542884194edd39 Mon Sep 17 00:00:00 2001 From: mh Date: Sat, 15 Sep 2012 14:09:56 +0200 Subject: fix config and output --- files/plugins/kvm_net | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) (limited to 'files') diff --git a/files/plugins/kvm_net b/files/plugins/kvm_net index 6da0d90..c7aae2b 100644 --- a/files/plugins/kvm_net +++ b/files/plugins/kvm_net @@ -20,7 +20,7 @@ import re, os, sys from subprocess import Popen, PIPE -def config(vm_names): +def config(vms): ''' Print the plugin's config @param vm_names : a list of "cleaned" vms' name ''' @@ -31,16 +31,20 @@ graph_info This graph shows the network I/O of the virtual machines graph_args --base 1024 """ print base_config - for vm in vm_names: - print "%s_in.label %s" % (vm, vm) - print "%s_in.type COUNTER" % vm - print "%s_in.min 0" % vm - print "%s_in.draw LINE2" % vm - print "%s_out.negative %s_in" % (vm, vm) - print "%s_out.label %s" % (vm, vm) - print "%s_out.type COUNTER" % vm - print "%s_out.min 0" % vm - print "%s_out.draw LINE2" % vm + for pid in vms: + macs = get_vm_macs(pid) + i = 0 + for mac in macs: + print "%s_eth%s_in.label %s" % (vms[pid],i, vms[pid]) + print "%s_eth%s_in.type COUNTER" % (vms[pid], i) + print "%s_eth%s_in.min 0" % (vms[pid],i) + print "%s_eth%s_in.draw LINE2" % (vms[pid],i) + print "%s_eth%s_out.negative %s_in" % (vms[pid], i, vms[pid]) + print "%s_eth%s_out.label %s" % (vms[pid], i, vms[pid]) + print "%s_eth%s_out.type COUNTER" % (vms[pid], i) + print "%s_eth%s_out.min 0" % (vms[pid], i) + print "%s_eth%s_out.draw LINE2" % (vms[pid], i) + i += 1 def clean_vm_name(vm_name): ''' Replace all special chars @@ -67,12 +71,14 @@ def fetch(vms): interfaces[s[0]] = (s[1],s[2]) for pid in vms: macs = get_vm_macs(pid) + i = 0 for mac in macs: inf = macs_to_inf[mac] values = interfaces[inf] if len(values) == 2: - print "%s_%s_in.value %s" % (vms[pid], inf, values[0]) - print "%s_%s_out.value %s" % (vms[pid], inf, values[1]) + print "%s_eth%s_in.value %s" % (vms[pid], i, values[0]) + print "%s_eth%s_out.value %s" % (vms[pid], i, values[1]) + i += 1 def detect_kvm(): ''' Check if kvm is installed @@ -135,7 +141,7 @@ if __name__ == "__main__": else: print "no" elif sys.argv[1] == "config": - config(find_vm_names(list_pids()).values()) + config(find_vm_names(list_pids())) else: fetch(find_vm_names(list_pids())) else: -- cgit v1.2.3 From d304394caaf15c0bc1f23c5e57fabcdffd86b90d Mon Sep 17 00:00:00 2001 From: mh Date: Sat, 15 Sep 2012 15:12:45 +0200 Subject: fix plugin --- files/plugins/kvm_net | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'files') diff --git a/files/plugins/kvm_net b/files/plugins/kvm_net index c7aae2b..bcad719 100644 --- a/files/plugins/kvm_net +++ b/files/plugins/kvm_net @@ -39,7 +39,7 @@ graph_args --base 1024 print "%s_eth%s_in.type COUNTER" % (vms[pid], i) print "%s_eth%s_in.min 0" % (vms[pid],i) print "%s_eth%s_in.draw LINE2" % (vms[pid],i) - print "%s_eth%s_out.negative %s_in" % (vms[pid], i, vms[pid]) + print "%s_eth%s_out.negative %s_eth%s_in" % (vms[pid], i, vms[pid], i) print "%s_eth%s_out.label %s" % (vms[pid], i, vms[pid]) print "%s_eth%s_out.type COUNTER" % (vms[pid], i) print "%s_eth%s_out.min 0" % (vms[pid], i) -- cgit v1.2.3 From a29438a07e9af6ccdcadd465492e527f6ba4a8ab Mon Sep 17 00:00:00 2001 From: mh Date: Sat, 15 Sep 2012 16:18:54 +0200 Subject: cleanup plugins --- files/plugins/kvm_io | 3 +-- files/plugins/kvm_mem | 3 +-- files/plugins/kvm_net | 7 +++---- 3 files changed, 5 insertions(+), 8 deletions(-) (limited to 'files') diff --git a/files/plugins/kvm_io b/files/plugins/kvm_io index 602b2ca..43941f5 100644 --- a/files/plugins/kvm_io +++ b/files/plugins/kvm_io @@ -25,8 +25,7 @@ def config(vm_names): graph_vlabel Bytes read(-)/written(+) per second graph_category KVM graph_info This graph shows the block device I/O used of virtual machines -graph_args --base 1024 - """ +graph_args --base 1024""" print base_config for vm in vm_names: diff --git a/files/plugins/kvm_mem b/files/plugins/kvm_mem index c64d8ce..14fb793 100644 --- a/files/plugins/kvm_mem +++ b/files/plugins/kvm_mem @@ -25,8 +25,7 @@ def config(vm_names): graph_vlabel Bytes graph_category KVM graph_info This graph shows the current amount of memory used by virtual machines -graph_args --base 1024 - """ +graph_args --base 1024""" print base_config draw = "AREA" for vm in vm_names: diff --git a/files/plugins/kvm_net b/files/plugins/kvm_net index bcad719..c7b5aca 100644 --- a/files/plugins/kvm_net +++ b/files/plugins/kvm_net @@ -28,19 +28,18 @@ def config(vms): graph_vlabel Bytes rx(-)/tx(+) per second graph_category KVM graph_info This graph shows the network I/O of the virtual machines -graph_args --base 1024 - """ +graph_args --base 1024""" print base_config for pid in vms: macs = get_vm_macs(pid) i = 0 for mac in macs: - print "%s_eth%s_in.label %s" % (vms[pid],i, vms[pid]) + print "%s_eth%s_in.label %s_eth%s" % (vms[pid],i, vms[pid], i) print "%s_eth%s_in.type COUNTER" % (vms[pid], i) print "%s_eth%s_in.min 0" % (vms[pid],i) print "%s_eth%s_in.draw LINE2" % (vms[pid],i) print "%s_eth%s_out.negative %s_eth%s_in" % (vms[pid], i, vms[pid], i) - print "%s_eth%s_out.label %s" % (vms[pid], i, vms[pid]) + print "%s_eth%s_out.label %s_eth%s" % (vms[pid], i, vms[pid], i) print "%s_eth%s_out.type COUNTER" % (vms[pid], i) print "%s_eth%s_out.min 0" % (vms[pid], i) print "%s_eth%s_out.draw LINE2" % (vms[pid], i) -- cgit v1.2.3 From a33995ad702c6203314d1b9b68000ae931a35dc4 Mon Sep 17 00:00:00 2001 From: mh Date: Wed, 17 Oct 2012 21:38:41 +0200 Subject: new upstream config --- files/config/host/munin.conf.header.CentOS | 88 +++++++++++++++++++++--------- 1 file changed, 62 insertions(+), 26 deletions(-) (limited to 'files') diff --git a/files/config/host/munin.conf.header.CentOS b/files/config/host/munin.conf.header.CentOS index 413cd84..f212ce0 100644 --- a/files/config/host/munin.conf.header.CentOS +++ b/files/config/host/munin.conf.header.CentOS @@ -5,26 +5,40 @@ # must be writable by the user running munin-cron. They are all # defaulted to the values you see here. # -# dbdir /var/lib/munin -# htmldir /var/www/html/munin -# logdir /var/log/munin -# rundir /var/run/munin +#dbdir /var/lib/munin +#htmldir /var/www/html/munin +htmldir /var/www/html/munin +#logdir /var/log/munin +#rundir /var/run/munin + +# Where to look for the HTML templates # -# tmpldir /etc/munin/templates +#tmpldir /etc/munin/templates -# (Exactly one) directory to include all files from. +# Where to look for the static www files +# +#staticdir /etc/munin/static + +# temporary cgi files are here. note that it has to be writable by +# the cgi user (usually nobody or httpd). # -# includedir /etc/munin/munin-conf.d +# cgitmpdir /var/lib/munin/cgi-tmp -# Make graphs show values per minute instead of per second -#graph_period minute +# (Exactly one) directory to include all files from. +includedir /etc/munin/conf.d + +# You can choose the time reference for "DERIVE" like graphs, and show +# "per minute", "per hour" values instead of the default "per second" +# +#graph_period second -# Graphics files are normaly generated by munin-graph, no matter if -# the graphs are used or not. You can change this to -# on-demand-graphing by following the instructions in -# http://munin.projects.linpro.no/wiki/CgiHowto +# Graphics files are generated either via cron or by a CGI process. +# See http://munin-monitoring.org/wiki/CgiHowto2 for more +# documentation. +# Since 2.0, munin-graph has been rewritten to use the cgi code. +# It is single threaded *by design* now. # -graph_strategy cgi +#graph_strategy cgi # munin-cgi-graph is invoked by the web server up to very many times at the # same time. This is not optimal since it results in high CPU and memory @@ -36,15 +50,41 @@ graph_strategy cgi # If the automatic CGI url is wrong for your system override it here: # -#cgiurl_graph /cgi-bin/munin-cgi-graph +#cgiurl_graph /munin-cgi/munin-cgi-graph + +# max_size_x and max_size_y are the max size of images in pixel. +# Default is 4000. Do not make it too large otherwise RRD might use all +# RAM to generate the images. +# +#max_size_x 4000 +#max_size_y 4000 -# munin-graph runs in parallel, the number of concurrent processes is -# 6. If you want munin-graph to not be parallel set to 0. If set too -# high it will slow down munin-graph. Some experiments are needed to -# determine how many are optimal on your system. On a multi-core -# system with good SCSI disks the number can probably be quite high. +# HTML files are normally generated by munin-html, no matter if the +# files are used or not. You can change this to on-demand generation +# by following the instructions in http://munin-monitoring.org/wiki/CgiHowto2 +# +# Notes: +# - moving to CGI for HTML means you cannot have graph generated by cron. +# - cgi html has some bugs, mostly you still have to launch munin-html by hand +# +html_strategy cron + +# munin-update runs in parallel. +# +# The default max number of processes is 16, and is probably ok for you. +# +# If set too high, it might hit some process/ram/filedesc limits. +# If set too low, munin-update might take more than 5 min. +# +# If you want munin-update to not be parallel set it to 0. # -#max_graph_jobs 6 +#max_processes 16 + +# RRD updates are per default, performed directly on the rrd files. +# To reduce IO and enable the use of the rrdcached, uncomment it and set it to +# the location of the socket that rrdcached uses. +# +#rrdcached_socket /var/run/rrdcached.sock # Drop somejuser@fnord.comm and anotheruser@blibb.comm an email everytime # something changes (OK -> WARNING, CRITICAL -> OK, etc) @@ -53,11 +93,7 @@ graph_strategy cgi # # For those with Nagios, the following might come in handy. In addition, # the services must be defined in the Nagios server as well. -#contact.nagios.command /usr/sbin/send_nsca -H nagios.host.com -c /etc/send_nsca.cfg - -contacts me -contact.me.command mail -s "Munin notification ${var:group} :: ${var:host} :: ${var:graph_title}" root -contact.me.always_send warning critical +#contact.nagios.command /usr/bin/send_nsca nagios.host.comm -c /etc/nsca.conf # a simple host tree #[localhost] -- cgit v1.2.3 From d43c6ae0fcf45411524d093d21f5cb5c01f7c830 Mon Sep 17 00:00:00 2001 From: mh Date: Tue, 27 Nov 2012 15:43:21 +0100 Subject: there are now official selinux plugins --- files/plugins/selinux_avcstats | 111 ----------------------------------------- files/plugins/selinuxenforced | 30 ----------- 2 files changed, 141 deletions(-) delete mode 100755 files/plugins/selinux_avcstats delete mode 100755 files/plugins/selinuxenforced (limited to 'files') diff --git a/files/plugins/selinux_avcstats b/files/plugins/selinux_avcstats deleted file mode 100755 index b7d2dbb..0000000 --- a/files/plugins/selinux_avcstats +++ /dev/null @@ -1,111 +0,0 @@ -#!/bin/sh -# -# Plugin to monitor SELinux's Access Vector Cache (AVC). -# -# config (required) -# autoconf (optional - used by munin-config) -# -# Lars Strand, 2007 -# -# -# Magic markers (used by munin-config and some installation scripts (i.e. -# optional)): -#%# family=auto -#%# capabilities=autoconf - - -AVCSTATS="/selinux/avc/cache_stats" - -if [ "$1" = "autoconf" ]; then - if [ -r $AVCSTATS ]; then - echo yes - exit 0 - else - echo no - exit 1 - fi -fi - -if [ "$1" = "config" ]; then - - echo "graph_title SELinux's Access Vector Cache" - echo 'graph_args -l 0 --base 1000' - echo 'graph_vlabel AVC operations' - echo 'graph_category selinux' - - echo 'lookups.label lookups' - echo 'lookups.type DERIVE' - echo 'lookups.min 0' - echo 'lookups.max 1000000000' - echo 'lookups.draw AREA' - echo 'lookups.colour ff0000' # Red - echo 'lookups.info Number of access vector lookups. This number is a good indicator of the load beeing placed on the AVC.' - - echo 'hits.label hits' - echo 'hits.type DERIVE' - echo 'hits.min 0' - echo 'hits.max 1000000000' - echo 'hits.draw STACK' - echo 'hits.colour 0022ff' # Blue - echo 'hits.info Number of access vector hits.' - - echo 'misses.label misses' - echo 'misses.type DERIVE' - echo 'misses.min 0' - echo 'misses.max 1000000000' - echo 'misses.draw STACK' - echo 'misses.colour 990000' # Darker red - echo 'misses.info Number of cache misses.' - - echo 'allocations.label allocations' - echo 'allocations.type DERIVE' - echo 'allocations.min 0' - echo 'allocations.max 100000000' - echo 'allocations.draw STACK' - echo 'allocations.colour ffa500' # Orange - echo 'allocations.info Number of AVC entries allocated.' - - echo 'reclaims.label reclaims' - echo 'reclaims.type DERIVE' - echo 'reclaims.min 0' - echo 'reclaims.max 1000000000' - echo 'reclaims.draw STACK' - echo 'reclaims.colour 00aaaa' # Darker turquoise - echo 'reclaims.info Number of current total reclaimed AVC entries. If this keeps changing, you may need to increase the cache size (/selinux/avc/cache_threshold).' - - echo 'frees.label frees' - echo 'frees.type DERIVE' - echo 'frees.min 0' - echo 'frees.max 1000000000' - echo 'frees.draw STACK' - echo 'frees.colour 00ff7f' # Spring green - echo 'frees.info Number of free AVC entries.' - - exit 0 -fi - -if [ -r $AVCSTATS ]; then - awk ' NR > 1 { - lookups += $1; - hits += $2; - misses += $3; - allocations += $4; - reclaims += $5; - frees += $6; - } END { - print "lookups.value " lookups; - print "hits.value " hits; - print "misses.value " misses; - print "allocations.value " allocations; - print "reclaims.value " reclaims; - print "frees.value " frees; - } ' < $AVCSTATS -else - echo "lookups.value U" - echo "hits.value U" - echo "misses.value U" - echo "allocations.value U" - echo "reclaims.value U" - echo "frees.value U" -fi - diff --git a/files/plugins/selinuxenforced b/files/plugins/selinuxenforced deleted file mode 100755 index e157e3d..0000000 --- a/files/plugins/selinuxenforced +++ /dev/null @@ -1,30 +0,0 @@ -#!/bin/sh -# -*- sh -*- -# -# Plugin to monitor the status of selinux -# -# Contributed by admin(at)immerda.ch - -if [ "$1" = "autoconf" ]; then - echo yes - exit 0 -fi - -if [ "$1" = "config" ]; then - echo 'graph_title enforced amount' - echo 'graph_args --upper-limit 1 -l 0 ' - echo 'graph_vlabel Is the system selinux enforced?' - echo 'graph_scale no\n'; - echo 'graph_category selinux' - echo 'enforced.label IsEnforced' - #echo 'enforced.draw AREA' - echo 'enforced.draw LINE2' - - exit 0 -fi - -if [ -r /selinux/enforce ]; then - echo -n "enforced.value " && cat /selinux/enforce -else - echo "enforced.value 0" -fi -- cgit v1.2.3 From 630f4d609e1e58a74abb04963ce68c9fc4bab4a1 Mon Sep 17 00:00:00 2001 From: mh Date: Thu, 6 Dec 2012 22:11:10 +0100 Subject: replace xen-cpu plugin with a better plugin --- files/plugins/xen-cpu | 121 -------------------------------- files/plugins/xen_cpu | 189 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 189 insertions(+), 121 deletions(-) delete mode 100755 files/plugins/xen-cpu create mode 100644 files/plugins/xen_cpu (limited to 'files') diff --git a/files/plugins/xen-cpu b/files/plugins/xen-cpu deleted file mode 100755 index b456a14..0000000 --- a/files/plugins/xen-cpu +++ /dev/null @@ -1,121 +0,0 @@ -#!/usr/bin/perl -wT -# -# Script to minitor the cpu usage of Xen domains -# -# Author: Adam Crews shroom 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) -# -#%# 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'; - -# we cache xm list for 5 min for perfomance reasons -system('((find /var/lib/munin/plugin-state/xm_list.state -mmin -5 2>&1 | grep -qE \'^\/var\/lib\/munin\/plugin-state\/xm_list\.state$\') && [ `cat /var/lib/munin/plugin-state/xm_list.state | wc -l` -gt 1 ]) || /usr/sbin/xm list | grep -v "^Name .* Console$" > /var/lib/munin/plugin-state/xm_list.state'); -system('((find /var/lib/munin/plugin-state/xm_top.state -mmin -5 2>&1 | grep -qE \'^\/var\/lib\/munin\/plugin-state\/xm_top\.state$\') && [ `cat /var/lib/munin/plugin-state/xm_top.state | wc -l` -gt 1 ]) || /usr/sbin/xentop -b -i1 > /var/lib/munin/plugin-state/xm_top.state'); - -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 = `cat /var/lib/munin/plugin-state/xm_list.state`; - # the header line is not in the cached file - #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 @stats = `cat /var/lib/munin/plugin-state/xm_top.state`; - -# 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); - - # 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"; -} - diff --git a/files/plugins/xen_cpu b/files/plugins/xen_cpu new file mode 100644 index 0000000..382c8b5 --- /dev/null +++ b/files/plugins/xen_cpu @@ -0,0 +1,189 @@ +#!/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/env 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 = ; + + if ( $debug ) + { + print "Oldtime: $oldtime\n"; + } + + while () + { + # 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; + -- cgit v1.2.3 From aeeee144bf7e4740e9a8826e3d2086a4320c6ac8 Mon Sep 17 00:00:00 2001 From: mh Date: Thu, 6 Dec 2012 22:58:02 +0100 Subject: make this plugin caching more stable --- files/plugins/xen_traffic_all | 75 +++++++++++++++++++++++++------------------ 1 file changed, 43 insertions(+), 32 deletions(-) (limited to 'files') diff --git a/files/plugins/xen_traffic_all b/files/plugins/xen_traffic_all index c5bbfbb..b6f668d 100644 --- a/files/plugins/xen_traffic_all +++ b/files/plugins/xen_traffic_all @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # Author: mario manno # Description: measure traffic for all xen hosts # @@ -32,6 +32,21 @@ if [ "$1" = "autoconf" ]; then exit 0 fi +# we update network devices only twice an hour +function net_state { + dom=$1 + (find /var/lib/munin/plugin-state/xm_net_$dom.state -mmin -30 > /dev/null 2>&1) && \ + [ `cat /var/lib/munin/plugin-state/xm_net_$dom.state | wc -l` -gt 0 ] + if [ $? -gt 0 ] || [ ! -f /var/lib/munin/plugin-state/xm_net_$dom.state ]; then + content=$(/usr/sbin/xm network-list $dom) + if [ $? -eq 0 ]; then + echo "${content}" | egrep "^[0-9]+" | sed 's@^.*vif/\([0-9]*\)/\([0-9]*\).*$@vif\1.\2@' > /var/lib/munin/plugin-state/xm_net_$dom.state + else + [ -f /var/lib/munin/plugin-state/xm_net_$dom.state ] && rm /var/lib/munin/plugin-state/xm_net_$dom.state + fi + fi +} + if [ "$1" = "config" ]; then echo 'graph_title Xen Traffic' echo 'graph_vlabel bits received (-) / sent (+) per ${graph_period}' @@ -39,43 +54,38 @@ if [ "$1" = "config" ]; then echo 'graph_category xen' DOMAINS=$(cat /var/lib/munin/plugin-state/xm_list.state | awk '{print $1}' | egrep -v "^(Name|Domain-0)") for dom in $DOMAINS; do - # we update network devices only twice an hour - ((find /var/lib/munin/plugin-state/xm_net_$dom.state -mmin -30 > /dev/null 2>&1) && \ - [ `cat /var/lib/munin/plugin-state/xm_net_$dom.state | wc -l` -gt 0 ]) || \ - (/usr/sbin/xm network-list $dom |\ - egrep "^[0-9]+" | sed 's@^.*vif/\([0-9]*\)/\([0-9]*\).*$@vif\1.\2@' > /var/lib/munin/plugin-state/xm_net_$dom.state) - devs=$(cat /var/lib/munin/plugin-state/xm_net_$dom.state) - real_name=$( echo $dom | sed -e's/-/_/g' ) - name=$real_name - for dev in $devs; do - if [ ${#devs} -gt 1 ]; then - name=$real_name"_"`echo $dev | sed 's/\./\_/'` - fi + net_state $dom + if [ -f /var/lib/munin/plugin-state/xm_net_$dom.state ]; then + devs=$(cat /var/lib/munin/plugin-state/xm_net_$dom.state) + real_name=$( echo $dom | sed -e's/-/_/g' ) + name=$real_name + for dev in $devs; do + if [ ${#devs} -gt 1 ]; then + name=$real_name"_"`echo $dev | sed 's/\./\_/'` + fi - 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 + 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 + fi done exit 0 fi DOMAINS=$(cat /var/lib/munin/plugin-state/xm_list.state | awk '{print $1}' | egrep -v "^(Name|Domain-0)") for dom in $DOMAINS; do - # we update network devices only twice an hour - ((find /var/lib/munin/plugin-state/xm_net_$dom.state -mmin -30 > /dev/null 2>&1) && \ - [ `cat /var/lib/munin/plugin-state/xm_net_$dom.state | wc -l` -gt 0 ]) || \ - (/usr/sbin/xm network-list $dom |\ - egrep "^[0-9]+" | sed 's@^.*vif/\([0-9]*\)/\([0-9]*\).*$@vif\1.\2@' > /var/lib/munin/plugin-state/xm_net_$dom.state) - devs=$(cat /var/lib/munin/plugin-state/xm_net_$dom.state) - real_name=$( echo $dom | sed -e's/-/_/g' ) - name=$real_name - for dev in $devs; do + net_state $dom + if [ -f /var/lib/munin/plugin-state/xm_net_$dom.state ]; then + devs=$(cat /var/lib/munin/plugin-state/xm_net_$dom.state) + real_name=$( echo $dom | sed -e's/-/_/g' ) + name=$real_name + for dev in $devs; do if [ ${#devs} -gt 1 ]; then name=$real_name"_"`echo $dev | sed 's/\./\_/'` fi @@ -86,6 +96,7 @@ for dom in $DOMAINS; do print name"Down.value " $1 "\n"name"Up.value " $9 \ }' \ /proc/net/dev - done + done + fi done -- cgit v1.2.3 From 61de53c6b99c18e309351c5e5cae5027ff2f4905 Mon Sep 17 00:00:00 2001 From: mh Date: Fri, 7 Dec 2012 11:17:54 +0100 Subject: fix plugin to work on debian and centos --- files/plugins/xen_vbd | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'files') diff --git a/files/plugins/xen_vbd b/files/plugins/xen_vbd index 4eca5a6..f3362c7 100755 --- a/files/plugins/xen_vbd +++ b/files/plugins/xen_vbd @@ -18,7 +18,7 @@ $XMTOP = '/usr/sbin/xentop'; # we cache xm list for 5 min for perfomance reasons system('((find /var/lib/munin/plugin-state/xm_list.state -mmin -5 2>&1 | grep -qE \'^\/var\/lib\/munin\/plugin-state\/xm_list\.state$\') && [ `cat /var/lib/munin/plugin-state/xm_list.state | wc -l` -gt 1 ]) || /usr/sbin/xm list | grep -v "^Name .* Console$" > /var/lib/munin/plugin-state/xm_list.state'); -system('((find /var/lib/munin/plugin-state/xm_top.state -mmin -5 2>&1 | grep -qE \'^\/var\/lib\/munin\/plugin-state\/xm_top\.state$\') && [ `cat /var/lib/munin/plugin-state/xm_top.state | wc -l` -gt 1 ]) || /usr/sbin/xentop -b -i1 > /var/lib/munin/plugin-state/xm_top.state'); +system('((find /var/lib/munin/plugin-state/xm_top.state -mmin -5 2>&1 | grep -qE \'^\/var\/lib\/munin\/plugin-state\/xm_top\.state$\') && [ `cat /var/lib/munin/plugin-state/xm_top.state | wc -l` -gt 1 ]) || /usr/sbin/xentop -b -i1 | grep -E "^ " > /var/lib/munin/plugin-state/xm_top.state'); # ah, parameters coming in if ( defined($ARGV[0])) @@ -88,10 +88,7 @@ if ( defined($ARGV[0])) # No args, get rolling my @stats = `cat /var/lib/munin/plugin-state/xm_top.state`; -# remove the first 4 items that are junk that we don't need. -shift(@stats); -shift(@stats); -shift(@stats); +# remove the first line shift(@stats); my %vals; undef(%vals); -- cgit v1.2.3 From 7bac1218e57c3092d52e4eb0734451e45cb78c94 Mon Sep 17 00:00:00 2001 From: mh Date: Fri, 7 Dec 2012 15:14:00 +0100 Subject: correct filtering --- files/plugins/xen | 2 +- files/plugins/xen_mem | 2 +- files/plugins/xen_traffic_all | 2 +- files/plugins/xen_vbd | 2 +- files/plugins/xen_vm | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) (limited to 'files') diff --git a/files/plugins/xen b/files/plugins/xen index a9f1a1e..378e040 100755 --- a/files/plugins/xen +++ b/files/plugins/xen @@ -20,7 +20,7 @@ fi # we cache xm list for 5 min for perfomance reasons ((find /var/lib/munin/plugin-state/xm_list.state -mmin -5 2>&1 | grep -qE '^\/var\/lib\/munin\/plugin-state\/xm_list\.state$') && \ [ `cat /var/lib/munin/plugin-state/xm_list.state | wc -l` -gt 1 ]) || \ - /usr/sbin/xm list | grep -v "^Name .* Console$" > /var/lib/munin/plugin-state/xm_list.state + /usr/sbin/xm list | grep -v "^Name .* ID" > /var/lib/munin/plugin-state/xm_list.state if [ "$1" = "config" ]; then diff --git a/files/plugins/xen_mem b/files/plugins/xen_mem index 16d91cf..edfc926 100644 --- a/files/plugins/xen_mem +++ b/files/plugins/xen_mem @@ -46,7 +46,7 @@ # we cache xm list for 5 min for perfomance reasons ((find /var/lib/munin/plugin-state/xm_list.state -mmin -5 2>&1 | grep -qE '^\/var\/lib\/munin\/plugin-state\/xm_list\.state$') && \ [ `cat /var/lib/munin/plugin-state/xm_list.state | wc -l` -gt 1 ]) || \ - /usr/sbin/xm list | grep -v "^Name .* Console$" > /var/lib/munin/plugin-state/xm_list.state + /usr/sbin/xm list | grep -v "^Name .* ID" > /var/lib/munin/plugin-state/xm_list.state if [ "$1" = "autoconf" ]; then echo yes diff --git a/files/plugins/xen_traffic_all b/files/plugins/xen_traffic_all index b6f668d..492effc 100644 --- a/files/plugins/xen_traffic_all +++ b/files/plugins/xen_traffic_all @@ -14,7 +14,7 @@ # we cache xm list for 5 min for perfomance reasons ((find /var/lib/munin/plugin-state/xm_list.state -mmin -5 2>&1 | grep -qE '^\/var\/lib\/munin\/plugin-state\/xm_list\.state$') && \ [ `cat /var/lib/munin/plugin-state/xm_list.state | wc -l` -gt 1 ]) || \ - /usr/sbin/xm list | grep -v "^Name .* Console$" > /var/lib/munin/plugin-state/xm_list.state + /usr/sbin/xm list | grep -v "^Name .* ID" > /var/lib/munin/plugin-state/xm_list.state if [ "$1" = "autoconf" ]; then if which xm > /dev/null ; then diff --git a/files/plugins/xen_vbd b/files/plugins/xen_vbd index f3362c7..ccea940 100755 --- a/files/plugins/xen_vbd +++ b/files/plugins/xen_vbd @@ -17,7 +17,7 @@ $XM = '/usr/sbin/xm'; $XMTOP = '/usr/sbin/xentop'; # we cache xm list for 5 min for perfomance reasons -system('((find /var/lib/munin/plugin-state/xm_list.state -mmin -5 2>&1 | grep -qE \'^\/var\/lib\/munin\/plugin-state\/xm_list\.state$\') && [ `cat /var/lib/munin/plugin-state/xm_list.state | wc -l` -gt 1 ]) || /usr/sbin/xm list | grep -v "^Name .* Console$" > /var/lib/munin/plugin-state/xm_list.state'); +system('((find /var/lib/munin/plugin-state/xm_list.state -mmin -5 2>&1 | grep -qE \'^\/var\/lib\/munin\/plugin-state\/xm_list\.state$\') && [ `cat /var/lib/munin/plugin-state/xm_list.state | wc -l` -gt 1 ]) || /usr/sbin/xm list | grep -v "^Name .* ID" > /var/lib/munin/plugin-state/xm_list.state'); system('((find /var/lib/munin/plugin-state/xm_top.state -mmin -5 2>&1 | grep -qE \'^\/var\/lib\/munin\/plugin-state\/xm_top\.state$\') && [ `cat /var/lib/munin/plugin-state/xm_top.state | wc -l` -gt 1 ]) || /usr/sbin/xentop -b -i1 | grep -E "^ " > /var/lib/munin/plugin-state/xm_top.state'); # ah, parameters coming in diff --git a/files/plugins/xen_vm b/files/plugins/xen_vm index a69b5fe..18ee9a8 100644 --- a/files/plugins/xen_vm +++ b/files/plugins/xen_vm @@ -48,7 +48,7 @@ XM="/usr/sbin/xm" # we cache xm list for 5 min for perfomance reasons ((find /var/lib/munin/plugin-state/xm_list.state -mmin -5 2>&1 | grep -qE '^\/var\/lib\/munin\/plugin-state\/xm_list\.state$') && \ [ `cat /var/lib/munin/plugin-state/xm_list.state | wc -l` -gt 1 ]) || \ - /usr/sbin/xm list | grep -v "^Name .* Console$" > /var/lib/munin/plugin-state/xm_list.state + /usr/sbin/xm list | grep -v "^Name .* ID" > /var/lib/munin/plugin-state/xm_list.state if [ "$1" = "autoconf" ]; then echo yes -- cgit v1.2.3 From 8cb10f7bcd7bb3084e20d5a26099d65a83fb0f56 Mon Sep 17 00:00:00 2001 From: mh Date: Fri, 7 Dec 2012 16:00:18 +0100 Subject: fix a few other issues --- files/plugins/xen_mem | 4 ++-- files/plugins/xen_vbd | 1 - files/plugins/xen_vm | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) (limited to 'files') diff --git a/files/plugins/xen_mem b/files/plugins/xen_mem index edfc926..a260fbd 100644 --- a/files/plugins/xen_mem +++ b/files/plugins/xen_mem @@ -63,7 +63,7 @@ if [ "$1" = "config" ]; then echo 'graph_info This graph shows affected memory for each domain.' echo 'Domain_0.label Domain-0' echo 'Domain_0.draw AREA' -cat /var/lib/munin/plugin-state/xm_list.state | grep -v 'Mem' | grep -v 'Domain-0' | while read i; do +cat /var/lib/munin/plugin-state/xm_list.state | grep -v 'Domain-0' | while read i; do name=`echo $i | awk '{ print $1 }' | sed 's/[\/.-]/_/g'` echo -n "$name.label " echo $i | awk '{ print $1 }' @@ -73,7 +73,7 @@ done exit 0 fi -cat /var/lib/munin/plugin-state/xm_list.state | grep -v 'Mem' | while read i; do +cat /var/lib/munin/plugin-state/xm_list.state | while read i; do name=`echo $i | awk '{ print $1 }' | sed 's/[\/.-]/_/g'` echo -n "$name.value " echo $i | awk '{ print $3 * 1024 * 1024 }' diff --git a/files/plugins/xen_vbd b/files/plugins/xen_vbd index ccea940..a684839 100755 --- a/files/plugins/xen_vbd +++ b/files/plugins/xen_vbd @@ -51,7 +51,6 @@ if ( defined($ARGV[0])) ); @domains = `cat /var/lib/munin/plugin-state/xm_list.state`; - shift(@domains); # we don't need the header line foreach $domain ( @domains ) { diff --git a/files/plugins/xen_vm b/files/plugins/xen_vm index 18ee9a8..725e800 100644 --- a/files/plugins/xen_vm +++ b/files/plugins/xen_vm @@ -69,4 +69,4 @@ fi domains=`cat /var/lib/munin/plugin-state/xm_list.state | wc -l` echo -n "domains.value " -echo $(($domains-2)) +echo $(($domains-1)) -- cgit v1.2.3 From f34990e5a63bf3aeaaeafb7be2ed842c524a9926 Mon Sep 17 00:00:00 2001 From: mh Date: Sat, 15 Dec 2012 20:29:41 +0100 Subject: fix a few remaining things in xen plugins --- files/plugins/xen_traffic_all | 4 +--- files/plugins/xen_vbd | 4 ++-- 2 files changed, 3 insertions(+), 5 deletions(-) (limited to 'files') diff --git a/files/plugins/xen_traffic_all b/files/plugins/xen_traffic_all index 492effc..72f3b27 100644 --- a/files/plugins/xen_traffic_all +++ b/files/plugins/xen_traffic_all @@ -35,9 +35,7 @@ fi # we update network devices only twice an hour function net_state { dom=$1 - (find /var/lib/munin/plugin-state/xm_net_$dom.state -mmin -30 > /dev/null 2>&1) && \ - [ `cat /var/lib/munin/plugin-state/xm_net_$dom.state | wc -l` -gt 0 ] - if [ $? -gt 0 ] || [ ! -f /var/lib/munin/plugin-state/xm_net_$dom.state ]; then + if [ `find /var/lib/munin/plugin-state/xm_net_$dom.state -mmin +30 2> /dev/null | wc -l` -gt 0 ] || [ ! -f /var/lib/munin/plugin-state/xm_net_$dom.state ]; then content=$(/usr/sbin/xm network-list $dom) if [ $? -eq 0 ]; then echo "${content}" | egrep "^[0-9]+" | sed 's@^.*vif/\([0-9]*\)/\([0-9]*\).*$@vif\1.\2@' > /var/lib/munin/plugin-state/xm_net_$dom.state diff --git a/files/plugins/xen_vbd b/files/plugins/xen_vbd index a684839..e34d41c 100755 --- a/files/plugins/xen_vbd +++ b/files/plugins/xen_vbd @@ -50,7 +50,7 @@ if ( defined($ARGV[0])) 'graph_info' => 'Display the I/O operations for each domain', ); - @domains = `cat /var/lib/munin/plugin-state/xm_list.state`; + @domains = `cat /var/lib/munin/plugin-state/xm_list.state | grep -v 'Domain-0'`; foreach $domain ( @domains ) { @@ -85,7 +85,7 @@ if ( defined($ARGV[0])) # No args, get rolling -my @stats = `cat /var/lib/munin/plugin-state/xm_top.state`; +my @stats = `cat /var/lib/munin/plugin-state/xm_top.state | grep -v 'Domain-0'`; # remove the first line shift(@stats); -- cgit v1.2.3 From 68a4cb4ae4dc5aeeece00a1e40e41edcda82a8ff Mon Sep 17 00:00:00 2001 From: mh Date: Thu, 28 Feb 2013 20:29:55 +0100 Subject: move this to the apache module --- files/plugins/apache_activity | 99 ------------------------------------------- 1 file changed, 99 deletions(-) delete mode 100755 files/plugins/apache_activity (limited to 'files') diff --git a/files/plugins/apache_activity b/files/plugins/apache_activity deleted file mode 100755 index 65fc072..0000000 --- a/files/plugins/apache_activity +++ /dev/null @@ -1,99 +0,0 @@ -#!/usr/bin/perl -# -# Parameters supported: -# -# config -# autoconf -# -# Configurable variables -# -# url - Override default status-url -# -# Magic markers: -#%# family=auto -#%# capabilities=autoconf - -my $ret = undef; -if (!eval "require LWP::UserAgent;") { - $ret = "LWP::UserAgent not found"; -} - -my $URL = exists $ENV{'url'} ? $ENV{'url'} : "http://127.0.0.1:%d/server-status?auto"; -my @PORTS = exists $ENV{'ports'} ? split(' ', $ENV{'ports'}) : (80); -my %chars = ( - # '\_' => 'Waiting', - # 'S' => 'Starting up', - 'R' => 'Reading request', - 'W' => 'Sending reply', - 'K' => 'Keepalive', - 'D' => 'DNS lookup', - 'C' => 'Closing', - # 'L' => 'Logging', - # 'G' => 'Gracefully finishing', - # 'I' => 'Idle cleanup', - # '\.' => 'Open slot', - ); - -# "_" Waiting for Connection, "S" Starting up, "R" Reading Request, -# "W" Sending Reply, "K" Keepalive (read), "D" DNS Lookup, -# "C" Closing connection, "L" Logging, "G" Gracefully finishing, -# "I" Idle cleanup of worker, "." Open slot with no current process - -if (exists $ARGV[0] and $ARGV[0] eq "autoconf") { - if ($ret) { - print "no ($ret)\n"; - exit 1; - } - my $ua = LWP::UserAgent->new(timeout => 30); - my @badports; - - foreach my $port (@PORTS) { - my $url = sprintf $URL, $port; - my $response = $ua->request(HTTP::Request->new('GET',$url)); - push @badports, $port unless $response->is_success and $response->content =~ /Scoreboard/im; - } - - if (@badports) { - print "no (no apache server-status on ports @badports)\n"; - exit 1; - } else { - print "yes\n"; - exit 0; - } -} - -if (exists $ARGV[0] and $ARGV[0] eq "config") { - print "graph_title Apache activity\n"; - print "graph_args --base 1000 -l 0\n"; - print "graph_category apache\n"; - print "graph_vlabel processes\n"; - foreach my $port (@PORTS) { - while (my ($char, $val) = each (%chars)) { - $char =~ s/\\\./dot/; - $char =~ s/\\\_/underline/; - print "activity_${port}_${char}.label "; - print $val, "\n"; - print "activity_${port}_${char}.type GAUGE\n"; - } - } - exit 0; -} - -foreach my $port (@PORTS) { - my $ua = LWP::UserAgent->new (timeout => 30); - my $url = sprintf $URL, $port; - my $response = $ua->request (HTTP::Request->new('GET',$url)); - if ($response->content =~ /^Scoreboard\:\s?(.*)$/sm) { - my $string = $1; - chomp $string; - my @act = split (//, $string); - foreach my $char (keys (%chars)) { - my $num = scalar (grep (/$char/, @act)); - $char =~ s/\\\./dot/; - $char =~ s/\\\_/underline/; - print "activity_${port}_${char}.value $num\n"; - } - } -} - - -- cgit v1.2.3