1994-08-28 14:49:04 +00:00
|
|
|
/*
|
|
|
|
* Sun RPC is a product of Sun Microsystems, Inc. and is provided for
|
|
|
|
* unrestricted use provided that this legend is included on all tape
|
|
|
|
* media and as a part of the software program in whole or part. Users
|
|
|
|
* may copy or modify Sun RPC without charge, but are not authorized
|
|
|
|
* to license or distribute it to anyone else except as part of a product or
|
|
|
|
* program developed by the user.
|
|
|
|
*
|
|
|
|
* SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
|
|
|
|
* WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
|
|
|
|
*
|
|
|
|
* Sun RPC is provided with no support and without any obligation on the
|
|
|
|
* part of Sun Microsystems, Inc. to assist in its use, correction,
|
|
|
|
* modification or enhancement.
|
|
|
|
*
|
|
|
|
* SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
|
|
|
|
* INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
|
|
|
|
* OR ANY PART THEREOF.
|
|
|
|
*
|
|
|
|
* In no event will Sun Microsystems, Inc. be liable for any lost revenue
|
|
|
|
* or profits or other special, indirect and consequential damages, even if
|
|
|
|
* Sun has been advised of the possibility of such damages.
|
|
|
|
*
|
|
|
|
* Sun Microsystems, Inc.
|
|
|
|
* 2550 Garcia Avenue
|
|
|
|
* Mountain View, California 94043
|
|
|
|
*/
|
1997-11-26 07:34:56 +00:00
|
|
|
|
1994-08-28 14:49:04 +00:00
|
|
|
#ifndef lint
|
1997-11-26 07:34:56 +00:00
|
|
|
#if 0
|
|
|
|
static char sccsid[] = "from: @(#)rpc.rstatd.c 1.1 86/09/25 Copyr 1984 Sun Micro";
|
|
|
|
static char sccsid[] = "from: @(#)rstat_proc.c 2.2 88/08/01 4.0 RPCSRC";
|
|
|
|
#endif
|
|
|
|
static const char rcsid[] =
|
1999-08-28 00:22:10 +00:00
|
|
|
"$FreeBSD$";
|
1994-08-28 14:49:04 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* rstat service: built with rstat.x and derived from rpc.rstatd.c
|
|
|
|
*
|
|
|
|
* Copyright (c) 1984 by Sun Microsystems, Inc.
|
|
|
|
*/
|
|
|
|
|
1996-12-11 19:11:52 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/sysctl.h>
|
|
|
|
#include <sys/time.h>
|
2003-02-16 15:21:26 +00:00
|
|
|
#include <sys/resource.h>
|
1996-12-11 19:11:52 +00:00
|
|
|
#include <sys/vmmeter.h>
|
1998-09-15 08:15:30 +00:00
|
|
|
#include <sys/param.h>
|
1996-12-11 19:11:52 +00:00
|
|
|
|
1997-11-26 07:34:56 +00:00
|
|
|
#include <err.h>
|
2001-10-17 04:12:29 +00:00
|
|
|
#include <errno.h>
|
1994-08-28 14:49:04 +00:00
|
|
|
#include <fcntl.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <signal.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <syslog.h>
|
1997-11-26 07:34:56 +00:00
|
|
|
#include <unistd.h>
|
1998-09-15 08:15:30 +00:00
|
|
|
#include <devstat.h>
|
1994-08-28 14:49:04 +00:00
|
|
|
|
|
|
|
#include <net/if.h>
|
1996-12-11 19:11:52 +00:00
|
|
|
#include <net/if_mib.h>
|
|
|
|
|
1994-08-28 14:49:04 +00:00
|
|
|
#undef FSHIFT /* Use protocol's shift and scale values */
|
|
|
|
#undef FSCALE
|
|
|
|
#undef if_ipackets
|
|
|
|
#undef if_ierrors
|
|
|
|
#undef if_opackets
|
|
|
|
#undef if_oerrors
|
|
|
|
#undef if_collisions
|
|
|
|
#include <rpcsvc/rstat.h>
|
|
|
|
|
2002-10-02 18:29:50 +00:00
|
|
|
int haveadisk(void);
|
2002-02-07 05:24:53 +00:00
|
|
|
void updatexfers(int, int *);
|
|
|
|
int stats_service(void);
|
1994-08-28 14:49:04 +00:00
|
|
|
|
|
|
|
extern int from_inetd;
|
|
|
|
int sincelastreq = 0; /* number of alarms since last request */
|
|
|
|
extern int closedown;
|
|
|
|
|
|
|
|
union {
|
|
|
|
struct stats s1;
|
|
|
|
struct statsswtch s2;
|
|
|
|
struct statstime s3;
|
|
|
|
} stats_all;
|
|
|
|
|
|
|
|
void updatestat();
|
2003-06-02 02:34:36 +00:00
|
|
|
static int stat_is_init = 0;
|
1994-08-28 14:49:04 +00:00
|
|
|
|
1995-05-30 05:51:47 +00:00
|
|
|
static int cp_time_xlat[RSTAT_CPUSTATES] = { CP_USER, CP_NICE, CP_SYS,
|
1994-08-28 14:49:04 +00:00
|
|
|
CP_IDLE };
|
|
|
|
static long bsd_cp_time[CPUSTATES];
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef FSCALE
|
|
|
|
#define FSCALE (1 << 8)
|
|
|
|
#endif
|
|
|
|
|
1997-11-26 07:34:56 +00:00
|
|
|
void
|
2002-02-07 05:24:53 +00:00
|
|
|
stat_init(void)
|
1994-08-28 14:49:04 +00:00
|
|
|
{
|
|
|
|
stat_is_init = 1;
|
2001-08-03 00:23:37 +00:00
|
|
|
alarm(0);
|
1994-08-28 14:49:04 +00:00
|
|
|
updatestat();
|
|
|
|
(void) signal(SIGALRM, updatestat);
|
|
|
|
alarm(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
statstime *
|
2002-02-07 05:24:53 +00:00
|
|
|
rstatproc_stats_3_svc(void *argp, struct svc_req *rqstp)
|
1994-08-28 14:49:04 +00:00
|
|
|
{
|
|
|
|
if (! stat_is_init)
|
|
|
|
stat_init();
|
|
|
|
sincelastreq = 0;
|
|
|
|
return(&stats_all.s3);
|
|
|
|
}
|
|
|
|
|
|
|
|
statsswtch *
|
2002-02-07 05:24:53 +00:00
|
|
|
rstatproc_stats_2_svc(void *argp, struct svc_req *rqstp)
|
1994-08-28 14:49:04 +00:00
|
|
|
{
|
|
|
|
if (! stat_is_init)
|
|
|
|
stat_init();
|
|
|
|
sincelastreq = 0;
|
|
|
|
return(&stats_all.s2);
|
|
|
|
}
|
|
|
|
|
|
|
|
stats *
|
2002-02-07 05:24:53 +00:00
|
|
|
rstatproc_stats_1_svc(void *argp, struct svc_req *rqstp)
|
1994-08-28 14:49:04 +00:00
|
|
|
{
|
|
|
|
if (! stat_is_init)
|
|
|
|
stat_init();
|
|
|
|
sincelastreq = 0;
|
|
|
|
return(&stats_all.s1);
|
|
|
|
}
|
|
|
|
|
|
|
|
u_int *
|
2002-02-07 05:24:53 +00:00
|
|
|
rstatproc_havedisk_3_svc(void *argp, struct svc_req *rqstp)
|
1994-08-28 14:49:04 +00:00
|
|
|
{
|
|
|
|
static u_int have;
|
|
|
|
|
|
|
|
if (! stat_is_init)
|
|
|
|
stat_init();
|
|
|
|
sincelastreq = 0;
|
2002-10-02 18:29:50 +00:00
|
|
|
have = haveadisk();
|
1994-08-28 14:49:04 +00:00
|
|
|
return(&have);
|
|
|
|
}
|
|
|
|
|
|
|
|
u_int *
|
2002-02-07 05:24:53 +00:00
|
|
|
rstatproc_havedisk_2_svc(void *argp, struct svc_req *rqstp)
|
1994-08-28 14:49:04 +00:00
|
|
|
{
|
1998-01-19 23:13:38 +00:00
|
|
|
return(rstatproc_havedisk_3_svc(argp, rqstp));
|
1994-08-28 14:49:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
u_int *
|
2002-02-07 05:24:53 +00:00
|
|
|
rstatproc_havedisk_1_svc(void *argp, struct svc_req *rqstp)
|
1994-08-28 14:49:04 +00:00
|
|
|
{
|
1998-01-19 23:13:38 +00:00
|
|
|
return(rstatproc_havedisk_3_svc(argp, rqstp));
|
1994-08-28 14:49:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-02-07 05:24:53 +00:00
|
|
|
updatestat(void)
|
1994-08-28 14:49:04 +00:00
|
|
|
{
|
1997-11-26 07:34:56 +00:00
|
|
|
int i, hz;
|
1996-12-11 19:11:52 +00:00
|
|
|
struct clockinfo clockrate;
|
1994-08-28 14:49:04 +00:00
|
|
|
struct vmmeter cnt;
|
1996-12-11 19:11:52 +00:00
|
|
|
struct ifmibdata ifmd;
|
1994-08-28 14:49:04 +00:00
|
|
|
double avrun[3];
|
|
|
|
struct timeval tm, btm;
|
1996-12-11 19:11:52 +00:00
|
|
|
int mib[6];
|
|
|
|
size_t len;
|
|
|
|
int ifcount;
|
1994-08-28 14:49:04 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
fprintf(stderr, "entering updatestat\n");
|
|
|
|
#endif
|
|
|
|
if (sincelastreq >= closedown) {
|
|
|
|
#ifdef DEBUG
|
|
|
|
fprintf(stderr, "about to closedown\n");
|
|
|
|
#endif
|
|
|
|
if (from_inetd)
|
|
|
|
exit(0);
|
|
|
|
else {
|
|
|
|
stat_is_init = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sincelastreq++;
|
|
|
|
|
1996-12-11 19:11:52 +00:00
|
|
|
mib[0] = CTL_KERN;
|
|
|
|
mib[1] = KERN_CLOCKRATE;
|
|
|
|
len = sizeof clockrate;
|
|
|
|
if (sysctl(mib, 2, &clockrate, &len, 0, 0) < 0) {
|
|
|
|
syslog(LOG_ERR, "sysctl(kern.clockrate): %m");
|
1994-08-28 14:49:04 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
1996-12-11 19:11:52 +00:00
|
|
|
hz = clockrate.hz;
|
|
|
|
|
2008-06-10 18:47:43 +00:00
|
|
|
len = sizeof(bsd_cp_time);
|
|
|
|
if (sysctlbyname("kern.cp_time", bsd_cp_time, &len, 0, 0) < 0) {
|
|
|
|
syslog(LOG_ERR, "sysctl(kern.cp_time): %m");
|
1994-08-28 14:49:04 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
for(i = 0; i < RSTAT_CPUSTATES ; i++)
|
|
|
|
stats_all.s1.cp_time[i] = bsd_cp_time[cp_time_xlat[i]];
|
1996-12-11 19:11:52 +00:00
|
|
|
|
1994-08-28 14:49:04 +00:00
|
|
|
(void)getloadavg(avrun, sizeof(avrun) / sizeof(avrun[0]));
|
1996-12-11 19:11:52 +00:00
|
|
|
|
1994-08-28 14:49:04 +00:00
|
|
|
stats_all.s2.avenrun[0] = avrun[0] * FSCALE;
|
|
|
|
stats_all.s2.avenrun[1] = avrun[1] * FSCALE;
|
|
|
|
stats_all.s2.avenrun[2] = avrun[2] * FSCALE;
|
1996-12-11 19:11:52 +00:00
|
|
|
|
|
|
|
mib[0] = CTL_KERN;
|
|
|
|
mib[1] = KERN_BOOTTIME;
|
|
|
|
len = sizeof btm;
|
|
|
|
if (sysctl(mib, 2, &btm, &len, 0, 0) < 0) {
|
|
|
|
syslog(LOG_ERR, "sysctl(kern.boottime): %m");
|
1994-08-28 14:49:04 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
1996-12-11 19:11:52 +00:00
|
|
|
|
1994-08-28 14:49:04 +00:00
|
|
|
stats_all.s2.boottime.tv_sec = btm.tv_sec;
|
|
|
|
stats_all.s2.boottime.tv_usec = btm.tv_usec;
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
fprintf(stderr, "%d %d %d %d\n", stats_all.s1.cp_time[0],
|
|
|
|
stats_all.s1.cp_time[1], stats_all.s1.cp_time[2], stats_all.s1.cp_time[3]);
|
|
|
|
#endif
|
|
|
|
|
2008-06-10 18:47:43 +00:00
|
|
|
#define FETCH_CNT(stat, cnt) do { \
|
|
|
|
len = sizeof((stat)); \
|
|
|
|
if (sysctlbyname("vm.stats." #cnt , &(stat), &len, 0, 0) < 0) { \
|
|
|
|
syslog(LOG_ERR, "sysctl(vm.stats." #cnt "): %m"); \
|
|
|
|
exit(1); \
|
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
FETCH_CNT(stats_all.s1.v_pgpgin, vm.v_vnodepgsin);
|
|
|
|
FETCH_CNT(stats_all.s1.v_pgpgout, vm.v_vnodepgsout);
|
|
|
|
FETCH_CNT(stats_all.s1.v_pswpin, vm.v_swappgsin);
|
|
|
|
FETCH_CNT(stats_all.s1.v_pswpout, vm.v_swappgsout);
|
|
|
|
FETCH_CNT(stats_all.s1.v_intr, sys.v_intr);
|
|
|
|
FETCH_CNT(stats_all.s2.v_swtch, sys.v_swtch);
|
1994-08-28 14:49:04 +00:00
|
|
|
gettimeofday(&tm, (struct timezone *) 0);
|
|
|
|
stats_all.s1.v_intr -= hz*(tm.tv_sec - btm.tv_sec) +
|
|
|
|
hz*(tm.tv_usec - btm.tv_usec)/1000000;
|
|
|
|
|
1998-09-15 08:15:30 +00:00
|
|
|
/* update disk transfers */
|
|
|
|
updatexfers(RSTAT_DK_NDRIVE, stats_all.s1.dk_xfer);
|
1994-08-28 14:49:04 +00:00
|
|
|
|
1996-12-11 19:11:52 +00:00
|
|
|
mib[0] = CTL_NET;
|
|
|
|
mib[1] = PF_LINK;
|
|
|
|
mib[2] = NETLINK_GENERIC;
|
|
|
|
mib[3] = IFMIB_SYSTEM;
|
|
|
|
mib[4] = IFMIB_IFCOUNT;
|
|
|
|
len = sizeof ifcount;
|
|
|
|
if (sysctl(mib, 5, &ifcount, &len, 0, 0) < 0) {
|
|
|
|
syslog(LOG_ERR, "sysctl(net.link.generic.system.ifcount): %m");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
1994-08-28 14:49:04 +00:00
|
|
|
stats_all.s1.if_ipackets = 0;
|
|
|
|
stats_all.s1.if_opackets = 0;
|
|
|
|
stats_all.s1.if_ierrors = 0;
|
|
|
|
stats_all.s1.if_oerrors = 0;
|
|
|
|
stats_all.s1.if_collisions = 0;
|
1996-12-11 19:11:52 +00:00
|
|
|
for (i = 1; i <= ifcount; i++) {
|
|
|
|
len = sizeof ifmd;
|
|
|
|
mib[3] = IFMIB_IFDATA;
|
|
|
|
mib[4] = i;
|
|
|
|
mib[5] = IFDATA_GENERAL;
|
|
|
|
if (sysctl(mib, 6, &ifmd, &len, 0, 0) < 0) {
|
2001-10-17 04:12:29 +00:00
|
|
|
if (errno == ENOENT)
|
|
|
|
continue;
|
|
|
|
|
1996-12-11 19:11:52 +00:00
|
|
|
syslog(LOG_ERR, "sysctl(net.link.ifdata.%d.general)"
|
|
|
|
": %m", i);
|
1994-08-28 14:49:04 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
1996-12-11 19:11:52 +00:00
|
|
|
|
|
|
|
stats_all.s1.if_ipackets += ifmd.ifmd_data.ifi_ipackets;
|
|
|
|
stats_all.s1.if_opackets += ifmd.ifmd_data.ifi_opackets;
|
|
|
|
stats_all.s1.if_ierrors += ifmd.ifmd_data.ifi_ierrors;
|
|
|
|
stats_all.s1.if_oerrors += ifmd.ifmd_data.ifi_oerrors;
|
|
|
|
stats_all.s1.if_collisions += ifmd.ifmd_data.ifi_collisions;
|
1994-08-28 14:49:04 +00:00
|
|
|
}
|
|
|
|
gettimeofday((struct timeval *)&stats_all.s3.curtime,
|
|
|
|
(struct timezone *) 0);
|
|
|
|
alarm(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* returns true if have a disk
|
|
|
|
*/
|
1997-11-26 07:34:56 +00:00
|
|
|
int
|
2002-10-02 18:29:50 +00:00
|
|
|
haveadisk(void)
|
1994-08-28 14:49:04 +00:00
|
|
|
{
|
1998-09-15 08:15:30 +00:00
|
|
|
register int i;
|
|
|
|
struct statinfo stats;
|
|
|
|
int num_devices, retval = 0;
|
1994-08-28 14:49:04 +00:00
|
|
|
|
2003-03-15 21:04:50 +00:00
|
|
|
if ((num_devices = devstat_getnumdevs(NULL)) < 0) {
|
1998-09-15 08:15:30 +00:00
|
|
|
syslog(LOG_ERR, "rstatd: can't get number of devices: %s",
|
|
|
|
devstat_errbuf);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2003-03-15 21:04:50 +00:00
|
|
|
if (devstat_checkversion(NULL) < 0) {
|
1998-09-15 08:15:30 +00:00
|
|
|
syslog(LOG_ERR, "rstatd: %s", devstat_errbuf);
|
|
|
|
exit(1);
|
|
|
|
}
|
1994-08-28 14:49:04 +00:00
|
|
|
|
1998-09-15 08:15:30 +00:00
|
|
|
stats.dinfo = (struct devinfo *)malloc(sizeof(struct devinfo));
|
|
|
|
bzero(stats.dinfo, sizeof(struct devinfo));
|
|
|
|
|
2003-03-15 21:04:50 +00:00
|
|
|
if (devstat_getdevs(NULL, &stats) == -1) {
|
1998-09-15 08:15:30 +00:00
|
|
|
syslog(LOG_ERR, "rstatd: can't get device list: %s",
|
|
|
|
devstat_errbuf);
|
1994-08-28 14:49:04 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
1998-09-15 08:15:30 +00:00
|
|
|
for (i = 0; i < stats.dinfo->numdevs; i++) {
|
|
|
|
if (((stats.dinfo->devices[i].device_type
|
|
|
|
& DEVSTAT_TYPE_MASK) == DEVSTAT_TYPE_DIRECT)
|
|
|
|
&& ((stats.dinfo->devices[i].device_type
|
|
|
|
& DEVSTAT_TYPE_PASS) == 0)) {
|
|
|
|
retval = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-10-08 19:59:40 +00:00
|
|
|
if (stats.dinfo->mem_ptr)
|
|
|
|
free(stats.dinfo->mem_ptr);
|
|
|
|
|
1998-09-15 08:15:30 +00:00
|
|
|
free(stats.dinfo);
|
|
|
|
return(retval);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-02-07 05:24:53 +00:00
|
|
|
updatexfers(int numdevs, int *devs)
|
1998-09-15 08:15:30 +00:00
|
|
|
{
|
Run a revision of the devstat interface:
Kernel:
Change statistics to use the *uptime() timescale (ie: relative to
boottime) rather than the UTC aligned timescale. This makes the
device statistics code oblivious to clock steps.
Change timestamps to bintime format, they are cheaper.
Remove the "busy_count", and replace it with two counter fields:
"start_count" and "end_count", which are updated in the down and
up paths respectively. This removes the locking constraint on
devstat.
Add a timestamp argument to devstat_start_transaction(), this will
normally be a timestamp set by the *_bio() function in bp->bio_t0.
Use this field to calculate duration of I/O operations.
Add two timestamp arguments to devstat_end_transaction(), one is
the current time, a NULL pointer means "take timestamp yourself",
the other is the timestamp of when this transaction started (see
above).
Change calculation of busy_time to operate on "the salami principle":
Only when we are idle, which we can determine by the start+end
counts being identical, do we update the "busy_from" field in the
down path. In the up path we accumulate the timeslice in busy_time
and update busy_from.
Change the byte_* and num_* fields into two arrays: bytes[] and
operations[].
Userland:
Change the misleading "busy_time" name to be called "snap_time" and
make the time long double since that is what most users need anyway,
fill it using clock_gettime(CLOCK_MONOTONIC) to put it on the same
timescale as the kernel fields.
Change devstat_compute_etime() to operate on struct bintime.
Remove the version 2 legacy interface: the change to bintime makes
compatibility far too expensive.
Fix a bug in systat's "vm" page where boot relative busy times would
be bogus.
Bump __FreeBSD_version to 500107
Review & Collaboration by: ken
2003-03-15 21:59:06 +00:00
|
|
|
register int i, j, k, t;
|
1998-09-15 08:15:30 +00:00
|
|
|
struct statinfo stats;
|
|
|
|
int num_devices = 0;
|
|
|
|
u_int64_t total_transfers;
|
|
|
|
|
2003-03-15 21:04:50 +00:00
|
|
|
if ((num_devices = devstat_getnumdevs(NULL)) < 0) {
|
1998-09-15 08:15:30 +00:00
|
|
|
syslog(LOG_ERR, "rstatd: can't get number of devices: %s",
|
|
|
|
devstat_errbuf);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2003-03-15 21:04:50 +00:00
|
|
|
if (devstat_checkversion(NULL) < 0) {
|
1998-09-15 08:15:30 +00:00
|
|
|
syslog(LOG_ERR, "rstatd: %s", devstat_errbuf);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
stats.dinfo = (struct devinfo *)malloc(sizeof(struct devinfo));
|
|
|
|
bzero(stats.dinfo, sizeof(struct devinfo));
|
|
|
|
|
2003-03-15 21:04:50 +00:00
|
|
|
if (devstat_getdevs(NULL, &stats) == -1) {
|
1998-09-15 08:15:30 +00:00
|
|
|
syslog(LOG_ERR, "rstatd: can't get device list: %s",
|
|
|
|
devstat_errbuf);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0, j = 0; i < stats.dinfo->numdevs && j < numdevs; i++) {
|
|
|
|
if (((stats.dinfo->devices[i].device_type
|
|
|
|
& DEVSTAT_TYPE_MASK) == DEVSTAT_TYPE_DIRECT)
|
|
|
|
&& ((stats.dinfo->devices[i].device_type
|
|
|
|
& DEVSTAT_TYPE_PASS) == 0)) {
|
Run a revision of the devstat interface:
Kernel:
Change statistics to use the *uptime() timescale (ie: relative to
boottime) rather than the UTC aligned timescale. This makes the
device statistics code oblivious to clock steps.
Change timestamps to bintime format, they are cheaper.
Remove the "busy_count", and replace it with two counter fields:
"start_count" and "end_count", which are updated in the down and
up paths respectively. This removes the locking constraint on
devstat.
Add a timestamp argument to devstat_start_transaction(), this will
normally be a timestamp set by the *_bio() function in bp->bio_t0.
Use this field to calculate duration of I/O operations.
Add two timestamp arguments to devstat_end_transaction(), one is
the current time, a NULL pointer means "take timestamp yourself",
the other is the timestamp of when this transaction started (see
above).
Change calculation of busy_time to operate on "the salami principle":
Only when we are idle, which we can determine by the start+end
counts being identical, do we update the "busy_from" field in the
down path. In the up path we accumulate the timeslice in busy_time
and update busy_from.
Change the byte_* and num_* fields into two arrays: bytes[] and
operations[].
Userland:
Change the misleading "busy_time" name to be called "snap_time" and
make the time long double since that is what most users need anyway,
fill it using clock_gettime(CLOCK_MONOTONIC) to put it on the same
timescale as the kernel fields.
Change devstat_compute_etime() to operate on struct bintime.
Remove the version 2 legacy interface: the change to bintime makes
compatibility far too expensive.
Fix a bug in systat's "vm" page where boot relative busy times would
be bogus.
Bump __FreeBSD_version to 500107
Review & Collaboration by: ken
2003-03-15 21:59:06 +00:00
|
|
|
total_transfers = 0;
|
|
|
|
for (k = 0; k < DEVSTAT_N_TRANS_FLAGS; k++)
|
|
|
|
total_transfers +=
|
|
|
|
stats.dinfo->devices[i].operations[k];
|
1998-09-15 08:15:30 +00:00
|
|
|
/*
|
|
|
|
* XXX KDM If the total transfers for this device
|
|
|
|
* are greater than the amount we can fit in a
|
|
|
|
* signed integer, just set them to the maximum
|
|
|
|
* amount we can fit in a signed integer. I have a
|
|
|
|
* feeling that the rstat protocol assumes 32-bit
|
|
|
|
* integers, so this could well break on a 64-bit
|
|
|
|
* architecture like the Alpha.
|
|
|
|
*/
|
|
|
|
if (total_transfers > INT_MAX)
|
1998-09-16 21:33:14 +00:00
|
|
|
t = INT_MAX;
|
1998-09-15 08:15:30 +00:00
|
|
|
else
|
1998-09-16 21:33:14 +00:00
|
|
|
t = total_transfers;
|
|
|
|
devs[j] = t;
|
1998-09-15 08:15:30 +00:00
|
|
|
j++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-10-08 19:59:40 +00:00
|
|
|
if (stats.dinfo->mem_ptr)
|
|
|
|
free(stats.dinfo->mem_ptr);
|
|
|
|
|
1998-09-15 08:15:30 +00:00
|
|
|
free(stats.dinfo);
|
1994-08-28 14:49:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-02-07 05:24:53 +00:00
|
|
|
rstat_service(struct svc_req *rqstp, SVCXPRT *transp)
|
1994-08-28 14:49:04 +00:00
|
|
|
{
|
|
|
|
union {
|
|
|
|
int fill;
|
|
|
|
} argument;
|
|
|
|
char *result;
|
|
|
|
bool_t (*xdr_argument)(), (*xdr_result)();
|
|
|
|
char *(*local)();
|
|
|
|
|
|
|
|
switch (rqstp->rq_proc) {
|
|
|
|
case NULLPROC:
|
2002-04-28 15:18:50 +00:00
|
|
|
(void)svc_sendreply(transp, (xdrproc_t)xdr_void, NULL);
|
1994-08-28 14:49:04 +00:00
|
|
|
goto leave;
|
|
|
|
|
|
|
|
case RSTATPROC_STATS:
|
|
|
|
xdr_argument = xdr_void;
|
|
|
|
xdr_result = xdr_statstime;
|
|
|
|
switch (rqstp->rq_vers) {
|
|
|
|
case RSTATVERS_ORIG:
|
1998-01-19 23:13:38 +00:00
|
|
|
local = (char *(*)()) rstatproc_stats_1_svc;
|
1994-08-28 14:49:04 +00:00
|
|
|
break;
|
|
|
|
case RSTATVERS_SWTCH:
|
1998-01-19 23:13:38 +00:00
|
|
|
local = (char *(*)()) rstatproc_stats_2_svc;
|
1994-08-28 14:49:04 +00:00
|
|
|
break;
|
|
|
|
case RSTATVERS_TIME:
|
1998-01-19 23:13:38 +00:00
|
|
|
local = (char *(*)()) rstatproc_stats_3_svc;
|
1994-08-28 14:49:04 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
svcerr_progvers(transp, RSTATVERS_ORIG, RSTATVERS_TIME);
|
|
|
|
goto leave;
|
|
|
|
/*NOTREACHED*/
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RSTATPROC_HAVEDISK:
|
|
|
|
xdr_argument = xdr_void;
|
|
|
|
xdr_result = xdr_u_int;
|
|
|
|
switch (rqstp->rq_vers) {
|
|
|
|
case RSTATVERS_ORIG:
|
1998-01-19 23:13:38 +00:00
|
|
|
local = (char *(*)()) rstatproc_havedisk_1_svc;
|
1994-08-28 14:49:04 +00:00
|
|
|
break;
|
|
|
|
case RSTATVERS_SWTCH:
|
1998-01-19 23:13:38 +00:00
|
|
|
local = (char *(*)()) rstatproc_havedisk_2_svc;
|
1994-08-28 14:49:04 +00:00
|
|
|
break;
|
|
|
|
case RSTATVERS_TIME:
|
1998-01-19 23:13:38 +00:00
|
|
|
local = (char *(*)()) rstatproc_havedisk_3_svc;
|
1994-08-28 14:49:04 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
svcerr_progvers(transp, RSTATVERS_ORIG, RSTATVERS_TIME);
|
|
|
|
goto leave;
|
|
|
|
/*NOTREACHED*/
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
svcerr_noproc(transp);
|
|
|
|
goto leave;
|
|
|
|
}
|
|
|
|
bzero((char *)&argument, sizeof(argument));
|
2002-04-28 15:18:50 +00:00
|
|
|
if (!svc_getargs(transp, (xdrproc_t)xdr_argument, &argument)) {
|
1994-08-28 14:49:04 +00:00
|
|
|
svcerr_decode(transp);
|
|
|
|
goto leave;
|
|
|
|
}
|
|
|
|
result = (*local)(&argument, rqstp);
|
2002-04-28 15:18:50 +00:00
|
|
|
if (result != NULL &&
|
|
|
|
!svc_sendreply(transp, (xdrproc_t)xdr_result, result)) {
|
1994-08-28 14:49:04 +00:00
|
|
|
svcerr_systemerr(transp);
|
|
|
|
}
|
2002-04-28 15:18:50 +00:00
|
|
|
if (!svc_freeargs(transp, (xdrproc_t)xdr_argument, &argument))
|
1997-11-26 07:34:56 +00:00
|
|
|
errx(1, "unable to free arguments");
|
1994-08-28 14:49:04 +00:00
|
|
|
leave:
|
|
|
|
if (from_inetd)
|
|
|
|
exit(0);
|
|
|
|
}
|