ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/host/ihost-perl/plugins/solaris/solaris.c
(Generate patch)

Comparing projects/cms/source/host/ihost-perl/plugins/solaris/solaris.c (file contents):
Revision 1.4 by pajs, Thu Mar 14 17:05:53 2002 UTC vs.
Revision 1.8 by pajs, Tue Mar 19 14:55:42 2002 UTC

# Line 9 | Line 9
9   #include <kstat.h>
10   #include <sys/sysinfo.h>
11   #include <unistd.h>
12 + #include <sys/stat.h>
13 + #include <sys/swap.h>
14 + #include <stdlib.h>
15 + #include <strings.h>
16 + #include <time.h>
17  
18   void die(){
19    exit(1);
# Line 29 | Line 34 | void diskStats(){
34    while((getmntent(f, &mp)) == 0){      
35      if ((statvfs(mp.mnt_mountp, &df)) !=0){
36        errf("Failed to gets fs stats (%m)");
37 <      die();
37 >      continue;
38      }
39 +
40 +    if((((strcmp(mp.mnt_fstype,"ufs"))==0) || (strcmp(mp.mnt_fstype,"tmpfs")) ==0)){
41          
42 <    printf("packet.disk.p%d.attributes.mount %s\n", counter, mp.mnt_mountp);
43 <    printf("packet.disk.p%d.attributes.name %s\n", counter, mp.mnt_special);
44 <    printf("packet.disk.p%d.attributes.kbytes %lu\n",counter, ((df.f_frsize/1024) * df.f_blocks));
45 <    printf("packet.disk.p%d.attributes.used %lu\n",counter, (((df.f_frsize/1024) * df.f_blocks) -((df.f_frsize/1024) * df.f_bfree)));
46 <    printf("packet.disk.p%d.attributes.avail %lu\n",counter, (df.f_frsize/1024) * df.f_bavail);
47 <    printf("packet.disk.p%d.attributes.totalinodes %lu\n", counter, df.f_files);
48 <    printf("packet.disk.p%d.attributes.freeinodes %lu\n",counter, df.f_ffree);
42 >      printf("packet.disk.p%d.attributes.mount %s\n", counter, mp.mnt_mountp);
43 >      printf("packet.disk.p%d.attributes.name %s\n", counter, mp.mnt_special);
44 >      printf("packet.disk.p%d.attributes.kbytes %lu\n",counter, ((df.f_frsize/1024) * df.f_blocks));
45 >      printf("packet.disk.p%d.attributes.used %lu\n",counter, (((df.f_frsize/1024) * df.f_blocks) -((df.f_frsize/1024) * df.f_bfree)));
46 >      printf("packet.disk.p%d.attributes.avail %lu\n",counter, (df.f_frsize/1024) * df.f_bavail);
47 >      printf("packet.disk.p%d.attributes.totalinodes %lu\n", counter, df.f_files);
48 >      printf("packet.disk.p%d.attributes.freeinodes %lu\n",counter, df.f_ffree);
49      
50 <    counter++;
50 >      counter++;
51 >    }
52    }
53   }
54  
# Line 92 | Line 100 | void userStats(){
100   void systemStats(){
101    kstat_ctl_t *kc;
102    kstat_t *ksp;
103 <  kstat_named_t *knp;
103 >  kstat_named_t *kn;
104 >  int pagesize;
105    cpu_stat_t cs;
106 <  uint_t cpustats[4][2];
106 >  uint_t cpustats[5][2];
107    float usage;
108 <  uint_t user, kernel, idle, iowait, total;
108 >  uint_t user, kernel, idle, iowait, swap, total;
109 >  ulong totalmem, freemem;
110 >  long swaptotal, swapused;
111 >  time_t uptime,curtime;
112 >  
113 >  struct anoninfo ai;
114  
115 +
116    if ((kc = kstat_open()) == NULL) {
117      errf("kstat_open failure (%m)");
118      die();
# Line 118 | Line 133 | void systemStats(){
133    cpustats[1][0]=cs.cpu_sysinfo.cpu[CPU_WAIT];
134    cpustats[2][0]=cs.cpu_sysinfo.cpu[CPU_KERNEL];
135    cpustats[3][0]=cs.cpu_sysinfo.cpu[CPU_IDLE];
136 +  cpustats[4][0]=cs.cpu_sysinfo.cpu[CPU_STATES];
137    
138    sleep(1);
139    
# Line 139 | Line 155 | void systemStats(){
155    cpustats[1][1]=cs.cpu_sysinfo.cpu[CPU_WAIT];
156    cpustats[2][1]=cs.cpu_sysinfo.cpu[CPU_KERNEL];
157    cpustats[3][1]=cs.cpu_sysinfo.cpu[CPU_IDLE];
158 +  cpustats[4][1]=cs.cpu_sysinfo.cpu[CPU_STATES];
159  
160    user=cpustats[0][1]-cpustats[0][0];
161    iowait=cpustats[1][1]-cpustats[1][0];
162    kernel=cpustats[2][1]-cpustats[2][0];
163    idle=cpustats[3][1]-cpustats[3][0];
164 +  swap=cpustats[4][1]-cpustats[4][0];
165  
166 <  total=user+kernel+idle+iowait;
166 >  total=user+kernel+idle+iowait+swap;
167    
168    usage=((((float)user)/((float)total))*100.00);
169  
152  printf("user : %u\n",user);
153  printf("total : %u\n",total);
154
170    printf("packet.cpu.user %3.2f\n", usage);
171    usage=((((float)kernel)/((float)total))*100.00);
172    printf("packet.cpu.kernel %3.2f\n", usage);
# Line 159 | Line 174 | void systemStats(){
174    printf("packet.cpu.idle %3.2f\n", usage);
175    usage=((((float)iowait)/((float)total))*100.00);
176    printf("packet.cpu.iowait %3.2f\n", usage);
177 +  usage=((((float)swap)/((float)total))*100.00);
178 +  printf("packet.cpu.swap %3.2f\n", usage);
179 +  
180 +  /* MEMORY STATS */
181 +  
182 +  if((pagesize=sysconf(_SC_PAGESIZE)) == -1){
183 +    errf("Failed to get pagesize (%m)");
184 +    die();
185 +  }
186  
187 <  /* if((ksp = kstat_lookup(kc, "unix", -1, "system_pages")) == NULL){
188 <    errf("Mem lookup failed (%m)");
187 >  if((totalmem=sysconf(_SC_PHYS_PAGES)) == -1){
188 >    errf("Failed to get total memory");
189      die();
190    }
191 +  
192 +  totalmem=((totalmem*pagesize)/1024)/1024;
193 +  
194 +  ksp = kstat_lookup(kc, "unix", 0, "system_pages");
195 +  if (kstat_read(kc, ksp, 0) == -1) {
196 +    perror("kstat_read");
197 +    die();
198 +  }  
199  
200 <  if((knp = (kstat_named_t *)kstat_data_lookup(ksp, "pagesfree")) == NULL){
201 <    errf("Mem lookup failed (%m)");
200 >  if((kn=kstat_data_lookup(ksp, "freemem")) == NULL){
201 >    errf("Failed to get free memory (%m)");
202      die();
203    }
204    
205 <  printf("%ui32\n",  knp->value.ui32);
206 <  */
207 < }
208 <    
205 >  freemem=(((kn->value.ul)*pagesize)/1024)/1024;
206 >
207 >  printf("packet.memory.total %lu\n",totalmem);
208 >  printf("packet.memory.free %lu\n",freemem);
209 >  printf("packet.memory.used %lu\n",(totalmem-freemem));
210 >
211 >
212 >  if (swapctl(SC_AINFO, &ai) == -1) {
213 >    errf("Failed to get swap details (%m)");
214 >    die();
215 >  }
216 >
217 >  swaptotal=((ai.ani_max/1024)*pagesize)/1024;
218 >  swapused=((ai.ani_resv/1024)*pagesize)/1024;
219 >
220 >  /* Ok this is actually for TOP combatability, but this is not
221 >     total swap, cos it actually also seems to include memory stats. */
222 >  printf("packet.swap.total %ld\n",swaptotal);
223 >  printf("packet.swap.used %ld\n", swapused);
224 >  printf("packet.swap.free %lu\n", (swaptotal-swapused));
225 >
226 >  ksp=kstat_lookup(kc, "unix", -1, "system_misc");
227 >  if (kstat_read(kc, ksp, 0) == -1) {
228 >    errf("Failed to get uptime (%m)");
229 >    die();
230 >  }
231 >
232 >  if((kn=kstat_data_lookup(ksp, "boot_time")) == NULL){
233 >    errf("Failed to get uptime (%m)");
234 >    die();
235 >  }
236 >
237 >  uptime=(kn->value.ui32);
238 >  time(&curtime);
239 >  printf("packet.os.uptime %ld\n", (curtime-uptime));
240 >
241 > }    
242    
243 + void processStats() {
244 +    int sleeping=-1;
245 +    int zombie=0;
246 +    int stopped=0;
247 +    int running=0;
248 +    char *line;
249 +    char *line_p;
250  
251 +
252 +    FILE *f;
253 +
254 +    if((f=popen("/bin/ps -Al" , "r")) == NULL) {
255 +        errf("Failed to get process stats (%m)");
256 +        die();
257 +    }
258 +
259 +    while((line=fpgetline(f)) != NULL) {
260 +      line_p=line;
261 +      for(; (*line_p == ' ') && (*line_p != '\0'); line_p++);
262 +      line_p=strchr(line_p, ' ');
263 +      for(; (*line_p == ' ') && (*line_p != '\0'); line_p++);
264 +      if (line_p==NULL) abort();
265 +      /* Ok, we should now be at the state :) .. */
266 +      if (*line_p=='S') sleeping++;
267 +      if (*line_p=='R') running++;
268 +      if (*line_p=='Z') zombie++;
269 +      if (*line_p=='T') stopped++;
270 +    }
271 +
272 +    if((pclose(f)) == -1) {
273 +        errf("Failed to close process stats (%m)");
274 +        die();
275 +    }
276 +
277 +    printf("packet.processes.sleeping %d\n",sleeping);
278 +    printf("packet.processes.cpu %d\n",running);
279 +    printf("packet.processes.zombie %d\n",zombie);
280 +    printf("packet.processes.stopped %d\n", stopped);
281 +    printf("packet.processes.total %d\n", (sleeping+running+zombie+stopped));
282 +
283 + }
284 +
285 +
286   int main(){
287    diskStats();
288    osStats();
289    loadStats();
290    userStats();
291    systemStats();
292 <
292 >  processStats();
293    return 0;
294   }
295  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines