diff options
author | Matthew Dempsky <matthew@cvs.openbsd.org> | 2012-06-14 17:31:33 +0000 |
---|---|---|
committer | Matthew Dempsky <matthew@cvs.openbsd.org> | 2012-06-14 17:31:33 +0000 |
commit | 1353018553f3635c0b78e8478cfcba87d0d80a3f (patch) | |
tree | e4495ad01626ad7423e953fde6a5f57e3e93a93a /usr.sbin/snmpd | |
parent | 8f2b3752fec486c1ae6d3dcb663d147fe0daeb59 (diff) |
Add support for UCD-DISKIO-MIB.
ok sthen
Diffstat (limited to 'usr.sbin/snmpd')
-rw-r--r-- | usr.sbin/snmpd/mib.c | 99 | ||||
-rw-r--r-- | usr.sbin/snmpd/mib.h | 31 |
2 files changed, 128 insertions, 2 deletions
diff --git a/usr.sbin/snmpd/mib.c b/usr.sbin/snmpd/mib.c index a24d916eea3..57d61b5ddcb 100644 --- a/usr.sbin/snmpd/mib.c +++ b/usr.sbin/snmpd/mib.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mib.c,v 1.53 2012/05/26 14:45:55 joel Exp $ */ +/* $OpenBSD: mib.c,v 1.54 2012/06/14 17:31:32 matthew Exp $ */ /* * Copyright (c) 2012 Joel Knight <joel@openbsd.org> @@ -32,6 +32,7 @@ #include <sys/socket.h> #include <sys/mount.h> #include <sys/ioctl.h> +#include <sys/disk.h> #include <net/if.h> #include <net/if_types.h> @@ -3363,6 +3364,99 @@ mib_ipfroute(struct oid *oid, struct ber_oid *o, struct ber_element **elm) } /* + * Defined in UCD-DISKIO-MIB.txt. + */ + +int mib_diskio(struct oid *oid, struct ber_oid *o, struct ber_element **elm); + +static struct oid diskio_mib[] = { + { MIB(ucdDiskIOMIB), OID_MIB }, + { MIB(diskIOIndex), OID_TRD, mib_diskio }, + { MIB(diskIODevice), OID_TRD, mib_diskio }, + { MIB(diskIONRead), OID_TRD, mib_diskio }, + { MIB(diskIONWritten), OID_TRD, mib_diskio }, + { MIB(diskIOReads), OID_TRD, mib_diskio }, + { MIB(diskIOWrites), OID_TRD, mib_diskio }, + { MIB(diskIONReadX), OID_TRD, mib_diskio }, + { MIB(diskIONWrittenX), OID_TRD, mib_diskio }, + { MIBEND } +}; + +int +mib_diskio(struct oid *oid, struct ber_oid *o, struct ber_element **elm) +{ + struct ber_element *ber = *elm; + u_int32_t idx; + int mib[] = { CTL_HW, 0 }; + unsigned int diskcount; + struct diskstats *stats; + size_t len; + + len = sizeof(diskcount); + mib[1] = HW_DISKCOUNT; + if (sysctl(mib, sizeofa(mib), &diskcount, &len, NULL, 0) == -1) + return (-1); + + /* Get and verify the current row index */ + idx = o->bo_id[OIDIDX_diskIOEntry]; + if (idx > diskcount) + return (1); + + /* Tables need to prepend the OID on their own */ + o->bo_id[OIDIDX_diskIOEntry] = idx; + ber = ber_add_oid(ber, o); + + len = diskcount * sizeof(*stats); + stats = malloc(len); + if (stats == NULL) + return (-1); + mib[1] = HW_DISKSTATS; + if (sysctl(mib, sizeofa(mib), stats, &len, NULL, 0) == -1) { + free(stats); + return (-1); + } + + switch (o->bo_id[OIDIDX_diskIO]) { + case 1: /* diskIOIndex */ + ber = ber_add_integer(ber, idx); + break; + case 2: /* diskIODevice */ + ber = ber_add_string(ber, stats[idx - 1].ds_name); + break; + case 3: /* diskIONRead */ + ber = ber_add_integer(ber, (u_int32_t)stats[idx - 1].ds_rbytes); + ber_set_header(ber, BER_CLASS_APPLICATION, SNMP_T_COUNTER32); + break; + case 4: /* diskIONWritten */ + ber = ber_add_integer(ber, (u_int32_t)stats[idx - 1].ds_wbytes); + ber_set_header(ber, BER_CLASS_APPLICATION, SNMP_T_COUNTER32); + break; + case 5: /* diskIOReads */ + ber = ber_add_integer(ber, (u_int32_t)stats[idx - 1].ds_rxfer); + ber_set_header(ber, BER_CLASS_APPLICATION, SNMP_T_COUNTER32); + break; + case 6: /* diskIOWrites */ + ber = ber_add_integer(ber, (u_int32_t)stats[idx - 1].ds_wxfer); + ber_set_header(ber, BER_CLASS_APPLICATION, SNMP_T_COUNTER32); + break; + case 12: /* diskIONReadX */ + ber = ber_add_integer(ber, stats[idx - 1].ds_rbytes); + ber_set_header(ber, BER_CLASS_APPLICATION, SNMP_T_COUNTER64); + break; + case 13: /* diskIONWrittenX */ + ber = ber_add_integer(ber, stats[idx - 1].ds_wbytes); + ber_set_header(ber, BER_CLASS_APPLICATION, SNMP_T_COUNTER64); + break; + default: + free(stats); + return (-1); + } + + free(stats); + return (0); +} + +/* * Defined in BRIDGE-MIB.txt (rfc1493) * * This MIB is required by some NMS to accept the device because @@ -3453,6 +3547,9 @@ mib_init(void) /* BRIDGE-MIB */ smi_mibtree(bridge_mib); + /* UCD-DISKIO-MIB */ + smi_mibtree(diskio_mib); + /* OPENBSD-MIB */ smi_mibtree(openbsd_mib); } diff --git a/usr.sbin/snmpd/mib.h b/usr.sbin/snmpd/mib.h index a57544638af..44e694aa674 100644 --- a/usr.sbin/snmpd/mib.h +++ b/usr.sbin/snmpd/mib.h @@ -1,4 +1,4 @@ -/* $OpenBSD: mib.h,v 1.25 2012/03/20 03:01:26 joel Exp $ */ +/* $OpenBSD: mib.h,v 1.26 2012/06/14 17:31:32 matthew Exp $ */ /* * Copyright (c) 2007, 2008 Reyk Floeter <reyk@vantronix.net> @@ -397,6 +397,22 @@ #define MIB_vantronix MIB_enterprises, 26766 #define MIB_openBSD MIB_enterprises, 30155 +/* UCD-DISKIO-MIB */ +#define MIB_ucdExperimental MIB_ucDavis, 13 +#define MIB_ucdDiskIOMIB MIB_ucdExperimental, 15 +#define MIB_diskIOTable MIB_ucdDiskIOMIB, 1 +#define MIB_diskIOEntry MIB_diskIOTable, 1 +#define OIDIDX_diskIO 11 +#define OIDIDX_diskIOEntry 12 +#define MIB_diskIOIndex MIB_diskIOEntry, 1 +#define MIB_diskIODevice MIB_diskIOEntry, 2 +#define MIB_diskIONRead MIB_diskIOEntry, 3 +#define MIB_diskIONWritten MIB_diskIOEntry, 4 +#define MIB_diskIOReads MIB_diskIOEntry, 5 +#define MIB_diskIOWrites MIB_diskIOEntry, 6 +#define MIB_diskIONReadX MIB_diskIOEntry, 12 +#define MIB_diskIONWrittenX MIB_diskIOEntry, 13 + /* OPENBSD-MIB */ #define MIB_pfMIBObjects MIB_openBSD, 1 #define MIB_pfInfo MIB_pfMIBObjects, 1 @@ -893,6 +909,19 @@ { MIBDECL(vantronix) }, \ { MIBDECL(openBSD) }, \ \ + { MIBDECL(ucdExperimental) }, \ + { MIBDECL(ucdDiskIOMIB) }, \ + { MIBDECL(diskIOTable) }, \ + { MIBDECL(diskIOEntry) }, \ + { MIBDECL(diskIOIndex) }, \ + { MIBDECL(diskIODevice) }, \ + { MIBDECL(diskIONRead) }, \ + { MIBDECL(diskIONWritten) }, \ + { MIBDECL(diskIOReads) }, \ + { MIBDECL(diskIOWrites) }, \ + { MIBDECL(diskIONReadX) }, \ + { MIBDECL(diskIONWrittenX) }, \ + \ { MIBDECL(pfMIBObjects) }, \ { MIBDECL(pfInfo) }, \ { MIBDECL(pfRunning) }, \ |