Example #1
0
int get_stats(void)
{
  st.cpu = sg_get_cpu_percents();
  if (!st.cpu) { LOG(LOG_INFO, "could not sg_get_cpu_stats"); }
  st.mem = sg_get_mem_stats();
  if (!st.mem) { LOG(LOG_INFO, "could not sg_get_mem_stats"); }
  st.swap = sg_get_swap_stats();
  if (!st.swap) { LOG(LOG_INFO, "could not get_swap_stats"); }
  st.load = sg_get_load_stats();
  if (!st.load) { LOG(LOG_INFO, "could not get_load_stats"); }
  st.process = sg_get_process_stats(&st.process_entries);
  if (!st.process) { LOG(LOG_INFO, "could not get_process_stats"); }
  st.paging = sg_get_page_stats_diff();
  if (!st.paging) { LOG(LOG_INFO, "could not get_page_stats_diff"); }
  st.network = sg_get_network_io_stats_diff(&(st.network_entries));
  if (!st.network) { LOG(LOG_INFO, "could not get_network_stats_diff"); }
  st.diskio = sg_get_disk_io_stats_diff(&(st.diskio_entries));
  if (!st.diskio) { LOG(LOG_INFO, "could not get_diskio_stats_diff"); }
  st.disk = sg_get_fs_stats(&(st.disk_entries));
  if (!st.disk) { LOG(LOG_INFO, "could not get_disk_stats"); }
  st.hostinfo = sg_get_host_info();
  if (!st.hostinfo) { LOG(LOG_INFO, "could not get_host_info"); }
  st.user = sg_get_user_stats();
  if (!st.user) { LOG(LOG_INFO, "could not get get_user_stats"); }

  return 1;
}
Example #2
0
void populate_user() {
	sg_user_stats *user = sg_get_user_stats();

	if (user != NULL) {
		add_stat(INT, &user->num_entries, "user", "num", NULL);
		add_stat(STRING, &user->name_list, "user", "names", NULL);
	}
}
Example #3
0
static int users_read (void)
{
#if HAVE_GETUTXENT
	unsigned int users = 0;
	struct utmpx *entry = NULL;

	/* according to the *utent(3) man page none of the functions sets errno
	   in case of an error, so we cannot do any error-checking here */
	setutxent();

	while (NULL != (entry = getutxent())) {
		if (USER_PROCESS == entry->ut_type) {
			++users;
		}
	}
	endutxent();

	users_submit (users);
/* #endif HAVE_GETUTXENT */
	
#elif HAVE_GETUTENT
	unsigned int users = 0;
	struct utmp *entry = NULL;

	/* according to the *utent(3) man page none of the functions sets errno
	   in case of an error, so we cannot do any error-checking here */
	setutent();

	while (NULL != (entry = getutent())) {
		if (USER_PROCESS == entry->ut_type) {
			++users;
		}
	}
	endutent();

	users_submit (users);
/* #endif HAVE_GETUTENT */

#elif HAVE_LIBSTATGRAB
	sg_user_stats *us;

	us = sg_get_user_stats ();
	if (us == NULL)
		return (-1);   

	users_submit ((gauge_t) us->num_entries);
/* #endif HAVE_LIBSTATGRAB */

#else
# error "No applicable input method."
#endif

	return (0);
} /* int users_read */
Example #4
0
int get_stats() {
    stats.cpu_percents = sg_get_cpu_percents();
    stats.mem_stats = sg_get_mem_stats();
    stats.swap_stats = sg_get_swap_stats();
    stats.load_stats = sg_get_load_stats();
    stats.process_count = sg_get_process_count();
    stats.page_stats = sg_get_page_stats_diff();
    stats.network_io_stats = sg_get_network_io_stats_diff(&(stats.network_io_entries));
    stats.disk_io_stats = sg_get_disk_io_stats_diff(&(stats.disk_io_entries));
    stats.fs_stats = sg_get_fs_stats(&(stats.fs_entries));
    stats.host_info = sg_get_host_info();
    stats.user_stats = sg_get_user_stats();

    return 1;
}
Example #5
0
static void
populate_user(void) {
	static size_t entries;
	static char *name_list = NULL;
	size_t name_list_length = 0, pos = 0;

	sg_user_stats *users = sg_get_user_stats(&entries);

	if (users != NULL) {
		size_t i;
		for (i = 0; i < entries; i++) {
			const char *name = users[i].login_name;
			const char *tty = users[i].device;

			name_list_length += strlen(name) + 1;

			add_stat(STRING, &users[i].login_name,
				 "user", tty, "login_name", NULL);
			add_stat(STRING, &users[i].device,
				 "user", tty, "tty", NULL);
			add_stat(STRING, &users[i].hostname,
				 "user", tty, "from", NULL);
			add_stat(TIME_T, &users[i].login_time,
				 "user", tty, "login_time", NULL);
		}

		name_list = realloc(name_list, name_list_length + 1);

		for (i = 0; i < entries; i++) {
			const char *name = users[i].login_name;

			strncpy(name_list + pos, name, strlen(name));
			pos += strlen(name);
			name_list[pos] = ' ';
			pos ++;
		}

		if (entries != 0) {
			pos--;
		}
		name_list[pos] = '\0';

		add_stat(INT, &entries, "user", "num", NULL);
		add_stat(STRING, &name_list, "user", "names", NULL);
	}
}
Example #6
0
/*
 * The current logged in users,
 * see <tt>sg_get_user_stats(3)</tt> manpage.
 *
 * Returns an array of login names.
 */
static VALUE
statgrab_user_stats(VALUE self)
{
	int i;
	char *names, *token, *saveptr;
	sg_user_stats *stats;
	VALUE arr;

	if ((stats = sg_get_user_stats()) == NULL)
		statgrab_handle_error();

	arr = rb_ary_new();
	for (i = 0, names = stats->name_list; i < stats->num_entries;
			i++, names = NULL) {
		token = strtok_r(names, " ", &saveptr);
		rb_ary_push(arr, rb_str_new2(token));
	}

	return arr;
}