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; 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>
29 #else /* !HAVE_UTMPX_H */
32 # endif /* HAVE_UTMP_H */
33 #endif /* HAVE_UTMPX_H */
35 #define MODULE_NAME "users"
37 #if HAVE_GETUTXENT || HAVE_GETUTENT
38 # define USERS_HAVE_READ 1
40 # define USERS_HAVE_READ 0
44 static void users_submit (gauge_t value)
47 value_list_t vl = VALUE_LIST_INIT;
49 values[0].gauge = value;
53 vl.time = time (NULL);
54 strcpy (vl.host, hostname_g);
55 strcpy (vl.plugin, "users");
57 plugin_dispatch_values ("users", &vl);
58 } /* void users_submit */
60 static int users_read (void)
63 unsigned int users = 0;
64 struct utmpx *entry = NULL;
66 /* according to the *utent(3) man page none of the functions sets errno
67 in case of an error, so we cannot do any error-checking here */
70 while (NULL != (entry = getutxent())) {
71 if (USER_PROCESS == entry->ut_type) {
78 /* #endif HAVE_GETUTXENT */
81 unsigned int users = 0;
82 struct utmp *entry = NULL;
84 /* according to the *utent(3) man page none of the functions sets errno
85 in case of an error, so we cannot do any error-checking here */
88 while (NULL != (entry = getutent())) {
89 if (USER_PROCESS == entry->ut_type) {
96 #endif /* HAVE_GETUTENT */
99 } /* int users_read */
100 #endif /* USERS_HAVE_READ */
102 void module_register (void)
105 plugin_register_read ("users", users_read);
107 } /* void module_register(void) */