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.9 by tdb, Sat May 18 18:15:56 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 "ukcprog.h"
22   #include <sys/param.h>
# Line 14 | Line 33
33   #include <sys/sysctl.h>
34   #include <fcntl.h>
35   #include <limits.h>
36 + #include <time.h>
37 + #include <sys/time.h>
38  
39   uid_t uid;
40   uid_t euid;
# Line 112 | Line 133 | void systemStats(){
133    long cp_time[CPUSTATES];
134    long total, user, idle, kernel, nice;
135    long totalmem, freemem, swaptotal, swapused;
136 +  float stat;
137  
138 +  static char *uptimename = "kern.boottime";
139    static char *cpname = "kern.cp_time";
140    static char *tmemname = "hw.physmem";
141    static char *fmemname = "vm.stats.vm.v_free_count";
# Line 122 | Line 145 | void systemStats(){
145    kvm_t *kvmd = NULL;
146    struct kvm_swap swapinfo;
147    char errbuf[_POSIX2_LINE_MAX];
148 +  time_t current;
149 +  struct timeval uptime;
150 +
151 +  time(&current);
152    
153 +  if (sysctlbyname(uptimename, NULL, &size, NULL, NULL) < 0){
154 +    errf("sysctlbyname (%m)");
155 +    die();
156 +  }
157 +
158 +
159 +  if (sysctlbyname(uptimename, &uptime, &size, NULL, NULL) < 0){
160 +    errf("Failed to get cpu stats (%m)");
161 +    die();
162 +  }
163 +  
164 +  printf("packet.os.uptime %ld\n",(current-(uptime.tv_sec)));
165 +
166 +
167    if (sysctlbyname(cpname, NULL, &size, NULL, NULL) < 0){
168      errf("sysctlbyname (%m)");
169      die();
# Line 150 | Line 191 | void systemStats(){
191      die();
192    }
193    
194 <  user-=cp_time[CP_USER];
195 <  nice-=cp_time[CP_NICE];
196 <  kernel-=cp_time[CP_SYS];
197 <  idle-=cp_time[CP_IDLE];
194 >  user=cp_time[CP_USER]-user;
195 >  nice=cp_time[CP_NICE]-nice;
196 >  kernel=cp_time[CP_SYS]-kernel;
197 >  idle=cp_time[CP_IDLE]-idle;
198    
199    total=user+nice+kernel+idle;
200 <
201 <  printf("packet.cpu.user %ld\n",((user+nice)*100)/total);
202 <  printf("packet.cpu.kernel %ld\n",(kernel*100)/total);
203 <  printf("packet.cpu.idle %ld\n",(idle*100)/total);
200 >  stat=((float)(user+nice)/(float)total)*100.0;
201 >  printf("packet.cpu.user %.2f\n",stat);
202 >  stat=((float)(kernel)/(float)total)*100.0;
203 >  printf("packet.cpu.kernel %.2f\n",stat);
204 >  stat=((float)(idle)/(float)total)*100.0;
205 >  printf("packet.cpu.idle %.2f\n",stat);
206  
207     /* Cos i-scream's expects this to be sent :/ */
208    printf("packet.cpu.iowait 0\n");
# Line 216 | Line 259 | void systemStats(){
259      die();
260    }
261    
262 <  /* Lose are setgid'ness */
262 >  /* Lose our setgid'ness */
263  
264    if ((setegid(gid)) != 0){
265      errf("Failed to release permissions, refusing to keep setgid. (%m)");

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines