adding core/sysmetrics.[ch]

This commit is contained in:
tth 2019-01-28 16:57:45 +01:00
parent 80b00561af
commit 65e9d58486
5 changed files with 70 additions and 29 deletions

View File

@ -6,7 +6,7 @@
COPT = -Wall -fpic -g -DDEBUG_LEVEL=0
OBJS = lut1024f.o parseconf.o utils.o
OBJS = lut1024f.o parseconf.o utils.o sysmetrics.o
DEPS = Makefile
ALIB = libdd2m-core.a
# ---------------------------------------------------
@ -15,13 +15,16 @@ ${ALIB}: ${OBJS}
ar r $@ $?
lut1024f.o: lut1024f.c lut1024.h ${DEPS}
gcc -Wall -c $<
gcc $(COPT) -c $<
parseconf.o: parseconf.c config.h ${DEPS}
gcc -Wall -c $<
gcc $(COPT) -c $<
utils.o: utils.c utils.h ${DEPS}
gcc -Wall -c $<
gcc $(COPT) -c $<
sysmetrics.o: sysmetrics.c ${DEPS}
gcc $(COPT) -c $<
# ---------------------------------------------------

38
core/sysmetrics.c Normal file
View File

@ -0,0 +1,38 @@
/*
* core/sysmetrics.c
*/
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "sysmetrics.h"
extern 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;
}
/* --------------------------------------------------------------- */

4
core/sysmetrics.h Normal file
View File

@ -0,0 +1,4 @@
int get_loadavg(double *where);

View File

@ -8,12 +8,29 @@
#include "lut1024.h"
#include "config.h"
#include "sysmetrics.h"
int verbosity;
Configuration config;
/* ---------------------------------------------------------------- */
int essai_sysmetrics(int k)
{
double dvalues3[3];
int foo;
foo = get_loadavg(dvalues3);
if (foo) {
fprintf(stderr, "err get load avg %d\n", foo);
return -1;
}
printf("load avg %f %f %f\n", dvalues3[0], dvalues3[1], dvalues3[2]);
return 0;
}
/* ---------------------------------------------------------------- */
int main (int argc, char *argv[])
@ -21,14 +38,12 @@ int main (int argc, char *argv[])
int foo, opt;
char *conffile = "dd2-monitor.conf";
fprintf(stderr, "+\n+ DD2 MONITOR\n+\n");
/* set some default values */
verbosity = 0;
while ((opt = getopt(argc, argv, "v")) != -1) {
switch (opt) {
case 'v': verbosity++; break;
@ -46,6 +61,7 @@ foo = parse_config(conffile, 0);
fprintf(stderr, "parse_config(%s) -> %d\n\n", conffile, foo);
show_config("foo");
essai_sysmetrics(0);
/*
foo = load_lut1024f("foo.lut1024f", NULL, 1);
fprintf(stderr, "chargement de la lut --> %d\n\n", foo);

26
essai.c
View File

@ -9,32 +9,11 @@
#include <time.h>
#include "core/utils.h"
#include "core/sysmetrics.h"
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;
}
/* --------------------------------------------------------------- */
int main(int argc, char *argv[])
@ -54,7 +33,8 @@ foo = get_loadavg(loads);
if (foo) fprintf(stderr, "get loadavg -> %d\n", foo);
for (foo=0; foo<3; foo++) {
il[foo] = ((int)(loads[foo] * 90.0)) & 0x3ff;
fprintf(stderr, "%f -> %d\n", loads[foo], il[foo]);
if (verbosity)
fprintf(stderr, "%f -> %d\n", loads[foo], il[foo]);
}
printf("%ld %d %d %d %d\n", time(NULL), getpid()%84, il[0], il[1], il[2]);