Deleted Added
full compact
rstat_proc.c (115667) rstat_proc.c (179710)
1/*
2 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
3 * unrestricted use provided that this legend is included on all tape
4 * media and as a part of the software program in whole or part. Users
5 * may copy or modify Sun RPC without charge, but are not authorized
6 * to license or distribute it to anyone else except as part of a product or
7 * program developed by the user.
8 *

--- 19 unchanged lines hidden (view full) ---

28 */
29
30#ifndef lint
31#if 0
32static char sccsid[] = "from: @(#)rpc.rstatd.c 1.1 86/09/25 Copyr 1984 Sun Micro";
33static char sccsid[] = "from: @(#)rstat_proc.c 2.2 88/08/01 4.0 RPCSRC";
34#endif
35static const char rcsid[] =
1/*
2 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
3 * unrestricted use provided that this legend is included on all tape
4 * media and as a part of the software program in whole or part. Users
5 * may copy or modify Sun RPC without charge, but are not authorized
6 * to license or distribute it to anyone else except as part of a product or
7 * program developed by the user.
8 *

--- 19 unchanged lines hidden (view full) ---

28 */
29
30#ifndef lint
31#if 0
32static char sccsid[] = "from: @(#)rpc.rstatd.c 1.1 86/09/25 Copyr 1984 Sun Micro";
33static char sccsid[] = "from: @(#)rstat_proc.c 2.2 88/08/01 4.0 RPCSRC";
34#endif
35static const char rcsid[] =
36 "$FreeBSD: head/libexec/rpc.rstatd/rstat_proc.c 115667 2003-06-02 02:34:36Z obrien $";
36 "$FreeBSD: head/libexec/rpc.rstatd/rstat_proc.c 179710 2008-06-10 18:47:43Z jhb $";
37#endif
38
39/*
40 * rstat service: built with rstat.x and derived from rpc.rstatd.c
41 *
42 * Copyright (c) 1984 by Sun Microsystems, Inc.
43 */
44
45#include <sys/types.h>
46#include <sys/socket.h>
47#include <sys/sysctl.h>
48#include <sys/time.h>
49#include <sys/resource.h>
50#include <sys/vmmeter.h>
51#include <sys/param.h>
52
53#include <err.h>
54#include <errno.h>
55#include <fcntl.h>
37#endif
38
39/*
40 * rstat service: built with rstat.x and derived from rpc.rstatd.c
41 *
42 * Copyright (c) 1984 by Sun Microsystems, Inc.
43 */
44
45#include <sys/types.h>
46#include <sys/socket.h>
47#include <sys/sysctl.h>
48#include <sys/time.h>
49#include <sys/resource.h>
50#include <sys/vmmeter.h>
51#include <sys/param.h>
52
53#include <err.h>
54#include <errno.h>
55#include <fcntl.h>
56#include <kvm.h>
57#include <limits.h>
56#include <limits.h>
58#include <nlist.h>
59#include <signal.h>
60#include <stdio.h>
61#include <stdlib.h>
62#include <string.h>
63#include <syslog.h>
64#include <unistd.h>
65#include <devstat.h>
66

--- 4 unchanged lines hidden (view full) ---

71#undef FSCALE
72#undef if_ipackets
73#undef if_ierrors
74#undef if_opackets
75#undef if_oerrors
76#undef if_collisions
77#include <rpcsvc/rstat.h>
78
57#include <signal.h>
58#include <stdio.h>
59#include <stdlib.h>
60#include <string.h>
61#include <syslog.h>
62#include <unistd.h>
63#include <devstat.h>
64

--- 4 unchanged lines hidden (view full) ---

69#undef FSCALE
70#undef if_ipackets
71#undef if_ierrors
72#undef if_opackets
73#undef if_oerrors
74#undef if_collisions
75#include <rpcsvc/rstat.h>
76
79struct nlist nl[] = {
80#define X_CPTIME 0
81 { "_cp_time" },
82#define X_CNT 1
83 { "_cnt" },
84 { "" },
85};
86
87int haveadisk(void);
88void updatexfers(int, int *);
77int haveadisk(void);
78void updatexfers(int, int *);
89void setup(void);
90int stats_service(void);
91
92extern int from_inetd;
93int sincelastreq = 0; /* number of alarms since last request */
94extern int closedown;
95
96union {
97 struct stats s1;
98 struct statsswtch s2;
99 struct statstime s3;
100} stats_all;
101
102void updatestat();
103static int stat_is_init = 0;
79int stats_service(void);
80
81extern int from_inetd;
82int sincelastreq = 0; /* number of alarms since last request */
83extern int closedown;
84
85union {
86 struct stats s1;
87 struct statsswtch s2;
88 struct statstime s3;
89} stats_all;
90
91void updatestat();
92static int stat_is_init = 0;
104static kvm_t *kd;
105
106static int cp_time_xlat[RSTAT_CPUSTATES] = { CP_USER, CP_NICE, CP_SYS,
107 CP_IDLE };
108static long bsd_cp_time[CPUSTATES];
109
110
111#ifndef FSCALE
112#define FSCALE (1 << 8)
113#endif
114
115void
116stat_init(void)
117{
118 stat_is_init = 1;
93
94static int cp_time_xlat[RSTAT_CPUSTATES] = { CP_USER, CP_NICE, CP_SYS,
95 CP_IDLE };
96static long bsd_cp_time[CPUSTATES];
97
98
99#ifndef FSCALE
100#define FSCALE (1 << 8)
101#endif
102
103void
104stat_init(void)
105{
106 stat_is_init = 1;
119 setup();
120 alarm(0);
121 updatestat();
122 (void) signal(SIGALRM, updatestat);
123 alarm(1);
124}
125
126statstime *
127rstatproc_stats_3_svc(void *argp, struct svc_req *rqstp)

--- 61 unchanged lines hidden (view full) ---

189
190#ifdef DEBUG
191 fprintf(stderr, "entering updatestat\n");
192#endif
193 if (sincelastreq >= closedown) {
194#ifdef DEBUG
195 fprintf(stderr, "about to closedown\n");
196#endif
107 alarm(0);
108 updatestat();
109 (void) signal(SIGALRM, updatestat);
110 alarm(1);
111}
112
113statstime *
114rstatproc_stats_3_svc(void *argp, struct svc_req *rqstp)

--- 61 unchanged lines hidden (view full) ---

176
177#ifdef DEBUG
178 fprintf(stderr, "entering updatestat\n");
179#endif
180 if (sincelastreq >= closedown) {
181#ifdef DEBUG
182 fprintf(stderr, "about to closedown\n");
183#endif
197 kvm_close(kd);
198 if (from_inetd)
199 exit(0);
200 else {
201 stat_is_init = 0;
202 return;
203 }
204 }
205 sincelastreq++;
206
207 mib[0] = CTL_KERN;
208 mib[1] = KERN_CLOCKRATE;
209 len = sizeof clockrate;
210 if (sysctl(mib, 2, &clockrate, &len, 0, 0) < 0) {
211 syslog(LOG_ERR, "sysctl(kern.clockrate): %m");
212 exit(1);
213 }
214 hz = clockrate.hz;
215
184 if (from_inetd)
185 exit(0);
186 else {
187 stat_is_init = 0;
188 return;
189 }
190 }
191 sincelastreq++;
192
193 mib[0] = CTL_KERN;
194 mib[1] = KERN_CLOCKRATE;
195 len = sizeof clockrate;
196 if (sysctl(mib, 2, &clockrate, &len, 0, 0) < 0) {
197 syslog(LOG_ERR, "sysctl(kern.clockrate): %m");
198 exit(1);
199 }
200 hz = clockrate.hz;
201
216 if (kvm_read(kd, (long)nl[X_CPTIME].n_value, (char *)bsd_cp_time, sizeof(bsd_cp_time))
217 != sizeof(bsd_cp_time)) {
218 syslog(LOG_ERR, "rstat: can't read cp_time from kmem");
202 len = sizeof(bsd_cp_time);
203 if (sysctlbyname("kern.cp_time", bsd_cp_time, &len, 0, 0) < 0) {
204 syslog(LOG_ERR, "sysctl(kern.cp_time): %m");
219 exit(1);
220 }
221 for(i = 0; i < RSTAT_CPUSTATES ; i++)
222 stats_all.s1.cp_time[i] = bsd_cp_time[cp_time_xlat[i]];
223
224 (void)getloadavg(avrun, sizeof(avrun) / sizeof(avrun[0]));
225
226 stats_all.s2.avenrun[0] = avrun[0] * FSCALE;

--- 12 unchanged lines hidden (view full) ---

239 stats_all.s2.boottime.tv_usec = btm.tv_usec;
240
241
242#ifdef DEBUG
243 fprintf(stderr, "%d %d %d %d\n", stats_all.s1.cp_time[0],
244 stats_all.s1.cp_time[1], stats_all.s1.cp_time[2], stats_all.s1.cp_time[3]);
245#endif
246
205 exit(1);
206 }
207 for(i = 0; i < RSTAT_CPUSTATES ; i++)
208 stats_all.s1.cp_time[i] = bsd_cp_time[cp_time_xlat[i]];
209
210 (void)getloadavg(avrun, sizeof(avrun) / sizeof(avrun[0]));
211
212 stats_all.s2.avenrun[0] = avrun[0] * FSCALE;

--- 12 unchanged lines hidden (view full) ---

225 stats_all.s2.boottime.tv_usec = btm.tv_usec;
226
227
228#ifdef DEBUG
229 fprintf(stderr, "%d %d %d %d\n", stats_all.s1.cp_time[0],
230 stats_all.s1.cp_time[1], stats_all.s1.cp_time[2], stats_all.s1.cp_time[3]);
231#endif
232
247 /* XXX - should use sysctl */
248 if (kvm_read(kd, (long)nl[X_CNT].n_value, (char *)&cnt, sizeof cnt) != sizeof cnt) {
249 syslog(LOG_ERR, "rstat: can't read cnt from kmem");
250 exit(1);
251 }
252 stats_all.s1.v_pgpgin = cnt.v_vnodepgsin;
253 stats_all.s1.v_pgpgout = cnt.v_vnodepgsout;
254 stats_all.s1.v_pswpin = cnt.v_swappgsin;
255 stats_all.s1.v_pswpout = cnt.v_swappgsout;
256 stats_all.s1.v_intr = cnt.v_intr;
233#define FETCH_CNT(stat, cnt) do { \
234 len = sizeof((stat)); \
235 if (sysctlbyname("vm.stats." #cnt , &(stat), &len, 0, 0) < 0) { \
236 syslog(LOG_ERR, "sysctl(vm.stats." #cnt "): %m"); \
237 exit(1); \
238 } \
239} while (0)
240
241 FETCH_CNT(stats_all.s1.v_pgpgin, vm.v_vnodepgsin);
242 FETCH_CNT(stats_all.s1.v_pgpgout, vm.v_vnodepgsout);
243 FETCH_CNT(stats_all.s1.v_pswpin, vm.v_swappgsin);
244 FETCH_CNT(stats_all.s1.v_pswpout, vm.v_swappgsout);
245 FETCH_CNT(stats_all.s1.v_intr, sys.v_intr);
246 FETCH_CNT(stats_all.s2.v_swtch, sys.v_swtch);
257 gettimeofday(&tm, (struct timezone *) 0);
258 stats_all.s1.v_intr -= hz*(tm.tv_sec - btm.tv_sec) +
259 hz*(tm.tv_usec - btm.tv_usec)/1000000;
247 gettimeofday(&tm, (struct timezone *) 0);
248 stats_all.s1.v_intr -= hz*(tm.tv_sec - btm.tv_sec) +
249 hz*(tm.tv_usec - btm.tv_usec)/1000000;
260 stats_all.s2.v_swtch = cnt.v_swtch;
261
262 /* update disk transfers */
263 updatexfers(RSTAT_DK_NDRIVE, stats_all.s1.dk_xfer);
264
265 mib[0] = CTL_NET;
266 mib[1] = PF_LINK;
267 mib[2] = NETLINK_GENERIC;
268 mib[3] = IFMIB_SYSTEM;

--- 29 unchanged lines hidden (view full) ---

298 stats_all.s1.if_oerrors += ifmd.ifmd_data.ifi_oerrors;
299 stats_all.s1.if_collisions += ifmd.ifmd_data.ifi_collisions;
300 }
301 gettimeofday((struct timeval *)&stats_all.s3.curtime,
302 (struct timezone *) 0);
303 alarm(1);
304}
305
250
251 /* update disk transfers */
252 updatexfers(RSTAT_DK_NDRIVE, stats_all.s1.dk_xfer);
253
254 mib[0] = CTL_NET;
255 mib[1] = PF_LINK;
256 mib[2] = NETLINK_GENERIC;
257 mib[3] = IFMIB_SYSTEM;

--- 29 unchanged lines hidden (view full) ---

287 stats_all.s1.if_oerrors += ifmd.ifmd_data.ifi_oerrors;
288 stats_all.s1.if_collisions += ifmd.ifmd_data.ifi_collisions;
289 }
290 gettimeofday((struct timeval *)&stats_all.s3.curtime,
291 (struct timezone *) 0);
292 alarm(1);
293}
294
306void
307setup()
308{
309 char errbuf[_POSIX2_LINE_MAX];
310
311 int en;
312
313 if ((kd = kvm_openfiles(NULL, NULL, NULL, O_RDONLY, errbuf)) == NULL) {
314 syslog(LOG_ERR, "rpc.rstatd, %s", errbuf);
315 exit(1);
316 }
317
318 if ((en = kvm_nlist(kd, nl)) != 0) {
319 syslog(LOG_ERR, "rstatd: Can't get namelist. %d", en);
320 exit (1);
321 }
322}
323
324/*
325 * returns true if have a disk
326 */
327int
328haveadisk(void)
329{
330 register int i;
331 struct statinfo stats;

--- 174 unchanged lines hidden ---
295/*
296 * returns true if have a disk
297 */
298int
299haveadisk(void)
300{
301 register int i;
302 struct statinfo stats;

--- 174 unchanged lines hidden ---