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.5 by pajs, Mon Mar 18 13:46:12 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 13 | Line 32
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 33 | 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 99 | Line 122 | void systemStats(){
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  
# Line 128 | 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 149 | 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  
162  printf("user : %u\n",user);
163  printf("total : %u\n",total);
164
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 169 | 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 <
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){
# Line 215 | Line 241 | void systemStats(){
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    

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines