Ejemplo n.º 1
0
static int data_source_filepoll(void * vinstance, wsdata_t* source_data,
                                ws_doutput_t * dout, int type_index) {

     proc_instance_t * proc = (proc_instance_t*)vinstance;
     
     if (!proc->fp) {
          time_t tnext = local_get_time();
          if (tnext > proc->next_time) {
               dprint("time %d %d %d", (int)tnext, (int)proc->next_time, (int)proc->poll_duration);
               proc->fp = gzopen(proc->poll_filename, "r");
               proc->next_time = tnext + proc->poll_duration;
          }
     }

     if (proc->fp) {
          if (poll_file(proc, source_data)) {
               wsdt_tuple_t * tuple = (wsdt_tuple_t*)source_data->data;
               if (tuple->len) {
                    ws_set_outdata(source_data, proc->outtype_tuple, dout);
               }
          }
     }

     return 1;
}
Ejemplo n.º 2
0
int system_poll_metrics(monikor_t *mon, struct timeval *clock) {
  uint64_t value;
  char *stat;
  int n = 0;

  if (!(stat = monikor_read_file("/proc/stat")))
    return 0;
  for (size_t i = 0; metrics[i].name; i++) {
    if (poll_metric(metrics[i].stat_name, stat, &value))
      continue;
    // printf("METRIC %s: %" PRIu64 "\n", metrics[i].name, value);
    n += monikor_metric_push(mon, monikor_metric_integer(
      metrics[i].name, clock, value, MONIKOR_METRIC_TIMEDELTA));
  }
  n += poll_inode(mon, clock);
  n += poll_file(mon, clock);
  free(stat);
  return n;
}