2 * collectd - src/wpar.c
3 * Copyright (C) 2010 Manuel Sanmartin
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; only version 2 of the License is applicable.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 * Manuel Sanmartin <manuel.luis at gmail.com>
27 # error "No applicable input method."
30 #include <sys/proc.h> /* AIX 5 */
31 #include <sys/protosw.h>
32 #include <libperfstat.h>
37 static perfstat_wpar_total_t *wpar_total;
38 static perfstat_memory_total_wpar_t wmemory;
39 static perfstat_cpu_total_wpar_t wcpu;
41 static int wpar_init(void)
43 pagesize = getpagesize ();
47 static void memory_submit (const char *plugin_instance, const char *type_instance, gauge_t value)
50 value_list_t vl = VALUE_LIST_INIT;
52 values[0].gauge = value;
56 sstrncpy (vl.host, hostname_g, sizeof (vl.host));
57 sstrncpy (vl.plugin, "wpar", sizeof (vl.plugin));
58 sstrncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance));
59 sstrncpy (vl.type, "memory", sizeof (vl.type));
60 sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance));
62 plugin_dispatch_values (&vl);
65 static void cpu_submit (const char *plugin_instance, const char *type_instance, counter_t value)
68 value_list_t vl = VALUE_LIST_INIT;
70 values[0].counter = value;
74 sstrncpy (vl.host, hostname_g, sizeof (vl.host));
75 sstrncpy (vl.plugin, "wpar", sizeof (vl.plugin));
76 sstrncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance));
77 sstrncpy (vl.type, "cpu", sizeof (vl.type));
78 sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance));
80 plugin_dispatch_values (&vl);
83 static void load_submit (const char *plugin_instance, gauge_t snum, gauge_t mnum, gauge_t lnum)
86 value_list_t vl = VALUE_LIST_INIT;
88 values[0].gauge = snum;
89 values[1].gauge = mnum;
90 values[2].gauge = lnum;
93 vl.values_len = STATIC_ARRAY_SIZE (values);
94 sstrncpy (vl.host, hostname_g, sizeof (vl.host));
95 sstrncpy (vl.plugin, "load", sizeof (vl.plugin));
96 sstrncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance));
97 sstrncpy (vl.type, "load", sizeof (vl.type));
99 plugin_dispatch_values (&vl);
102 static int wpar_read (void)
105 float snum, mnum, lnum;
106 perfstat_id_wpar_t id_wpar;
108 nwpar = perfstat_wpar_total(NULL, NULL, sizeof(perfstat_wpar_total_t), 0);
112 WARNING ("wpar plugin: perfstat_wpar_total: %s",
113 sstrerror (errno, errbuf, sizeof (errbuf)));
117 if (pwpar != nwpar || wpar_total == NULL)
119 if (wpar_total != NULL)
121 wpar_total = malloc(nwpar * sizeof(perfstat_wpar_total_t));
125 bzero(&id_wpar, sizeof(perfstat_id_wpar_t));
126 id_wpar.spec = WPARID;
127 id_wpar.u.wpar_id = FIRST_WPARID;
128 if ((wpars = perfstat_wpar_total(&id_wpar, wpar_total, sizeof(perfstat_wpar_total_t), nwpar)) < 0)
131 WARNING ("cpu plugin: perfstat_wpar_total: %s",
132 sstrerror (errno, errbuf, sizeof (errbuf)));
136 for (i = 0; i < wpars; i++)
138 char *wname = wpar_total[i].name;
140 bzero(&id_wpar, sizeof(perfstat_id_wpar_t));
141 id_wpar.spec = WPARID;
142 id_wpar.u.wpar_id = wpar_total[i].wpar_id;
144 if (perfstat_memory_total_wpar(&id_wpar, &wmemory, sizeof(perfstat_memory_total_wpar_t), 1) < 0)
147 WARNING ("memory plugin: perfstat_memory_total_wpar failed: %s",
148 sstrerror (errno, errbuf, sizeof (errbuf)));
151 memory_submit (wname, "used", wmemory.real_inuse * pagesize);
152 memory_submit (wname, "free", wmemory.real_free * pagesize);
153 memory_submit (wname, "cached", wmemory.numperm * pagesize);
154 memory_submit (wname, "total", wmemory.real_total * pagesize);
157 if (perfstat_cpu_total_wpar(&id_wpar, &wcpu, sizeof(perfstat_cpu_total_wpar_t), 1) < 0)
160 WARNING ("memory plugin: perfstat_cpu_total_wpar failed: %s",
161 sstrerror (errno, errbuf, sizeof (errbuf)));
165 snum = (float)wcpu.loadavg[0]/(float)(1<<SBITS);
166 mnum = (float)wcpu.loadavg[1]/(float)(1<<SBITS);
167 lnum = (float)wcpu.loadavg[2]/(float)(1<<SBITS);
169 load_submit (wname, snum, mnum, lnum);
171 cpu_submit (wname, "idle", (counter_t) wcpu.pidle);
172 cpu_submit (wname, "system", (counter_t) wcpu.psys);
173 cpu_submit (wname, "user", (counter_t) wcpu.puser);
174 cpu_submit (wname, "wait", (counter_t) wcpu.pwait);
180 void module_register (void)
182 plugin_register_init ("wpar", wpar_init);
183 plugin_register_read ("wpar", wpar_read);