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; }
void populate_load() { sg_load_stats *load = sg_get_load_stats(); if (load != NULL) { add_stat(DOUBLE, &load->min1, "load", "min1", NULL); add_stat(DOUBLE, &load->min5, "load", "min5", NULL); add_stat(DOUBLE, &load->min15, "load", "min15", NULL); } }
static void populate_load(void) { sg_load_stats *load = sg_get_load_stats(NULL); if (load != NULL) { add_stat(STAT_TYPE_DOUBLE, &load->min1, "load", "min1", NULL); add_stat(STAT_TYPE_DOUBLE, &load->min5, "load", "min5", NULL); add_stat(STAT_TYPE_DOUBLE, &load->min15, "load", "min15", NULL); } }
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; }
/* * System load, see <tt>sg_get_load_stats(3)</tt> manpage. */ static VALUE statgrab_load_stats(VALUE self) { sg_load_stats *load; VALUE info; if ((load = sg_get_load_stats()) == NULL) statgrab_handle_error(); info = rb_hash_new(); rb_hash_aset(info, ID2SYM(rb_intern("min1")), rb_float_new(load->min1)); rb_hash_aset(info, ID2SYM(rb_intern("min5")), rb_float_new(load->min5)); rb_hash_aset(info, ID2SYM(rb_intern("min15")), rb_float_new(load->min15)); return info; }
static int load_read (void) { #if defined(HAVE_GETLOADAVG) double load[3]; if (getloadavg (load, 3) == 3) load_submit (load[LOADAVG_1MIN], load[LOADAVG_5MIN], load[LOADAVG_15MIN]); else { char errbuf[1024]; WARNING ("load: getloadavg failed: %s", sstrerror (errno, errbuf, sizeof (errbuf))); } /* #endif HAVE_GETLOADAVG */ #elif defined(KERNEL_LINUX) gauge_t snum, mnum, lnum; FILE *loadavg; char buffer[16]; char *fields[8]; int numfields; if ((loadavg = fopen ("/proc/loadavg", "r")) == NULL) { char errbuf[1024]; WARNING ("load: fopen: %s", sstrerror (errno, errbuf, sizeof (errbuf))); return (-1); } if (fgets (buffer, 16, loadavg) == NULL) { char errbuf[1024]; WARNING ("load: fgets: %s", sstrerror (errno, errbuf, sizeof (errbuf))); fclose (loadavg); return (-1); } if (fclose (loadavg)) { char errbuf[1024]; WARNING ("load: fclose: %s", sstrerror (errno, errbuf, sizeof (errbuf))); } numfields = strsplit (buffer, fields, 8); if (numfields < 3) return (-1); snum = atof (fields[0]); mnum = atof (fields[1]); lnum = atof (fields[2]); load_submit (snum, mnum, lnum); /* #endif KERNEL_LINUX */ #elif HAVE_LIBSTATGRAB gauge_t snum, mnum, lnum; sg_load_stats *ls; if ((ls = sg_get_load_stats ()) == NULL) return; snum = ls->min1; mnum = ls->min5; lnum = ls->min15; load_submit (snum, mnum, lnum); /* #endif HAVE_LIBSTATGRAB */ #else # error "No applicable input method." #endif return (0); }