Esempio n. 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;
}
Esempio n. 2
0
void populate_page() {
	sg_page_stats *page;

	page = use_diffs ? sg_get_page_stats_diff() : sg_get_page_stats();
	if (page != NULL) {
		add_stat(LONG_LONG, &page->pages_pagein, "page", "in", NULL);
		add_stat(LONG_LONG, &page->pages_pageout, "page", "out", NULL);
		add_stat(TIME_T, &page->systime, "page", "systime", NULL);
	}
}
Esempio n. 3
0
int main(int argc, char **argv){

	extern char *optarg;
	int c;

	int delay = 1;
	sg_page_stats *page_stats;

	while ((c = getopt(argc, argv, "d:")) != -1){
		switch (c){
			case 'd':
				delay = atoi(optarg);
				break;
		}
	}

	/* Initialise helper - e.g. logging, if any */
	sg_log_init("libstatgrab-examples", "SGEXAMPLES_LOG_PROPERTIES", argc ? argv[0] : NULL);

	/* Initialise statgrab */
	sg_init(1);

	register_sig_flagger( SIGINT, &quit );

	/* Drop setuid/setgid privileges. */
	if (sg_drop_privileges() != SG_ERROR_NONE)
		sg_die("Error. Failed to drop privileges", 1);

	page_stats = sg_get_page_stats_diff(NULL);
	if(page_stats == NULL)
		sg_die("Failed to get page stats", 1);

	while( (page_stats = sg_get_page_stats_diff(NULL)) != NULL){
		int ch;
		printf("Pages in : %llu\n", page_stats->pages_pagein);
		printf("Pages out : %llu\n", page_stats->pages_pageout);
		ch = inp_wait(delay);
		if( quit || (ch == 'q') )
			break;
	}

	exit(0);
}
Esempio n. 4
0
static void
populate_page(void) {
	sg_page_stats *page;

	page = use_diffs ? sg_get_page_stats_diff(NULL) : sg_get_page_stats(NULL);
	if (page != NULL) {
		add_stat(STAT_TYPE_UNSIGNED_LONG_LONG, &page->pages_pagein, "page", "in", NULL);
		add_stat(STAT_TYPE_UNSIGNED_LONG_LONG, &page->pages_pageout, "page", "out", NULL);
		add_stat(STAT_TYPE_TIME_T, &page->systime, "page", "systime", NULL);
	}
}
Esempio n. 5
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;
}
Esempio n. 6
0
/*
 * Paging statistics difference since last call,
 * see <tt>sg_get_page_stats(3)</tt> manpage.
 */
static VALUE
statgrab_page_stats_diff(VALUE self)
{
	sg_page_stats *stats;
	VALUE info, time_now;

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

	info = rb_hash_new();
	rb_hash_aset(info, ID2SYM(rb_intern("pages_pagein")),
			INT2NUM(stats->pages_pagein));
	rb_hash_aset(info, ID2SYM(rb_intern("pages_pageout")),
			INT2NUM(stats->pages_pageout));
	rb_hash_aset(info, ID2SYM(rb_intern("systime")),
			INT2NUM(stats->systime));

	time_now = rb_funcall(rb_cTime, rb_intern("now"), 0);
	rb_hash_aset(info, ID2SYM(rb_intern("last_call")),
			rb_funcall(time_now, rb_intern("-"), 1,
				INT2NUM(stats->systime)));

	return info;
}