Merge branch 'master' of ssh://tetalab.org:2213/tTh/DD2-monitor

kr kr kr kr kr kr kr
This commit is contained in:
tth 2019-01-18 17:36:30 +01:00
commit c17b4a01fb
6 changed files with 42 additions and 68 deletions

1
.gitignore vendored
View File

@ -2,6 +2,7 @@ a.out
*.o *.o
fake-values fake-values
essai essai
foo.dat
serial/t serial/t
core/t core/t
core/*.a core/*.a

View File

@ -8,13 +8,12 @@ CCOPT = -Wall -g
all: essai fake-values all: essai fake-values
essai: essai.c funcs.o Makefile # ---------------------------------------------
gcc ${CCOPT} $< funcs.o -o $@
essai: essai.c Makefile
gcc ${CCOPT} $< core/utils.o -o $@
funcs.o: funcs.c funcs.h Makefile fake-values: fake-values.c Makefile
gcc ${CCOPT} -c $< gcc ${CCOPT} $< core/utils.o -o $@
fake-values: fake-values.c funcs.o Makefile
gcc ${CCOPT} $< funcs.o -o $@
# ---------------------------------------------

41
essai.c
View File

@ -5,32 +5,59 @@
#include <stdio.h> #include <stdio.h>
#include <unistd.h> #include <unistd.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
#include <time.h>
#include "funcs.h" #include "core/utils.h"
int verbosity; 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[]) int main(int argc, char *argv[])
{ {
int opt, foo; int opt, foo;
int type = 0;
double loads[3]; double loads[3];
int il[3];
while ((opt = getopt(argc, argv, "vst:")) != -1) { while ((opt = getopt(argc, argv, "v")) != -1) {
switch (opt) { switch (opt) {
case 'v': verbosity++; break; case 'v': verbosity++; break;
case 's': srand(getpid()); break;
case 't': type = atoi(optarg); break;
default: break; default: break;
} }
} }
foo = get_loadavg(loads); foo = get_loadavg(loads);
if (foo) fprintf(stderr, "get loadavg -> %d\n", foo); if (foo) fprintf(stderr, "get loadavg -> %d\n", foo);
for (foo=0; foo<3; foo++) {
il[foo] = ((int)(loads[foo] * 900.0)) & 0x3ff;
fprintf(stderr, "%f -> %d\n", loads[foo], il[foo]);
}
printf("%f %f %f %f\n", dtime(), loads[0], loads[1], loads[2]); printf("T %ld %d %d %d %d\n", time(NULL), getpid()%1024, il[0], il[1], il[2]);
return 0; return 0;
} }

View File

@ -6,7 +6,7 @@
#include <unistd.h> #include <unistd.h>
#include <stdlib.h> #include <stdlib.h>
#include "funcs.h" #include "core/utils.h"
int verbosity; int verbosity;

40
funcs.c
View File

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

13
funcs.h
View File

@ -1,13 +0,0 @@
/*
* funcs.c
*/
/* return an in random value in [0.999] */
int random1000(int mode);
/* get the 'timeofday' as a double float */
double dtime(void);
/* only usable on standard Linux ! */
int get_loadavg(double where[]);