2 * collectd - src/users.c
3 * Copyright (C) 2005-2007 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; 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 * Sebastian Harl <sh at tokkee.org>
27 # include <statgrab.h>
28 #endif /* HAVE_STATGRAB_H */
32 /* #endif HAVE_UTMPX_H */
36 /* #endif HAVE_UTMP_H */
39 # error "No applicable input method."
42 static void users_submit (gauge_t value)
45 value_list_t vl = VALUE_LIST_INIT;
47 values[0].gauge = value;
51 vl.time = time (NULL);
52 strcpy (vl.host, hostname_g);
53 strcpy (vl.plugin, "users");
54 strcpy (vl.type, "users");
56 plugin_dispatch_values (&vl);
57 } /* void users_submit */
59 static int users_read (void)
62 unsigned int users = 0;
63 struct utmpx *entry = NULL;
65 /* according to the *utent(3) man page none of the functions sets errno
66 in case of an error, so we cannot do any error-checking here */
69 while (NULL != (entry = getutxent())) {
70 if (USER_PROCESS == entry->ut_type) {
77 /* #endif HAVE_GETUTXENT */
80 unsigned int users = 0;
81 struct utmp *entry = NULL;
83 /* according to the *utent(3) man page none of the functions sets errno
84 in case of an error, so we cannot do any error-checking here */
87 while (NULL != (entry = getutent())) {
88 if (USER_PROCESS == entry->ut_type) {
95 /* #endif HAVE_GETUTENT */
97 #elif HAVE_LIBSTATGRAB
100 us = sg_get_user_stats ();
104 users_submit ((gauge_t) us->num_entries);
105 /* #endif HAVE_LIBSTATGRAB */
108 # error "No applicable input method."
112 } /* int users_read */
114 void module_register (void)
116 plugin_register_read ("users", users_read);
117 } /* void module_register(void) */