Monitoring du Phytotron
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

sysmetrics.c 675B

1234567891011121314151617181920212223242526272829303132333435363738
  1. /*
  2. * core/sysmetrics.c
  3. */
  4. #include <stdio.h>
  5. #include <unistd.h>
  6. #include <stdlib.h>
  7. #include <string.h>
  8. #include <time.h>
  9. #include "sysmetrics.h"
  10. extern int verbosity;
  11. /* --------------------------------------------------------------- */
  12. int get_loadavg(float *where)
  13. {
  14. FILE *fp;
  15. float loads[3];
  16. int foo;
  17. if ( ! (fp=fopen("/proc/loadavg", "r")) ) {
  18. perror("read loadavg");
  19. return -1;
  20. }
  21. foo = fscanf(fp, "%f %f %f", loads, loads+1, loads+2);
  22. if (3 != foo) fprintf(stderr, "%s : read %d vals\n", __func__, foo);
  23. memcpy(where, loads, 3 * sizeof(float));
  24. fclose(fp);
  25. return 0;
  26. }
  27. /* --------------------------------------------------------------- */