ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/libstatgrab/src/libstatgrab/load_stats.c
(Generate patch)

Comparing projects/libstatgrab/src/libstatgrab/load_stats.c (file contents):
Revision 1.9 by tdb, Mon Jan 19 16:49:21 2004 UTC vs.
Revision 1.15 by tdb, Wed Apr 7 21:08:40 2004 UTC

# Line 1 | Line 1
1   /*
2 < * i-scream central monitoring system
2 > * i-scream libstatgrab
3   * http://www.i-scream.org
4   * Copyright (C) 2000-2004 i-scream
5   *
# Line 29 | Line 29
29   #include <stdlib.h>
30   #include "statgrab.h"
31   #ifdef SOLARIS
32 + #ifdef HAVE_SYS_LOADAVG_H
33   #include <sys/loadavg.h>
34 + #else
35 + #include <kstat.h>
36   #endif
37 + #endif
38  
39 < load_stat_t *get_load_stats(){
39 > sg_load_stats *sg_get_load_stats(){
40  
41 <        static load_stat_t load_stat;
41 >        static sg_load_stats load_stat;
42  
43          double loadav[3];
44  
45   #ifdef CYGWIN
46 +        sg_set_error(SG_ERROR_UNSUPPORTED, "Cygwin");
47          return NULL;
48   #else
49  
50 + #if defined(SOLARIS) && !defined(HAVE_SYS_LOADAVG_H)
51 +
52 +        kstat_ctl_t *kc;        
53 +        kstat_t *ksp;
54 +        kstat_named_t *kn;
55 +
56 +        if ((kc = kstat_open()) == NULL) {
57 +                sg_set_error(SG_ERROR_KSTAT_OPEN, NULL);
58 +                return NULL;
59 +        }
60 +
61 +        if((ksp=kstat_lookup(kc, "unix", 0, "system_misc")) == NULL){
62 +                sg_set_error(SG_ERROR_KSTAT_LOOKUP, "unix,0,system_misc");
63 +                return NULL;
64 +        }
65 +
66 +        if (kstat_read(kc, ksp, 0) == -1) {
67 +                sg_set_error(SG_ERROR_KSTAT_READ, NULL);
68 +                return NULL;
69 +        }
70 +
71 +        if((kn=kstat_data_lookup(ksp, "avenrun_1min")) == NULL){
72 +                sg_set_error(SG_ERROR_KSTAT_DATA_LOOKUP, "avenrun_1min");
73 +                return NULL;
74 +        }
75 +        load_stat.min1 = (double)kn->value.ui32 / (double)256;
76 +
77 +        if((kn=kstat_data_lookup(ksp, "avenrun_5min")) == NULL){
78 +                sg_set_error(SG_ERROR_KSTAT_DATA_LOOKUP, "avenrun_5min");
79 +                return NULL;
80 +        }
81 +        load_stat.min5 = (double)kn->value.ui32 / (double)256;
82 +
83 +        if((kn=kstat_data_lookup(ksp, "avenrun_15min")) == NULL){
84 +                sg_set_error(SG_ERROR_KSTAT_DATA_LOOKUP, "avenrun_15min");
85 +                return NULL;
86 +        }
87 +        load_stat.min15 = (double)kn->value.ui32 / (double)256;
88 + #else
89          getloadavg(loadav,3);
90  
91          load_stat.min1=loadav[0];
92          load_stat.min5=loadav[1];
93          load_stat.min15=loadav[2];
94 + #endif
95  
96          return &load_stat;
97   #endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines