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>
28 /* #endif HAVE_UTMPX_H */
32 /* #endif HAVE_UTMP_H */
35 # error "No applicable input method."
38 static void users_submit (gauge_t value)
41 value_list_t vl = VALUE_LIST_INIT;
43 values[0].gauge = value;
47 vl.time = time (NULL);
48 strcpy (vl.host, hostname_g);
49 strcpy (vl.plugin, "users");
51 plugin_dispatch_values ("users", &vl);
52 } /* void users_submit */
54 static int users_read (void)
57 unsigned int users = 0;
58 struct utmpx *entry = NULL;
60 /* according to the *utent(3) man page none of the functions sets errno
61 in case of an error, so we cannot do any error-checking here */
64 while (NULL != (entry = getutxent())) {
65 if (USER_PROCESS == entry->ut_type) {
72 /* #endif HAVE_GETUTXENT */
75 unsigned int users = 0;
76 struct utmp *entry = NULL;
78 /* according to the *utent(3) man page none of the functions sets errno
79 in case of an error, so we cannot do any error-checking here */
82 while (NULL != (entry = getutent())) {
83 if (USER_PROCESS == entry->ut_type) {
90 /* #endif HAVE_GETUTENT */
93 # error "No applicable input method."
97 } /* int users_read */
99 void module_register (void)
101 plugin_register_read ("users", users_read);
102 } /* void module_register(void) */