ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/ihost/libstatgrab/load_stat.c
Revision: 1.1
Committed: Sun May 12 19:10:55 2002 UTC (22 years, 6 months ago) by pajs
Content type: text/plain
Branch: MAIN
Log Message:
Gets system load averages.

File Contents

# Content
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include "ukcprog.h"
4
5 char* get_load_stats(){
6
7 double loadav[3];
8 char *xml_load_out;
9 #ifdef OLDLINUX
10 FILE *f;
11 char *loadavg;
12 char *load_p;
13 #endif
14
15 #ifdef OLDLINUX
16 if ((f=fopen("/proc/loadavg", "r" ))==NULL) {
17 errf("Failed to open load averages (%m)");
18 return NULL;
19 }
20
21 fscanf(f,"%lf %lf %lf", &loadav[0], &loadav[1], &loadav[2]);
22
23 if ((fclose(f)) != 0) {
24 errf("Failed to close file (%m).");
25 return NULL;
26 }
27 #else
28 if((getloadavg(loadav,3)) == -1){
29 errf("Failed to get load averages (%m)");
30 }
31 #endif
32
33 xml_load_out=strf("<load><load1>%.2lf</load1><load5>%.2lf</load5><loag15>%.2lf</load15></load>\n", loadav[0], loadav[1], loadav[2]);
34
35 return xml_load_out;
36 }