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
43 static data_source_t dsrc[1] =
45 {"users", DS_TYPE_GAUGE, 0.0, 65535.0}
48 static data_set_t ds =
54 static void users_submit (gauge_t value)
57 value_list_t vl = VALUE_LIST_INIT;
59 DBG ("value = %lf;", value);
61 values[0].gauge = value;
65 vl.time = time (NULL);
66 strcpy (vl.host, hostname_g);
67 strcpy (vl.plugin, "users");
69 plugin_dispatch_values ("users", &vl);
70 } /* void users_submit */
72 static int users_read (void)
75 unsigned int users = 0;
76 struct utmpx *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 = getutxent())) {
83 if (USER_PROCESS == entry->ut_type) {
90 /* #endif HAVE_GETUTXENT */
93 unsigned int users = 0;
94 struct utmp *entry = NULL;
96 /* according to the *utent(3) man page none of the functions sets errno
97 in case of an error, so we cannot do any error-checking here */
100 while (NULL != (entry = getutent())) {
101 if (USER_PROCESS == entry->ut_type) {
107 users_submit (users);
108 #endif /* HAVE_GETUTENT */
111 } /* int users_read */
112 #endif /* USERS_HAVE_READ */
114 void module_register (void)
116 plugin_register_data_set (&ds);
117 plugin_register_read ("users", users_read);
119 } /* void module_register(void) */