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>
34 # include <statgrab.h>
35 #endif /* HAVE_STATGRAB_H */
39 /* #endif HAVE_UTMPX_H */
43 /* #endif HAVE_UTMP_H */
46 static void users_submit (gauge_t value)
48 value_list_t vl = VALUE_LIST_INIT;
50 vl.values = &(value_t) { .gauge = value };
52 sstrncpy (vl.host, hostname_g, sizeof (vl.host));
53 sstrncpy (vl.plugin, "users", sizeof (vl.plugin));
54 sstrncpy (vl.type, "users", sizeof (vl.plugin));
56 plugin_dispatch_values (&vl);
57 } /* void users_submit */
59 static int users_read (void)
62 unsigned int users = 0;
63 struct utmpx *entry = NULL;
65 /* according to the *utent(3) man page none of the functions sets errno
66 in case of an error, so we cannot do any error-checking here */
69 while (NULL != (entry = getutxent())) {
70 if (USER_PROCESS == entry->ut_type) {
77 /* #endif HAVE_GETUTXENT */
80 unsigned int users = 0;
81 struct utmp *entry = NULL;
83 /* according to the *utent(3) man page none of the functions sets errno
84 in case of an error, so we cannot do any error-checking here */
87 while (NULL != (entry = getutent())) {
88 if (USER_PROCESS == entry->ut_type) {
95 /* #endif HAVE_GETUTENT */
97 #elif HAVE_LIBSTATGRAB
100 # if HAVE_LIBSTATGRAB_0_90
102 us = sg_get_user_stats (&num_entries);
104 us = sg_get_user_stats ();
109 users_submit ((gauge_t)
110 # if HAVE_LIBSTATGRAB_0_90
115 /* #endif HAVE_LIBSTATGRAB */
118 # error "No applicable input method."
122 } /* int users_read */
124 void module_register (void)
126 plugin_register_read ("users", users_read);
127 } /* void module_register(void) */