2 * collectd - src/users.c
3 * Copyright (C) 2005 Sebastian Harl
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; either version 2 of the License, or (at your
8 * option) any later version.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 * Sebastian Harl <sh at tokkee.org>
26 #define MODULE_NAME "users"
33 #elif defined(HAVE_UTMP_H)
37 static char *rrd_file = "users.rrd";
39 static char *ds_def[] = {
40 "DS:users:GAUGE:25:0:65535",
43 static int ds_num = 1;
45 extern time_t curtime;
49 /* we have nothing to do here :-) */
56 unsigned int users = 0;
57 struct utmpx *entry = NULL;
59 /* according to the *utent(3) man page none of the functions sets errno in
60 * case of an error, so we cannot do any error-checking here */
63 while (NULL != (entry = getutxent()))
64 if (USER_PROCESS == entry->ut_type)
69 /* #endif HAVE_GETUTXENT */
71 #elif defined(HAVE_GETUTENT)
72 unsigned int users = 0;
73 struct utmp *entry = NULL;
75 /* according to the *utent(3) man page none of the functions sets errno in
76 * case of an error, so we cannot do any error-checking here */
79 while (NULL != (entry = getutent()))
80 if (USER_PROCESS == entry->ut_type)
90 /* I don't like this temporary macro definition - well it's used everywhere
91 * else in the collectd-sources, so I will just stick with it... */
93 void users_submit(users)
96 char buf[BUFSIZE] = "";
98 if (snprintf(buf, BUFSIZE, "%u:%u",
99 (unsigned int)curtime,
103 plugin_submit(MODULE_NAME, NULL, buf);
108 void users_write(host, inst, val)
113 rrd_update_file(host, rrd_file, val, ds_def, ds_num);
117 void module_register(void)
119 plugin_register(MODULE_NAME, users_init, users_read, users_write);
124 #endif /* COLLECT_USERS */