From 2b21b8110edad4f701718988ae95c4aaa6a3d62f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Manuel=20Luis=20Sanmart=C3=ADn=20Rozada?= Date: Tue, 20 Jul 2010 18:53:11 +0200 Subject: [PATCH] new plugin: AIX WPAR Signed-off-by: Florian Forster --- configure.in | 4 ++ src/Makefile.am | 13 ++++ src/wpar.c | 184 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 201 insertions(+) create mode 100644 src/wpar.c diff --git a/configure.in b/configure.in index fc12c088..0257dc7f 100644 --- a/configure.in +++ b/configure.in @@ -4145,6 +4145,7 @@ plugin_users="no" plugin_uptime="no" plugin_vmem="no" plugin_vserver="no" +plugin_wpar="no" plugin_wireless="no" plugin_zfs_arc="no" @@ -4202,6 +4203,7 @@ then plugin_swap="yes" plugin_interface="yes" plugin_load="yes" + plugin_wpar="yes" fi if test "x$with_procinfo" = "xyes" @@ -4501,6 +4503,7 @@ AC_PLUGIN([varnish], [$with_libvarnish], [Varnish cache statistics]) AC_PLUGIN([vmem], [$plugin_vmem], [Virtual memory statistics]) AC_PLUGIN([vserver], [$plugin_vserver], [Linux VServer statistics]) AC_PLUGIN([wireless], [$plugin_wireless], [Wireless statistics]) +AC_PLUGIN([wpar], [$plugin_wpar], [WPAR statistics]) AC_PLUGIN([write_http], [$with_libcurl], [HTTP output plugin]) AC_PLUGIN([xmms], [$with_libxmms], [XMMS statistics]) AC_PLUGIN([zfs_arc], [$plugin_zfs_arc], [ZFS ARC statistics]) @@ -4820,6 +4823,7 @@ Configuration: vmem . . . . . . . . $enable_vmem vserver . . . . . . . $enable_vserver wireless . . . . . . $enable_wireless + wpar . . . . . . . . $enable_wpar write_http . . . . . $enable_write_http xmms . . . . . . . . $enable_xmms zfs_arc . . . . . . . $enable_zfs_arc diff --git a/src/Makefile.am b/src/Makefile.am index 00d0e20e..aca1f420 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1185,6 +1185,19 @@ collectd_LDADD += "-dlopen" wireless.la collectd_DEPENDENCIES += wireless.la endif +if BUILD_PLUGIN_WPAR +pkglib_LTLIBRARIES += wpar.la +wpar_la_SOURCES = wpar.c +wpar_la_CFLAGS = $(AM_CFLAGS) +wpar_la_LDFLAGS = -module -avoid-version +wpar_la_LIBADD = +if BUILD_WITH_PERFSTAT +wpar_la_LIBADD += -lperfstat +endif +collectd_LDADD += "-dlopen" wpar.la +collectd_DEPENDENCIES += wpar.la +endif + if BUILD_PLUGIN_WRITE_HTTP pkglib_LTLIBRARIES += write_http.la write_http_la_SOURCES = write_http.c \ diff --git a/src/wpar.c b/src/wpar.c new file mode 100644 index 00000000..ac9bd21c --- /dev/null +++ b/src/wpar.c @@ -0,0 +1,184 @@ +/** + * collectd - src/wpar.c + * Copyright (C) 2010 Manuel Sanmartin + * + * 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; only version 2 of the License is applicable. + * + * 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 St, Fifth Floor, Boston, MA 02110-1301 USA + * + * Authors: + * Manuel Sanmartin + **/ + +#include "collectd.h" +#include "common.h" +#include "plugin.h" + +#if !HAVE_PERFSTAT +# error "No applicable input method." +#endif + +#include /* AIX 5 */ +#include +#include + +static int pagesize; +int nwpar = -1; +int pwpar; +static perfstat_wpar_total_t *wpar_total; +static perfstat_memory_total_wpar_t wmemory; +static perfstat_cpu_total_wpar_t wcpu; + +static int wpar_init(void) +{ + pagesize = getpagesize (); + return (0); +} + +static void memory_submit (const char *plugin_instance, const char *type_instance, gauge_t value) +{ + value_t values[1]; + value_list_t vl = VALUE_LIST_INIT; + + values[0].gauge = value; + + vl.values = values; + vl.values_len = 1; + sstrncpy (vl.host, hostname_g, sizeof (vl.host)); + sstrncpy (vl.plugin, "wpar", sizeof (vl.plugin)); + sstrncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance)); + sstrncpy (vl.type, "memory", sizeof (vl.type)); + sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance)); + + plugin_dispatch_values (&vl); +} + +static void cpu_submit (const char *plugin_instance, const char *type_instance, counter_t value) +{ + value_t values[1]; + value_list_t vl = VALUE_LIST_INIT; + + values[0].counter = value; + + vl.values = values; + vl.values_len = 1; + sstrncpy (vl.host, hostname_g, sizeof (vl.host)); + sstrncpy (vl.plugin, "wpar", sizeof (vl.plugin)); + sstrncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance)); + sstrncpy (vl.type, "cpu", sizeof (vl.type)); + sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance)); + + plugin_dispatch_values (&vl); +} + +static void load_submit (const char *plugin_instance, gauge_t snum, gauge_t mnum, gauge_t lnum) +{ + value_t values[3]; + value_list_t vl = VALUE_LIST_INIT; + + values[0].gauge = snum; + values[1].gauge = mnum; + values[2].gauge = lnum; + + vl.values = values; + vl.values_len = STATIC_ARRAY_SIZE (values); + sstrncpy (vl.host, hostname_g, sizeof (vl.host)); + sstrncpy (vl.plugin, "load", sizeof (vl.plugin)); + sstrncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance)); + sstrncpy (vl.type, "load", sizeof (vl.type)); + + plugin_dispatch_values (&vl); +} + +static int wpar_read (void) +{ + int i,wpars; + float snum, mnum, lnum; + perfstat_id_wpar_t id_wpar; + + nwpar = perfstat_wpar_total(NULL, NULL, sizeof(perfstat_wpar_total_t), 0); + if (nwpar == -1) + { + char errbuf[1024]; + WARNING ("wpar plugin: perfstat_wpar_total: %s", + sstrerror (errno, errbuf, sizeof (errbuf))); + return (-1); + } + + if (pwpar != nwpar || wpar_total == NULL) + { + if (wpar_total != NULL) + free(wpar_total); + wpar_total = malloc(nwpar * sizeof(perfstat_wpar_total_t)); + } + pwpar = nwpar; + + bzero(&id_wpar, sizeof(perfstat_id_wpar_t)); + id_wpar.spec = WPARID; + id_wpar.u.wpar_id = FIRST_WPARID; + if ((wpars = perfstat_wpar_total(&id_wpar, wpar_total, sizeof(perfstat_wpar_total_t), nwpar)) < 0) + { + char errbuf[1024]; + WARNING ("cpu plugin: perfstat_wpar_total: %s", + sstrerror (errno, errbuf, sizeof (errbuf))); + return (-1); + } + + for (i = 0; i < wpars; i++) + { + char *wname = wpar_total[i].name; + + bzero(&id_wpar, sizeof(perfstat_id_wpar_t)); + id_wpar.spec = WPARID; + id_wpar.u.wpar_id = wpar_total[i].wpar_id; + + if (perfstat_memory_total_wpar(&id_wpar, &wmemory, sizeof(perfstat_memory_total_wpar_t), 1) < 0) + { + char errbuf[1024]; + WARNING ("memory plugin: perfstat_memory_total_wpar failed: %s", + sstrerror (errno, errbuf, sizeof (errbuf))); + return (-1); + } + memory_submit (wname, "used", wmemory.real_inuse * pagesize); + memory_submit (wname, "free", wmemory.real_free * pagesize); + memory_submit (wname, "cached", wmemory.numperm * pagesize); + memory_submit (wname, "total", wmemory.real_total * pagesize); + + + if (perfstat_cpu_total_wpar(&id_wpar, &wcpu, sizeof(perfstat_cpu_total_wpar_t), 1) < 0) + { + char errbuf[1024]; + WARNING ("memory plugin: perfstat_cpu_total_wpar failed: %s", + sstrerror (errno, errbuf, sizeof (errbuf))); + return (-1); + } + + snum = (float)wcpu.loadavg[0]/(float)(1<