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 values[0].gauge = value;
63 vl.time = time (NULL);
64 strcpy (vl.host, hostname_g);
65 strcpy (vl.plugin, "users");
67 plugin_dispatch_values ("users", &vl);
68 } /* void users_submit */
70 static int users_read (void)
73 unsigned int users = 0;
74 struct utmpx *entry = NULL;
76 /* according to the *utent(3) man page none of the functions sets errno
77 in case of an error, so we cannot do any error-checking here */
80 while (NULL != (entry = getutxent())) {
81 if (USER_PROCESS == entry->ut_type) {
88 /* #endif HAVE_GETUTXENT */
91 unsigned int users = 0;
92 struct utmp *entry = NULL;
94 /* according to the *utent(3) man page none of the functions sets errno
95 in case of an error, so we cannot do any error-checking here */
98 while (NULL != (entry = getutent())) {
99 if (USER_PROCESS == entry->ut_type) {
105 users_submit (users);
106 #endif /* HAVE_GETUTENT */
109 } /* int users_read */
110 #endif /* USERS_HAVE_READ */
112 void module_register (modreg_e load)
114 if (load & MR_DATASETS)
115 plugin_register_data_set (&ds);
119 plugin_register_read ("users", users_read);
121 } /* void module_register(void) */