[collectd] [PATCH] new plugin: AIX WPAR

Manuel Luis Sanmartín Rozada manuel.luis at gmail.com
Tue Jul 20 18:53:11 CEST 2010


---
 configure.in    |    4 +
 src/Makefile.am |   13 ++++
 src/wpar.c      |  185 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 202 insertions(+), 0 deletions(-)
 create mode 100644 src/wpar.c

diff --git a/configure.in b/configure.in
index fc12c08..0257dc7 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 00d0e20..12fc31b 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 0000000..f33645c
--- /dev/null
+++ b/src/wpar.c
@@ -0,0 +1,185 @@
+/**
+ * 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 <manuel.luis at gmail.com>
+ **/
+
+#include "collectd.h"
+#include "common.h"
+#include "plugin.h"
+
+#if !HAVE_PERFSTAT
+# error "No applicable input method."
+#endif
+
+#include <sys/proc.h> /* AIX 5 */
+#include <sys/protosw.h>
+#include <libperfstat.h>
+
+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<<SBITS);
+               mnum = (float)wcpu.loadavg[1]/(float)(1<<SBITS);
+               lnum = (float)wcpu.loadavg[2]/(float)(1<<SBITS);
+
+               load_submit (wname, snum, mnum, lnum);
+
+               cpu_submit (wname, "idle",   (counter_t) wcpu.pidle);
+                cpu_submit (wname, "system", (counter_t) wcpu.psys);
+                cpu_submit (wname, "user",   (counter_t) wcpu.puser);
+                cpu_submit (wname, "wait",   (counter_t) wcpu.pwait);
+        }
+
+       return (0);
+}
+
+void module_register (void)
+{
+       plugin_register_init ("wpar", wpar_init);
+       plugin_register_read ("wpar", wpar_read);
+}
+
-- 
1.7.1.1



More information about the collectd mailing list