DD2-monitor/essai.c

66 lines
1.2 KiB
C
Raw Normal View History

2018-12-08 23:02:24 +11:00
/*
* essai.c
*/
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
2019-01-18 04:37:30 +11:00
#include <string.h>
2019-01-19 01:39:07 +11:00
#include <time.h>
2018-12-08 23:02:24 +11:00
2019-01-18 04:37:30 +11:00
#include "core/utils.h"
2018-12-08 23:02:24 +11:00
2019-01-18 04:37:30 +11:00
int verbosity;
/* --------------------------------------------------------------- */
int get_loadavg(double *where)
{
FILE *fp;
double loads[3];
int foo;
if ( ! (fp=fopen("/proc/loadavg", "r")) ) {
perror("read loadavg");
return -1;
}
foo = fscanf(fp, "%lf %lf %lf", loads, loads+1, loads+2);
if (3 != foo) fprintf(stderr, "%s : read %d vals\n", __func__, foo);
memcpy(where, loads, 3 * sizeof(double));
fclose(fp);
return 0;
}
2018-12-08 23:02:24 +11:00
/* --------------------------------------------------------------- */
int main(int argc, char *argv[])
{
int opt, foo;
double loads[3];
2019-01-19 01:39:07 +11:00
int il[3];
2018-12-08 23:02:24 +11:00
2019-01-18 04:37:30 +11:00
while ((opt = getopt(argc, argv, "v")) != -1) {
2018-12-08 23:02:24 +11:00
switch (opt) {
case 'v': verbosity++; break;
default: break;
}
}
foo = get_loadavg(loads);
if (foo) fprintf(stderr, "get loadavg -> %d\n", foo);
2019-01-19 01:39:07 +11:00
for (foo=0; foo<3; foo++) {
2019-01-19 03:56:27 +11:00
il[foo] = ((int)(loads[foo] * 90.0)) & 0x3ff;
2019-01-19 01:39:07 +11:00
fprintf(stderr, "%f -> %d\n", loads[foo], il[foo]);
}
2018-12-08 23:02:24 +11:00
2019-01-19 03:56:27 +11:00
printf("%ld %d %d %d %d\n", time(NULL), getpid()%84, il[0], il[1], il[2]);
2018-12-08 23:02:24 +11:00
return 0;
}
/* --------------------------------------------------------------- */