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.5
Committed: Fri May 17 13:56:20 2002 UTC (22 years, 6 months ago) by pajs
Content type: text/plain
Branch: MAIN
Changes since 1.4: +3 -0 lines
Log Message:
fixed a minor solaris forgoten include line ;)

File Contents

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