DD2-monitor/core/sysmetrics.c

39 lines
675 B
C
Raw Normal View History

2019-01-29 02:57:45 +11:00
/*
* core/sysmetrics.c
*/
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "sysmetrics.h"
extern int verbosity;
/* --------------------------------------------------------------- */
2019-01-31 05:14:40 +11:00
int get_loadavg(float *where)
2019-01-29 02:57:45 +11:00
{
FILE *fp;
2019-01-31 05:14:40 +11:00
float loads[3];
2019-01-29 02:57:45 +11:00
int foo;
if ( ! (fp=fopen("/proc/loadavg", "r")) ) {
perror("read loadavg");
return -1;
}
2019-01-31 05:14:40 +11:00
foo = fscanf(fp, "%f %f %f", loads, loads+1, loads+2);
2019-01-29 02:57:45 +11:00
if (3 != foo) fprintf(stderr, "%s : read %d vals\n", __func__, foo);
2019-01-31 05:14:40 +11:00
memcpy(where, loads, 3 * sizeof(float));
2019-01-29 02:57:45 +11:00
fclose(fp);
return 0;
}
/* --------------------------------------------------------------- */