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;
47 /* we have nothing to do here :-) */
54 unsigned int users = 0;
55 struct utmpx *entry = NULL;
57 /* according to the *utent(3) man page none of the functions sets errno in
58 * case of an error, so we cannot do any error-checking here */
61 while (NULL != (entry = getutxent()))
62 if (USER_PROCESS == entry->ut_type)
67 /* #endif HAVE_GETUTXENT */
69 #elif defined(HAVE_GETUTENT)
70 unsigned int users = 0;
71 struct utmp *entry = NULL;
73 /* according to the *utent(3) man page none of the functions sets errno in
74 * case of an error, so we cannot do any error-checking here */
77 while (NULL != (entry = getutent()))
78 if (USER_PROCESS == entry->ut_type)
88 /* I don't like this temporary macro definition - well it's used everywhere
89 * else in the collectd-sources, so I will just stick with it... */
91 void users_submit(users)
94 char buf[BUFSIZE] = "";
96 if (snprintf(buf, BUFSIZE, "%u:%u",
97 (unsigned int)curtime,
101 plugin_submit(MODULE_NAME, NULL, buf);
106 void users_write(host, inst, val)
111 rrd_update_file(host, rrd_file, val, ds_def, ds_num);
115 void module_register(void)
117 plugin_register(MODULE_NAME, users_init, users_read, users_write);
122 #endif /* COLLECT_USERS */