2 * collectd - src/users.c
3 * Copyright (C) 2005-2007 Sebastian Harl
4 * Copyright (C) 2005 Niki W. Waibel
5 * Copyright (C) 2005-2007 Florian octo Forster
6 * Copyright (C) 2008 Oleg King
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; only version 2 of the license is applicable.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 * Sebastian Harl <sh at tokkee.org>
23 * Niki W. Waibel <niki.waibel at newlogic.com>
24 * Florian octo Forster <octo at collectd.org>
25 * Oleg King <king2 at kaluga.ru>
33 # include <statgrab.h>
34 #endif /* HAVE_STATGRAB_H */
38 /* #endif HAVE_UTMPX_H */
42 /* #endif HAVE_UTMP_H */
45 # error "No applicable input method."
48 static void users_submit (gauge_t value)
51 value_list_t vl = VALUE_LIST_INIT;
53 values[0].gauge = value;
57 sstrncpy (vl.host, hostname_g, sizeof (vl.host));
58 sstrncpy (vl.plugin, "users", sizeof (vl.plugin));
59 sstrncpy (vl.type, "users", sizeof (vl.plugin));
61 plugin_dispatch_values (&vl);
62 } /* void users_submit */
64 static int users_read (void)
67 unsigned int users = 0;
68 struct utmpx *entry = NULL;
70 /* according to the *utent(3) man page none of the functions sets errno
71 in case of an error, so we cannot do any error-checking here */
74 while (NULL != (entry = getutxent())) {
75 if (USER_PROCESS == entry->ut_type) {
82 /* #endif HAVE_GETUTXENT */
85 unsigned int users = 0;
86 struct utmp *entry = NULL;
88 /* according to the *utent(3) man page none of the functions sets errno
89 in case of an error, so we cannot do any error-checking here */
92 while (NULL != (entry = getutent())) {
93 if (USER_PROCESS == entry->ut_type) {
100 /* #endif HAVE_GETUTENT */
102 #elif HAVE_LIBSTATGRAB
105 # if HAVE_LIBSTATGRAB_GET_USER_STATS_ARG
107 us = sg_get_user_stats (&num_entries);
109 us = sg_get_user_stats ();
114 users_submit ((gauge_t)
115 # if HAVE_LIBSTATGRAB_GET_USER_STATS_ARG
120 /* #endif HAVE_LIBSTATGRAB */
123 # error "No applicable input method."
127 } /* int users_read */
129 void module_register (void)
131 plugin_register_read ("users", users_read);
132 } /* void module_register(void) */