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.9 by tdb, Sat May 18 18:15:57 2002 UTC

# Line 1 | Line 1
1 + /*
2 + * i-scream central monitoring system
3 + * Copyright (C) 2000-2002 i-scream
4 + *
5 + * This program is free software; you can redistribute it and/or
6 + * modify it under the terms of the GNU General Public License
7 + * as published by the Free Software Foundation; either version 2
8 + * of the License, or (at your option) any later version.
9 + *
10 + * This program is distributed in the hope that it will be useful,
11 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 + * GNU General Public License for more details.
14 + *
15 + * You should have received a copy of the GNU General Public License
16 + * along with this program; if not, write to the Free Software
17 + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18 + */
19 +
20   #include <stdio.h>
21   #include <sys/types.h>
22   #include <sys/statvfs.h>
# Line 9 | Line 28
28   #include <kstat.h>
29   #include <sys/sysinfo.h>
30   #include <unistd.h>
31 + #include <sys/stat.h>
32 + #include <sys/swap.h>
33 + #include <stdlib.h>
34 + #include <strings.h>
35 + #include <time.h>
36  
37   void die(){
38    exit(1);
# Line 29 | Line 53 | void diskStats(){
53    while((getmntent(f, &mp)) == 0){      
54      if ((statvfs(mp.mnt_mountp, &df)) !=0){
55        errf("Failed to gets fs stats (%m)");
56 <      die();
56 >      continue;
57      }
58 +
59 +    if((((strcmp(mp.mnt_fstype,"ufs"))==0) || (strcmp(mp.mnt_fstype,"tmpfs")) ==0)){
60          
61 <    printf("packet.disk.p%d.attributes.mount %s\n", counter, mp.mnt_mountp);
62 <    printf("packet.disk.p%d.attributes.name %s\n", counter, mp.mnt_special);
63 <    printf("packet.disk.p%d.attributes.kbytes %lu\n",counter, ((df.f_frsize/1024) * df.f_blocks));
64 <    printf("packet.disk.p%d.attributes.used %lu\n",counter, (((df.f_frsize/1024) * df.f_blocks) -((df.f_frsize/1024) * df.f_bfree)));
65 <    printf("packet.disk.p%d.attributes.avail %lu\n",counter, (df.f_frsize/1024) * df.f_bavail);
66 <    printf("packet.disk.p%d.attributes.totalinodes %lu\n", counter, df.f_files);
67 <    printf("packet.disk.p%d.attributes.freeinodes %lu\n",counter, df.f_ffree);
61 >      printf("packet.disk.p%d.attributes.mount %s\n", counter, mp.mnt_mountp);
62 >      printf("packet.disk.p%d.attributes.name %s\n", counter, mp.mnt_special);
63 >      printf("packet.disk.p%d.attributes.kbytes %lu\n",counter, ((df.f_frsize/1024) * df.f_blocks));
64 >      printf("packet.disk.p%d.attributes.used %lu\n",counter, (((df.f_frsize/1024) * df.f_blocks) -((df.f_frsize/1024) * df.f_bfree)));
65 >      printf("packet.disk.p%d.attributes.avail %lu\n",counter, (df.f_frsize/1024) * df.f_bavail);
66 >      printf("packet.disk.p%d.attributes.totalinodes %lu\n", counter, df.f_files);
67 >      printf("packet.disk.p%d.attributes.freeinodes %lu\n",counter, df.f_ffree);
68      
69 <    counter++;
69 >      counter++;
70 >    }
71    }
72   }
73  
# Line 92 | Line 119 | void userStats(){
119   void systemStats(){
120    kstat_ctl_t *kc;
121    kstat_t *ksp;
122 <  kstat_named_t *knp;
122 >  kstat_named_t *kn;
123 >  int pagesize;
124    cpu_stat_t cs;
125 <  uint_t cpustats[4][2];
125 >  uint_t cpustats[5][2];
126    float usage;
127 <  uint_t user, kernel, idle, iowait, total;
127 >  uint_t user, kernel, idle, iowait, swap, total;
128 >  ulong totalmem, freemem;
129 >  long swaptotal, swapused;
130 >  time_t uptime,curtime;
131 >  
132 >  struct anoninfo ai;
133  
134 +
135    if ((kc = kstat_open()) == NULL) {
136      errf("kstat_open failure (%m)");
137      die();
# Line 118 | Line 152 | void systemStats(){
152    cpustats[1][0]=cs.cpu_sysinfo.cpu[CPU_WAIT];
153    cpustats[2][0]=cs.cpu_sysinfo.cpu[CPU_KERNEL];
154    cpustats[3][0]=cs.cpu_sysinfo.cpu[CPU_IDLE];
155 +  cpustats[4][0]=cs.cpu_sysinfo.cpu[CPU_STATES];
156    
157    sleep(1);
158    
# Line 139 | Line 174 | void systemStats(){
174    cpustats[1][1]=cs.cpu_sysinfo.cpu[CPU_WAIT];
175    cpustats[2][1]=cs.cpu_sysinfo.cpu[CPU_KERNEL];
176    cpustats[3][1]=cs.cpu_sysinfo.cpu[CPU_IDLE];
177 +  cpustats[4][1]=cs.cpu_sysinfo.cpu[CPU_STATES];
178  
179    user=cpustats[0][1]-cpustats[0][0];
180    iowait=cpustats[1][1]-cpustats[1][0];
181    kernel=cpustats[2][1]-cpustats[2][0];
182    idle=cpustats[3][1]-cpustats[3][0];
183 +  swap=cpustats[4][1]-cpustats[4][0];
184  
185 <  total=user+kernel+idle+iowait;
185 >  total=user+kernel+idle+iowait+swap;
186    
187    usage=((((float)user)/((float)total))*100.00);
188  
152  printf("user : %u\n",user);
153  printf("total : %u\n",total);
154
189    printf("packet.cpu.user %3.2f\n", usage);
190    usage=((((float)kernel)/((float)total))*100.00);
191    printf("packet.cpu.kernel %3.2f\n", usage);
# Line 159 | Line 193 | void systemStats(){
193    printf("packet.cpu.idle %3.2f\n", usage);
194    usage=((((float)iowait)/((float)total))*100.00);
195    printf("packet.cpu.iowait %3.2f\n", usage);
196 +  usage=((((float)swap)/((float)total))*100.00);
197 +  printf("packet.cpu.swap %3.2f\n", usage);
198 +  
199 +  /* MEMORY STATS */
200 +  
201 +  if((pagesize=sysconf(_SC_PAGESIZE)) == -1){
202 +    errf("Failed to get pagesize (%m)");
203 +    die();
204 +  }
205  
206 <  /* if((ksp = kstat_lookup(kc, "unix", -1, "system_pages")) == NULL){
207 <    errf("Mem lookup failed (%m)");
206 >  if((totalmem=sysconf(_SC_PHYS_PAGES)) == -1){
207 >    errf("Failed to get total memory");
208      die();
209    }
210 +  
211 +  totalmem=((totalmem*pagesize)/1024)/1024;
212 +  
213 +  ksp = kstat_lookup(kc, "unix", 0, "system_pages");
214 +  if (kstat_read(kc, ksp, 0) == -1) {
215 +    perror("kstat_read");
216 +    die();
217 +  }  
218  
219 <  if((knp = (kstat_named_t *)kstat_data_lookup(ksp, "pagesfree")) == NULL){
220 <    errf("Mem lookup failed (%m)");
219 >  if((kn=kstat_data_lookup(ksp, "freemem")) == NULL){
220 >    errf("Failed to get free memory (%m)");
221      die();
222    }
223    
224 <  printf("%ui32\n",  knp->value.ui32);
225 <  */
226 < }
227 <    
224 >  freemem=(((kn->value.ul)*pagesize)/1024)/1024;
225 >
226 >  printf("packet.memory.total %lu\n",totalmem);
227 >  printf("packet.memory.free %lu\n",freemem);
228 >  printf("packet.memory.used %lu\n",(totalmem-freemem));
229 >
230 >
231 >  if (swapctl(SC_AINFO, &ai) == -1) {
232 >    errf("Failed to get swap details (%m)");
233 >    die();
234 >  }
235 >
236 >  swaptotal=((ai.ani_max/1024)*pagesize)/1024;
237 >  swapused=((ai.ani_resv/1024)*pagesize)/1024;
238 >
239 >  /* Ok this is actually for TOP combatability, but this is not
240 >     total swap, cos it actually also seems to include memory stats. */
241 >  printf("packet.swap.total %ld\n",swaptotal);
242 >  printf("packet.swap.used %ld\n", swapused);
243 >  printf("packet.swap.free %lu\n", (swaptotal-swapused));
244 >
245 >  ksp=kstat_lookup(kc, "unix", -1, "system_misc");
246 >  if (kstat_read(kc, ksp, 0) == -1) {
247 >    errf("Failed to get uptime (%m)");
248 >    die();
249 >  }
250 >
251 >  if((kn=kstat_data_lookup(ksp, "boot_time")) == NULL){
252 >    errf("Failed to get uptime (%m)");
253 >    die();
254 >  }
255 >
256 >  uptime=(kn->value.ui32);
257 >  time(&curtime);
258 >  printf("packet.os.uptime %ld\n", (curtime-uptime));
259 >
260 > }    
261    
262 + void processStats() {
263 +    int sleeping=-1;
264 +    int zombie=0;
265 +    int stopped=0;
266 +    int running=0;
267 +    char *line;
268 +    char *line_p;
269  
270 +
271 +    FILE *f;
272 +
273 +    if((f=popen("/bin/ps -Al" , "r")) == NULL) {
274 +        errf("Failed to get process stats (%m)");
275 +        die();
276 +    }
277 +
278 +    while((line=fpgetline(f)) != NULL) {
279 +      line_p=line;
280 +      for(; (*line_p == ' ') && (*line_p != '\0'); line_p++);
281 +      line_p=strchr(line_p, ' ');
282 +      for(; (*line_p == ' ') && (*line_p != '\0'); line_p++);
283 +      if (line_p==NULL) abort();
284 +      /* Ok, we should now be at the state :) .. */
285 +      if (*line_p=='S') sleeping++;
286 +      if (*line_p=='R') running++;
287 +      if (*line_p=='Z') zombie++;
288 +      if (*line_p=='T') stopped++;
289 +    }
290 +
291 +    if((pclose(f)) == -1) {
292 +        errf("Failed to close process stats (%m)");
293 +        die();
294 +    }
295 +
296 +    printf("packet.processes.sleeping %d\n",sleeping);
297 +    printf("packet.processes.cpu %d\n",running);
298 +    printf("packet.processes.zombie %d\n",zombie);
299 +    printf("packet.processes.stopped %d\n", stopped);
300 +    printf("packet.processes.total %d\n", (sleeping+running+zombie+stopped));
301 +
302 + }
303 +
304 +
305   int main(){
306    diskStats();
307    osStats();
308    loadStats();
309    userStats();
310    systemStats();
311 <
311 >  processStats();
312    return 0;
313   }
314  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines