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

Comparing projects/cms/source/host/ihost-perl/plugins/freebsd/freebsd.c (file contents):
Revision 1.6 by pajs, Thu Mar 28 18:16:21 2002 UTC vs.
Revision 1.10 by tdb, Tue May 21 16:47:12 2002 UTC

# Line 1 | Line 1
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>
# Line 14 | Line 34
34   #include <sys/sysctl.h>
35   #include <fcntl.h>
36   #include <limits.h>
37 + #include <time.h>
38 + #include <sys/time.h>
39  
40   uid_t uid;
41   uid_t euid;
# Line 112 | Line 134 | void systemStats(){
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";
141    static char *tmemname = "hw.physmem";
142    static char *fmemname = "vm.stats.vm.v_free_count";
# Line 122 | Line 146 | void systemStats(){
146    kvm_t *kvmd = NULL;
147    struct kvm_swap swapinfo;
148    char errbuf[_POSIX2_LINE_MAX];
149 +  time_t current;
150 +  struct timeval uptime;
151 +
152 +  time(&current);
153    
154 +  if (sysctlbyname(uptimename, NULL, &size, NULL, NULL) < 0){
155 +    errf("sysctlbyname (%m)");
156 +    die();
157 +  }
158 +
159 +
160 +  if (sysctlbyname(uptimename, &uptime, &size, NULL, NULL) < 0){
161 +    errf("Failed to get cpu stats (%m)");
162 +    die();
163 +  }
164 +  
165 +  printf("packet.os.uptime %ld\n",(current-(uptime.tv_sec)));
166 +
167 +
168    if (sysctlbyname(cpname, NULL, &size, NULL, NULL) < 0){
169      errf("sysctlbyname (%m)");
170      die();
# Line 150 | Line 192 | void systemStats(){
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");
# Line 216 | Line 260 | void systemStats(){
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)");

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines