| 1 |
+ |
/* |
| 2 |
+ |
* i-scream central monitoring system |
| 3 |
+ |
* http://www.i-scream.org.uk |
| 4 |
+ |
* Copyright (C) 2000-2002 i-scream |
| 5 |
+ |
* |
| 6 |
+ |
* This program is free software; you can redistribute it and/or |
| 7 |
+ |
* modify it under the terms of the GNU General Public License |
| 8 |
+ |
* as published by the Free Software Foundation; either version 2 |
| 9 |
+ |
* of the License, or (at your option) any later version. |
| 10 |
+ |
* |
| 11 |
+ |
* This program is distributed in the hope that it will be useful, |
| 12 |
+ |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
+ |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
+ |
* GNU General Public License for more details. |
| 15 |
+ |
* |
| 16 |
+ |
* You should have received a copy of the GNU General Public License |
| 17 |
+ |
* along with this program; if not, write to the Free Software |
| 18 |
+ |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 19 |
+ |
*/ |
| 20 |
+ |
|
| 21 |
|
#include <stdio.h> |
| 22 |
|
#include <sys/types.h> |
| 23 |
|
#include <sys/statvfs.h> |
| 33 |
|
#include <sys/swap.h> |
| 34 |
|
#include <stdlib.h> |
| 35 |
|
#include <strings.h> |
| 36 |
+ |
#include <time.h> |
| 37 |
|
|
| 38 |
|
void die(){ |
| 39 |
|
exit(1); |
| 54 |
|
while((getmntent(f, &mp)) == 0){ |
| 55 |
|
if ((statvfs(mp.mnt_mountp, &df)) !=0){ |
| 56 |
|
errf("Failed to gets fs stats (%m)"); |
| 57 |
< |
die(); |
| 57 |
> |
continue; |
| 58 |
|
} |
| 59 |
+ |
|
| 60 |
+ |
if((((strcmp(mp.mnt_fstype,"ufs"))==0) || (strcmp(mp.mnt_fstype,"tmpfs")) ==0)){ |
| 61 |
|
|
| 62 |
< |
printf("packet.disk.p%d.attributes.mount %s\n", counter, mp.mnt_mountp); |
| 63 |
< |
printf("packet.disk.p%d.attributes.name %s\n", counter, mp.mnt_special); |
| 64 |
< |
printf("packet.disk.p%d.attributes.kbytes %lu\n",counter, ((df.f_frsize/1024) * df.f_blocks)); |
| 65 |
< |
printf("packet.disk.p%d.attributes.used %lu\n",counter, (((df.f_frsize/1024) * df.f_blocks) -((df.f_frsize/1024) * df.f_bfree))); |
| 66 |
< |
printf("packet.disk.p%d.attributes.avail %lu\n",counter, (df.f_frsize/1024) * df.f_bavail); |
| 67 |
< |
printf("packet.disk.p%d.attributes.totalinodes %lu\n", counter, df.f_files); |
| 68 |
< |
printf("packet.disk.p%d.attributes.freeinodes %lu\n",counter, df.f_ffree); |
| 62 |
> |
printf("packet.disk.p%d.attributes.mount %s\n", counter, mp.mnt_mountp); |
| 63 |
> |
printf("packet.disk.p%d.attributes.name %s\n", counter, mp.mnt_special); |
| 64 |
> |
printf("packet.disk.p%d.attributes.kbytes %lu\n",counter, ((df.f_frsize/1024) * df.f_blocks)); |
| 65 |
> |
printf("packet.disk.p%d.attributes.used %lu\n",counter, (((df.f_frsize/1024) * df.f_blocks) -((df.f_frsize/1024) * df.f_bfree))); |
| 66 |
> |
printf("packet.disk.p%d.attributes.avail %lu\n",counter, (df.f_frsize/1024) * df.f_bavail); |
| 67 |
> |
printf("packet.disk.p%d.attributes.totalinodes %lu\n", counter, df.f_files); |
| 68 |
> |
printf("packet.disk.p%d.attributes.freeinodes %lu\n",counter, df.f_ffree); |
| 69 |
|
|
| 70 |
< |
counter++; |
| 70 |
> |
counter++; |
| 71 |
> |
} |
| 72 |
|
} |
| 73 |
|
} |
| 74 |
|
|
| 123 |
|
kstat_named_t *kn; |
| 124 |
|
int pagesize; |
| 125 |
|
cpu_stat_t cs; |
| 126 |
< |
uint_t cpustats[4][2]; |
| 126 |
> |
uint_t cpustats[5][2]; |
| 127 |
|
float usage; |
| 128 |
< |
uint_t user, kernel, idle, iowait, total; |
| 128 |
> |
uint_t user, kernel, idle, iowait, swap, total; |
| 129 |
|
ulong totalmem, freemem; |
| 130 |
|
long swaptotal, swapused; |
| 131 |
+ |
time_t uptime,curtime; |
| 132 |
|
|
| 133 |
|
struct anoninfo ai; |
| 134 |
|
|
| 153 |
|
cpustats[1][0]=cs.cpu_sysinfo.cpu[CPU_WAIT]; |
| 154 |
|
cpustats[2][0]=cs.cpu_sysinfo.cpu[CPU_KERNEL]; |
| 155 |
|
cpustats[3][0]=cs.cpu_sysinfo.cpu[CPU_IDLE]; |
| 156 |
+ |
cpustats[4][0]=cs.cpu_sysinfo.cpu[CPU_STATES]; |
| 157 |
|
|
| 158 |
|
sleep(1); |
| 159 |
|
|
| 175 |
|
cpustats[1][1]=cs.cpu_sysinfo.cpu[CPU_WAIT]; |
| 176 |
|
cpustats[2][1]=cs.cpu_sysinfo.cpu[CPU_KERNEL]; |
| 177 |
|
cpustats[3][1]=cs.cpu_sysinfo.cpu[CPU_IDLE]; |
| 178 |
+ |
cpustats[4][1]=cs.cpu_sysinfo.cpu[CPU_STATES]; |
| 179 |
|
|
| 180 |
|
user=cpustats[0][1]-cpustats[0][0]; |
| 181 |
|
iowait=cpustats[1][1]-cpustats[1][0]; |
| 182 |
|
kernel=cpustats[2][1]-cpustats[2][0]; |
| 183 |
|
idle=cpustats[3][1]-cpustats[3][0]; |
| 184 |
+ |
swap=cpustats[4][1]-cpustats[4][0]; |
| 185 |
|
|
| 186 |
< |
total=user+kernel+idle+iowait; |
| 186 |
> |
total=user+kernel+idle+iowait+swap; |
| 187 |
|
|
| 188 |
|
usage=((((float)user)/((float)total))*100.00); |
| 189 |
|
|
| 162 |
– |
printf("user : %u\n",user); |
| 163 |
– |
printf("total : %u\n",total); |
| 164 |
– |
|
| 190 |
|
printf("packet.cpu.user %3.2f\n", usage); |
| 191 |
|
usage=((((float)kernel)/((float)total))*100.00); |
| 192 |
|
printf("packet.cpu.kernel %3.2f\n", usage); |
| 194 |
|
printf("packet.cpu.idle %3.2f\n", usage); |
| 195 |
|
usage=((((float)iowait)/((float)total))*100.00); |
| 196 |
|
printf("packet.cpu.iowait %3.2f\n", usage); |
| 197 |
< |
|
| 197 |
> |
usage=((((float)swap)/((float)total))*100.00); |
| 198 |
> |
printf("packet.cpu.swap %3.2f\n", usage); |
| 199 |
> |
|
| 200 |
|
/* MEMORY STATS */ |
| 201 |
|
|
| 202 |
|
if((pagesize=sysconf(_SC_PAGESIZE)) == -1){ |
| 242 |
|
printf("packet.swap.total %ld\n",swaptotal); |
| 243 |
|
printf("packet.swap.used %ld\n", swapused); |
| 244 |
|
printf("packet.swap.free %lu\n", (swaptotal-swapused)); |
| 245 |
+ |
|
| 246 |
+ |
ksp=kstat_lookup(kc, "unix", -1, "system_misc"); |
| 247 |
+ |
if (kstat_read(kc, ksp, 0) == -1) { |
| 248 |
+ |
errf("Failed to get uptime (%m)"); |
| 249 |
+ |
die(); |
| 250 |
+ |
} |
| 251 |
+ |
|
| 252 |
+ |
if((kn=kstat_data_lookup(ksp, "boot_time")) == NULL){ |
| 253 |
+ |
errf("Failed to get uptime (%m)"); |
| 254 |
+ |
die(); |
| 255 |
+ |
} |
| 256 |
+ |
|
| 257 |
+ |
uptime=(kn->value.ui32); |
| 258 |
+ |
time(&curtime); |
| 259 |
+ |
printf("packet.os.uptime %ld\n", (curtime-uptime)); |
| 260 |
|
|
| 261 |
|
} |
| 262 |
|
|