rstat_proc.c (32629) | rstat_proc.c (39228) |
---|---|
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 "$Id: rstat_proc.c,v 1.9 1998/01/07 07:50:59 charnier Exp $"; | 36 "$Id: rstat_proc.c,v 1.10 1998/01/19 23:13:19 wpaul Exp $"; |
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/dkstat.h> 47#include <sys/socket.h> 48#include <sys/sysctl.h> 49#include <sys/time.h> 50#include <sys/vmmeter.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/dkstat.h> 47#include <sys/socket.h> 48#include <sys/sysctl.h> 49#include <sys/time.h> 50#include <sys/vmmeter.h> |
51#include <sys/param.h> |
|
51 52#include <err.h> 53#include <fcntl.h> 54#include <kvm.h> 55#include <limits.h> 56#include <signal.h> 57#include <stdio.h> 58#include <stdlib.h> 59#include <string.h> 60#include <syslog.h> 61#include <unistd.h> | 52 53#include <err.h> 54#include <fcntl.h> 55#include <kvm.h> 56#include <limits.h> 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> |
|
62 63#include <net/if.h> 64#include <net/if_mib.h> 65 66#undef FSHIFT /* Use protocol's shift and scale values */ 67#undef FSCALE 68#undef if_ipackets 69#undef if_ierrors 70#undef if_opackets 71#undef if_oerrors 72#undef if_collisions 73#include <rpcsvc/rstat.h> 74 75struct nlist nl[] = { 76#define X_CPTIME 0 77 { "_cp_time" }, 78#define X_CNT 1 79 { "_cnt" }, | 64 65#include <net/if.h> 66#include <net/if_mib.h> 67 68#undef FSHIFT /* Use protocol's shift and scale values */ 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 77struct nlist nl[] = { 78#define X_CPTIME 0 79 { "_cp_time" }, 80#define X_CNT 1 81 { "_cnt" }, |
80#define X_DKXFER 2 81 { "_dk_xfer" }, 82#define X_DKNDRIVE 3 83 { "_dk_ndrive" }, | |
84 { "" }, 85}; 86 87int havedisk __P((void)); | 82 { "" }, 83}; 84 85int havedisk __P((void)); |
86void updatexfers __P((int, int *)); |
|
88void setup __P((void)); 89int stats_service(); 90 91extern int from_inetd; 92int sincelastreq = 0; /* number of alarms since last request */ 93extern int closedown; 94 95union { --- 167 unchanged lines hidden (view full) --- 263 stats_all.s1.v_pswpin = cnt.v_swappgsin; 264 stats_all.s1.v_pswpout = cnt.v_swappgsout; 265 stats_all.s1.v_intr = cnt.v_intr; 266 gettimeofday(&tm, (struct timezone *) 0); 267 stats_all.s1.v_intr -= hz*(tm.tv_sec - btm.tv_sec) + 268 hz*(tm.tv_usec - btm.tv_usec)/1000000; 269 stats_all.s2.v_swtch = cnt.v_swtch; 270 | 87void setup __P((void)); 88int stats_service(); 89 90extern int from_inetd; 91int sincelastreq = 0; /* number of alarms since last request */ 92extern int closedown; 93 94union { --- 167 unchanged lines hidden (view full) --- 262 stats_all.s1.v_pswpin = cnt.v_swappgsin; 263 stats_all.s1.v_pswpout = cnt.v_swappgsout; 264 stats_all.s1.v_intr = cnt.v_intr; 265 gettimeofday(&tm, (struct timezone *) 0); 266 stats_all.s1.v_intr -= hz*(tm.tv_sec - btm.tv_sec) + 267 hz*(tm.tv_usec - btm.tv_usec)/1000000; 268 stats_all.s2.v_swtch = cnt.v_swtch; 269 |
271 /* XXX - should use sysctl */ 272 if (kvm_read(kd, (long)nl[X_DKXFER].n_value, (char *)stats_all.s1.dk_xfer, sizeof (stats_all.s1.dk_xfer)) 273 != sizeof (stats_all.s1.dk_xfer)) { 274 syslog(LOG_ERR, "rstat: can't read dk_xfer from kmem"); 275 exit(1); 276 } | 270 /* update disk transfers */ 271 updatexfers(RSTAT_DK_NDRIVE, stats_all.s1.dk_xfer); |
277 278 mib[0] = CTL_NET; 279 mib[1] = PF_LINK; 280 mib[2] = NETLINK_GENERIC; 281 mib[3] = IFMIB_SYSTEM; 282 mib[4] = IFMIB_IFCOUNT; 283 len = sizeof ifcount; 284 if (sysctl(mib, 5, &ifcount, &len, 0, 0) < 0) { --- 47 unchanged lines hidden (view full) --- 332} 333 334/* 335 * returns true if have a disk 336 */ 337int 338havedisk() 339{ | 272 273 mib[0] = CTL_NET; 274 mib[1] = PF_LINK; 275 mib[2] = NETLINK_GENERIC; 276 mib[3] = IFMIB_SYSTEM; 277 mib[4] = IFMIB_IFCOUNT; 278 len = sizeof ifcount; 279 if (sysctl(mib, 5, &ifcount, &len, 0, 0) < 0) { --- 47 unchanged lines hidden (view full) --- 327} 328 329/* 330 * returns true if have a disk 331 */ 332int 333havedisk() 334{ |
340 int dk_ndrive; | 335 register int i; 336 struct statinfo stats; 337 int num_devices, retval = 0; |
341 | 338 |
342 if (kvm_nlist(kd, nl) != 0) { 343 syslog(LOG_ERR, "rstatd: can't get namelist.(d)"); 344 exit (1); 345 } | 339 if ((num_devices = getnumdevs()) < 0) { 340 syslog(LOG_ERR, "rstatd: can't get number of devices: %s", 341 devstat_errbuf); 342 exit(1); 343 } |
346 | 344 |
347 if (kvm_read(kd, (long)nl[X_DKNDRIVE].n_value, (char *)&dk_ndrive, 348 sizeof dk_ndrive)!= sizeof dk_ndrive) { 349 syslog(LOG_ERR, "rstat: can't read kmem"); | 345 if (checkversion() < 0) { 346 syslog(LOG_ERR, "rstatd: %s", devstat_errbuf); |
350 exit(1); 351 } | 347 exit(1); 348 } |
352 return (dk_ndrive != 0); | 349 350 stats.dinfo = (struct devinfo *)malloc(sizeof(struct devinfo)); 351 bzero(stats.dinfo, sizeof(struct devinfo)); 352 353 if (getdevs(&stats) == -1) { 354 syslog(LOG_ERR, "rstatd: can't get device list: %s", 355 devstat_errbuf); 356 exit(1); 357 } 358 for (i = 0; i < stats.dinfo->numdevs; i++) { 359 if (((stats.dinfo->devices[i].device_type 360 & DEVSTAT_TYPE_MASK) == DEVSTAT_TYPE_DIRECT) 361 && ((stats.dinfo->devices[i].device_type 362 & DEVSTAT_TYPE_PASS) == 0)) { 363 retval = 1; 364 break; 365 } 366 } 367 368 free(stats.dinfo); 369 return(retval); |
353} 354 355void | 370} 371 372void |
373updatexfers(numdevs, devs) 374 int numdevs, *devs; 375{ 376 register int i, j; 377 struct statinfo stats; 378 int num_devices = 0; 379 u_int64_t total_transfers; 380 381 if ((num_devices = getnumdevs()) < 0) { 382 syslog(LOG_ERR, "rstatd: can't get number of devices: %s", 383 devstat_errbuf); 384 exit(1); 385 } 386 387 if (checkversion() < 0) { 388 syslog(LOG_ERR, "rstatd: %s", devstat_errbuf); 389 exit(1); 390 } 391 392 stats.dinfo = (struct devinfo *)malloc(sizeof(struct devinfo)); 393 bzero(stats.dinfo, sizeof(struct devinfo)); 394 395 if (getdevs(&stats) == -1) { 396 syslog(LOG_ERR, "rstatd: can't get device list: %s", 397 devstat_errbuf); 398 exit(1); 399 } 400 401 for (i = 0, j = 0; i < stats.dinfo->numdevs && j < numdevs; i++) { 402 if (((stats.dinfo->devices[i].device_type 403 & DEVSTAT_TYPE_MASK) == DEVSTAT_TYPE_DIRECT) 404 && ((stats.dinfo->devices[i].device_type 405 & DEVSTAT_TYPE_PASS) == 0)) { 406 total_transfers = stats.dinfo->devices[i].num_reads + 407 stats.dinfo->devices[i].num_writes + 408 stats.dinfo->devices[i].num_other; 409 /* 410 * XXX KDM If the total transfers for this device 411 * are greater than the amount we can fit in a 412 * signed integer, just set them to the maximum 413 * amount we can fit in a signed integer. I have a 414 * feeling that the rstat protocol assumes 32-bit 415 * integers, so this could well break on a 64-bit 416 * architecture like the Alpha. 417 */ 418 if (total_transfers > INT_MAX) 419 devs[j] = INT_MAX; 420 else 421 devs[j] = total_transfers; 422 j++; 423 } 424 } 425 426 free(stats.dinfo); 427} 428 429void |
|
356rstat_service(rqstp, transp) 357 struct svc_req *rqstp; 358 SVCXPRT *transp; 359{ 360 union { 361 int fill; 362 } argument; 363 char *result; --- 67 unchanged lines hidden --- | 430rstat_service(rqstp, transp) 431 struct svc_req *rqstp; 432 SVCXPRT *transp; 433{ 434 union { 435 int fill; 436 } argument; 437 char *result; --- 67 unchanged lines hidden --- |