| 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 "ukcprog.h" |
| 23 |
|
#include <sys/param.h> |
| 134 |
|
long cp_time[CPUSTATES]; |
| 135 |
|
long total, user, idle, kernel, nice; |
| 136 |
|
long totalmem, freemem, swaptotal, swapused; |
| 137 |
+ |
float stat; |
| 138 |
|
|
| 139 |
|
static char *uptimename = "kern.boottime"; |
| 140 |
|
static char *cpname = "kern.cp_time"; |
| 192 |
|
die(); |
| 193 |
|
} |
| 194 |
|
|
| 195 |
< |
user-=cp_time[CP_USER]; |
| 196 |
< |
nice-=cp_time[CP_NICE]; |
| 197 |
< |
kernel-=cp_time[CP_SYS]; |
| 198 |
< |
idle-=cp_time[CP_IDLE]; |
| 195 |
> |
user=cp_time[CP_USER]-user; |
| 196 |
> |
nice=cp_time[CP_NICE]-nice; |
| 197 |
> |
kernel=cp_time[CP_SYS]-kernel; |
| 198 |
> |
idle=cp_time[CP_IDLE]-idle; |
| 199 |
|
|
| 200 |
|
total=user+nice+kernel+idle; |
| 201 |
< |
|
| 202 |
< |
printf("packet.cpu.user %ld\n",((user+nice)*100)/total); |
| 203 |
< |
printf("packet.cpu.kernel %ld\n",(kernel*100)/total); |
| 204 |
< |
printf("packet.cpu.idle %ld\n",(idle*100)/total); |
| 201 |
> |
stat=((float)(user+nice)/(float)total)*100.0; |
| 202 |
> |
printf("packet.cpu.user %.2f\n",stat); |
| 203 |
> |
stat=((float)(kernel)/(float)total)*100.0; |
| 204 |
> |
printf("packet.cpu.kernel %.2f\n",stat); |
| 205 |
> |
stat=((float)(idle)/(float)total)*100.0; |
| 206 |
> |
printf("packet.cpu.idle %.2f\n",stat); |
| 207 |
|
|
| 208 |
|
/* Cos i-scream's expects this to be sent :/ */ |
| 209 |
|
printf("packet.cpu.iowait 0\n"); |
| 260 |
|
die(); |
| 261 |
|
} |
| 262 |
|
|
| 263 |
< |
/* Lose are setgid'ness */ |
| 263 |
> |
/* Lose our setgid'ness */ |
| 264 |
|
|
| 265 |
|
if ((setegid(gid)) != 0){ |
| 266 |
|
errf("Failed to release permissions, refusing to keep setgid. (%m)"); |