|
|
9a6c41 |
1092308 - backport diskio device filtering
|
|
|
9a6c41 |
|
|
|
9a6c41 |
Backported from:
|
|
|
9a6c41 |
|
|
|
9a6c41 |
commit 5be210c90870ff6bab193d497d401b92c1d50db9
|
|
|
9a6c41 |
Author: Jan Safranek <jsafranek@users.sourceforge.net>
|
|
|
9a6c41 |
Date: Thu Mar 6 13:26:30 2014 +0100
|
|
|
9a6c41 |
|
|
|
9a6c41 |
CHANGES: snmpd: add new snmpd.conf option 'diskio' to monitor only selected disks.
|
|
|
9a6c41 |
|
|
|
9a6c41 |
On machines with thousands of block devices, parsing /proc/diskstats is really
|
|
|
9a6c41 |
slow. The new option enables monitoring of selected devices, saving lot of CPU
|
|
|
9a6c41 |
time.
|
|
|
9a6c41 |
|
|
|
9a6c41 |
diff -up net-snmp-5.7.2/agent/mibgroup/ucd-snmp/diskio.c.test net-snmp-5.7.2/agent/mibgroup/ucd-snmp/diskio.c
|
|
|
9a6c41 |
--- net-snmp-5.7.2/agent/mibgroup/ucd-snmp/diskio.c.test 2012-10-10 00:28:58.000000000 +0200
|
|
|
9a6c41 |
+++ net-snmp-5.7.2/agent/mibgroup/ucd-snmp/diskio.c 2015-06-18 15:14:57.164891695 +0200
|
|
|
9a6c41 |
@@ -27,11 +27,18 @@
|
|
|
9a6c41 |
|
|
|
9a6c41 |
#include <math.h>
|
|
|
9a6c41 |
|
|
|
9a6c41 |
+#if defined (linux)
|
|
|
9a6c41 |
+/* for stat() */
|
|
|
9a6c41 |
+#include <ctype.h>
|
|
|
9a6c41 |
+#include <sys/stat.h>
|
|
|
9a6c41 |
+#endif
|
|
|
9a6c41 |
+
|
|
|
9a6c41 |
#include <net-snmp/net-snmp-includes.h>
|
|
|
9a6c41 |
#include <net-snmp/agent/net-snmp-agent-includes.h>
|
|
|
9a6c41 |
|
|
|
9a6c41 |
#include "util_funcs/header_simple_table.h"
|
|
|
9a6c41 |
|
|
|
9a6c41 |
+#include "struct.h"
|
|
|
9a6c41 |
/*
|
|
|
9a6c41 |
* include our .h file
|
|
|
9a6c41 |
*/
|
|
|
9a6c41 |
@@ -95,6 +102,66 @@ static int ps_numdisks; /* number of d
|
|
|
9a6c41 |
#if defined (linux)
|
|
|
9a6c41 |
#define DISKIO_SAMPLE_INTERVAL 5
|
|
|
9a6c41 |
void devla_getstats(unsigned int regno, void * dummy);
|
|
|
9a6c41 |
+static void diskio_parse_config_disks(const char *token, char *cptr);
|
|
|
9a6c41 |
+static void diskio_free_config(void);
|
|
|
9a6c41 |
+static int get_sysfs_stats(void);
|
|
|
9a6c41 |
+
|
|
|
9a6c41 |
+struct diskiopart {
|
|
|
9a6c41 |
+ char syspath[STRMAX]; /* full stat path */
|
|
|
9a6c41 |
+ char name[STRMAX]; /* name as provided */
|
|
|
9a6c41 |
+ char shortname[STRMAX]; /* short name for output */
|
|
|
9a6c41 |
+ int major;
|
|
|
9a6c41 |
+ int minor;
|
|
|
9a6c41 |
+};
|
|
|
9a6c41 |
+
|
|
|
9a6c41 |
+static int numdisks;
|
|
|
9a6c41 |
+static int maxdisks = 0;
|
|
|
9a6c41 |
+static struct diskiopart *disks;
|
|
|
9a6c41 |
+
|
|
|
9a6c41 |
+#define DISK_INCR 2
|
|
|
9a6c41 |
+
|
|
|
9a6c41 |
+typedef struct linux_diskio
|
|
|
9a6c41 |
+{
|
|
|
9a6c41 |
+ int major;
|
|
|
9a6c41 |
+ int minor;
|
|
|
9a6c41 |
+ unsigned long blocks;
|
|
|
9a6c41 |
+ char name[256];
|
|
|
9a6c41 |
+ unsigned long rio;
|
|
|
9a6c41 |
+ unsigned long rmerge;
|
|
|
9a6c41 |
+ unsigned long rsect;
|
|
|
9a6c41 |
+ unsigned long ruse;
|
|
|
9a6c41 |
+ unsigned long wio;
|
|
|
9a6c41 |
+ unsigned long wmerge;
|
|
|
9a6c41 |
+ unsigned long wsect;
|
|
|
9a6c41 |
+ unsigned long wuse;
|
|
|
9a6c41 |
+ unsigned long running;
|
|
|
9a6c41 |
+ unsigned long use;
|
|
|
9a6c41 |
+ unsigned long aveq;
|
|
|
9a6c41 |
+} linux_diskio;
|
|
|
9a6c41 |
+
|
|
|
9a6c41 |
+/* disk load averages */
|
|
|
9a6c41 |
+typedef struct linux_diskio_la
|
|
|
9a6c41 |
+{
|
|
|
9a6c41 |
+ unsigned long use_prev;
|
|
|
9a6c41 |
+ double la1, la5, la15;
|
|
|
9a6c41 |
+} linux_diskio_la;
|
|
|
9a6c41 |
+
|
|
|
9a6c41 |
+typedef struct linux_diskio_header
|
|
|
9a6c41 |
+{
|
|
|
9a6c41 |
+ linux_diskio* indices;
|
|
|
9a6c41 |
+ int length;
|
|
|
9a6c41 |
+ int alloc;
|
|
|
9a6c41 |
+} linux_diskio_header;
|
|
|
9a6c41 |
+
|
|
|
9a6c41 |
+typedef struct linux_diskio_la_header
|
|
|
9a6c41 |
+{
|
|
|
9a6c41 |
+ linux_diskio_la * indices;
|
|
|
9a6c41 |
+ int length;
|
|
|
9a6c41 |
+} linux_diskio_la_header;
|
|
|
9a6c41 |
+
|
|
|
9a6c41 |
+static linux_diskio_header head;
|
|
|
9a6c41 |
+static linux_diskio_la_header la_head;
|
|
|
9a6c41 |
+
|
|
|
9a6c41 |
#endif /* linux */
|
|
|
9a6c41 |
|
|
|
9a6c41 |
#if defined (darwin)
|
|
|
9a6c41 |
@@ -228,6 +295,8 @@ init_diskio(void)
|
|
|
9a6c41 |
devla_getstats(0, NULL);
|
|
|
9a6c41 |
/* collect LA data regularly */
|
|
|
9a6c41 |
snmp_alarm_register(DISKIO_SAMPLE_INTERVAL, SA_REPEAT, devla_getstats, NULL);
|
|
|
9a6c41 |
+ snmpd_register_config_handler("diskio", diskio_parse_config_disks,
|
|
|
9a6c41 |
+ diskio_free_config, "path | device");
|
|
|
9a6c41 |
#endif
|
|
|
9a6c41 |
|
|
|
9a6c41 |
|
|
|
9a6c41 |
@@ -870,49 +939,134 @@ var_diskio(struct variable * vp,
|
|
|
9a6c41 |
|
|
|
9a6c41 |
#ifdef linux
|
|
|
9a6c41 |
|
|
|
9a6c41 |
-#define DISK_INCR 2
|
|
|
9a6c41 |
-
|
|
|
9a6c41 |
-typedef struct linux_diskio
|
|
|
9a6c41 |
+static void
|
|
|
9a6c41 |
+diskio_free_config()
|
|
|
9a6c41 |
+ {
|
|
|
9a6c41 |
+ if (la_head.length) {
|
|
|
9a6c41 |
+ /* reset any usage stats, we may get different list of devices from config */
|
|
|
9a6c41 |
+ free(la_head.indices);
|
|
|
9a6c41 |
+ la_head.length = 0;
|
|
|
9a6c41 |
+ la_head.indices = NULL;
|
|
|
9a6c41 |
+ }
|
|
|
9a6c41 |
+ if (numdisks > 0) {
|
|
|
9a6c41 |
+ int i;
|
|
|
9a6c41 |
+ head.length = 0;
|
|
|
9a6c41 |
+ numdisks = 0;
|
|
|
9a6c41 |
+ for (i = 0; i < maxdisks; i++) { /* init/erase disk db */
|
|
|
9a6c41 |
+ disks[i].syspath[0] = 0;
|
|
|
9a6c41 |
+ disks[i].name[0] = 0;
|
|
|
9a6c41 |
+ disks[i].shortname[0] = 0;
|
|
|
9a6c41 |
+ disks[i].major = -1;
|
|
|
9a6c41 |
+ disks[i].minor = -1;
|
|
|
9a6c41 |
+ }
|
|
|
9a6c41 |
+ }
|
|
|
9a6c41 |
+}
|
|
|
9a6c41 |
+static int
|
|
|
9a6c41 |
+disk_exists(char *path)
|
|
|
9a6c41 |
{
|
|
|
9a6c41 |
- int major;
|
|
|
9a6c41 |
- int minor;
|
|
|
9a6c41 |
- unsigned long blocks;
|
|
|
9a6c41 |
- char name[256];
|
|
|
9a6c41 |
- unsigned long rio;
|
|
|
9a6c41 |
- unsigned long rmerge;
|
|
|
9a6c41 |
- unsigned long rsect;
|
|
|
9a6c41 |
- unsigned long ruse;
|
|
|
9a6c41 |
- unsigned long wio;
|
|
|
9a6c41 |
- unsigned long wmerge;
|
|
|
9a6c41 |
- unsigned long wsect;
|
|
|
9a6c41 |
- unsigned long wuse;
|
|
|
9a6c41 |
- unsigned long running;
|
|
|
9a6c41 |
- unsigned long use;
|
|
|
9a6c41 |
- unsigned long aveq;
|
|
|
9a6c41 |
-} linux_diskio;
|
|
|
9a6c41 |
+ int index;
|
|
|
9a6c41 |
+ for(index = 0; index < numdisks; index++) {
|
|
|
9a6c41 |
+ DEBUGMSGTL(("ucd-snmp/disk", "Checking for %s. Found %s at %d\n", path, disks[index].syspath, index));
|
|
|
9a6c41 |
+ if(strcmp(path, disks[index].syspath) == 0) {
|
|
|
9a6c41 |
+ return index;
|
|
|
9a6c41 |
+ }
|
|
|
9a6c41 |
+ }
|
|
|
9a6c41 |
+ return -1;
|
|
|
9a6c41 |
+}
|
|
|
9a6c41 |
|
|
|
9a6c41 |
-/* disk load averages */
|
|
|
9a6c41 |
-typedef struct linux_diskio_la
|
|
|
9a6c41 |
-{
|
|
|
9a6c41 |
- unsigned long use_prev;
|
|
|
9a6c41 |
- double la1, la5, la15;
|
|
|
9a6c41 |
-} linux_diskio_la;
|
|
|
9a6c41 |
+static void
|
|
|
9a6c41 |
+add_device(char *path, int addNewDisks )
|
|
|
9a6c41 |
+ {
|
|
|
9a6c41 |
+ int index;
|
|
|
9a6c41 |
+ char device[STRMAX];
|
|
|
9a6c41 |
+ char syspath[STRMAX];
|
|
|
9a6c41 |
+ char *basename;
|
|
|
9a6c41 |
+ struct stat stbuf;
|
|
|
9a6c41 |
|
|
|
9a6c41 |
-typedef struct linux_diskio_header
|
|
|
9a6c41 |
-{
|
|
|
9a6c41 |
- linux_diskio* indices;
|
|
|
9a6c41 |
- int length;
|
|
|
9a6c41 |
- int alloc;
|
|
|
9a6c41 |
-} linux_diskio_header;
|
|
|
9a6c41 |
+ if (!path || !strcmp(path, "none")) {
|
|
|
9a6c41 |
+ DEBUGMSGTL(("ucd-snmp/diskio", "Skipping null path device (%s)\n", path));
|
|
|
9a6c41 |
+ return;
|
|
|
9a6c41 |
+ }
|
|
|
9a6c41 |
+ if (numdisks == maxdisks) {
|
|
|
9a6c41 |
+ if (maxdisks == 0) {
|
|
|
9a6c41 |
+ maxdisks = 50;
|
|
|
9a6c41 |
+ disks = malloc(maxdisks * sizeof(struct diskiopart));
|
|
|
9a6c41 |
+ if (!disks) {
|
|
|
9a6c41 |
+ config_perror("malloc failed for new disko allocation.");
|
|
|
9a6c41 |
+ netsnmp_config_error("\tignoring: %s", path);
|
|
|
9a6c41 |
+ return;
|
|
|
9a6c41 |
+ }
|
|
|
9a6c41 |
+ memset(disks, 0, maxdisks * sizeof(struct diskiopart));
|
|
|
9a6c41 |
+ } else {
|
|
|
9a6c41 |
+ maxdisks *= 2;
|
|
|
9a6c41 |
+ disks = realloc(disks, maxdisks * sizeof(struct diskiopart));
|
|
|
9a6c41 |
+ if (!disks) {
|
|
|
9a6c41 |
+ config_perror("malloc failed for new disko allocation.");
|
|
|
9a6c41 |
+ netsnmp_config_error("\tignoring: %s", path);
|
|
|
9a6c41 |
+ return;
|
|
|
9a6c41 |
+ }
|
|
|
9a6c41 |
+ memset(disks + maxdisks/2, 0, maxdisks/2 * sizeof(struct diskiopart));
|
|
|
9a6c41 |
+ }
|
|
|
9a6c41 |
+ }
|
|
|
9a6c41 |
|
|
|
9a6c41 |
-typedef struct linux_diskio_la_header
|
|
|
9a6c41 |
-{
|
|
|
9a6c41 |
- linux_diskio_la * indices;
|
|
|
9a6c41 |
- int length;
|
|
|
9a6c41 |
-} linux_diskio_la_header;
|
|
|
9a6c41 |
+ /* first find the path for this device */
|
|
|
9a6c41 |
+ device[0]='\0';
|
|
|
9a6c41 |
+ if ( *path != '/' ) {
|
|
|
9a6c41 |
+ strlcpy(device, "/dev/", STRMAX - 1 );
|
|
|
9a6c41 |
+ }
|
|
|
9a6c41 |
+ strncat(device, path, STRMAX - 1 );
|
|
|
9a6c41 |
+
|
|
|
9a6c41 |
+ /* check for /dev existence */
|
|
|
9a6c41 |
+ if ( stat(device,&stbuf)!=0 ) { /* ENOENT */
|
|
|
9a6c41 |
+ config_perror("diskio path does not exist.");
|
|
|
9a6c41 |
+ netsnmp_config_error("\tignoring: %s", path);
|
|
|
9a6c41 |
+ return;
|
|
|
9a6c41 |
+ }
|
|
|
9a6c41 |
+ else if ( ! S_ISBLK(stbuf.st_mode) ) { /* ENODEV */
|
|
|
9a6c41 |
+ config_perror("diskio path is not a device.");
|
|
|
9a6c41 |
+ netsnmp_config_error("\tignoring: %s", path);
|
|
|
9a6c41 |
+ return;
|
|
|
9a6c41 |
+ }
|
|
|
9a6c41 |
|
|
|
9a6c41 |
-static linux_diskio_header head;
|
|
|
9a6c41 |
-static linux_diskio_la_header la_head;
|
|
|
9a6c41 |
+ /* either came with a slash or we just put one there, so the following always works */
|
|
|
9a6c41 |
+ basename = strrchr(device, '/' )+1;
|
|
|
9a6c41 |
+ /* construct a sys path using the device numbers to avoid having to disambiguate the various text forms */
|
|
|
9a6c41 |
+ snprintf( syspath, STRMAX - 1, "/sys/dev/block/%d:%d/stat", major(stbuf.st_rdev), minor(stbuf.st_rdev) );
|
|
|
9a6c41 |
+ DEBUGMSGTL(("ucd-snmp/diskio", " monitoring sys path (%s)\n", syspath));
|
|
|
9a6c41 |
+
|
|
|
9a6c41 |
+ index = disk_exists(syspath);
|
|
|
9a6c41 |
+
|
|
|
9a6c41 |
+ if(index == -1 && addNewDisks){
|
|
|
9a6c41 |
+ /* The following buffers are cleared above, no need to add '\0' */
|
|
|
9a6c41 |
+ strlcpy(disks[numdisks].syspath, syspath, sizeof(disks[numdisks].syspath) - 1);
|
|
|
9a6c41 |
+ strlcpy(disks[numdisks].name, path, sizeof(disks[numdisks].name) - 1);
|
|
|
9a6c41 |
+ strlcpy(disks[numdisks].shortname, basename, sizeof(disks[numdisks].shortname) - 1);
|
|
|
9a6c41 |
+ disks[numdisks].major = major(stbuf.st_rdev);
|
|
|
9a6c41 |
+ disks[numdisks].minor = minor(stbuf.st_rdev);
|
|
|
9a6c41 |
+ numdisks++;
|
|
|
9a6c41 |
+ }
|
|
|
9a6c41 |
+}
|
|
|
9a6c41 |
+
|
|
|
9a6c41 |
+static void
|
|
|
9a6c41 |
+diskio_parse_config_disks(const char *token, char *cptr)
|
|
|
9a6c41 |
+ {
|
|
|
9a6c41 |
+#if HAVE_FSTAB_H || HAVE_GETMNTENT || HAVE_STATFS
|
|
|
9a6c41 |
+ char path[STRMAX];
|
|
|
9a6c41 |
+
|
|
|
9a6c41 |
+
|
|
|
9a6c41 |
+ /*
|
|
|
9a6c41 |
+ * read disk path (eg, /1 or /usr)
|
|
|
9a6c41 |
+ */
|
|
|
9a6c41 |
+ copy_nword(cptr, path, sizeof(path));
|
|
|
9a6c41 |
+
|
|
|
9a6c41 |
+ /* TODO: we may include regular expressions in future */
|
|
|
9a6c41 |
+ /*
|
|
|
9a6c41 |
+ * check if the disk already exists, if so then modify its
|
|
|
9a6c41 |
+ * parameters. if it does not exist then add it
|
|
|
9a6c41 |
+ */
|
|
|
9a6c41 |
+ add_device(path, 1);
|
|
|
9a6c41 |
+#endif /* HAVE_FSTAB_H || HAVE_GETMNTENT || HAVE_STATFS */
|
|
|
9a6c41 |
+}
|
|
|
9a6c41 |
|
|
|
9a6c41 |
void devla_getstats(unsigned int regno, void * dummy) {
|
|
|
9a6c41 |
|
|
|
9a6c41 |
@@ -976,6 +1130,47 @@ int is_excluded(const char *name)
|
|
|
9a6c41 |
return 0;
|
|
|
9a6c41 |
}
|
|
|
9a6c41 |
|
|
|
9a6c41 |
+static int get_sysfs_stats()
|
|
|
9a6c41 |
+{
|
|
|
9a6c41 |
+ int i;
|
|
|
9a6c41 |
+ char buffer[1024];
|
|
|
9a6c41 |
+
|
|
|
9a6c41 |
+ head.length = 0;
|
|
|
9a6c41 |
+
|
|
|
9a6c41 |
+ for(i = 0; i < numdisks; i++) {
|
|
|
9a6c41 |
+ FILE *f = fopen(disks[i].syspath, "r");
|
|
|
9a6c41 |
+ if ( f == NULL ) {
|
|
|
9a6c41 |
+ DEBUGMSGTL(("ucd-snmp/diskio", "Can't open %s, skipping", disks[i].syspath));
|
|
|
9a6c41 |
+ continue;
|
|
|
9a6c41 |
+ }
|
|
|
9a6c41 |
+ if (fgets(buffer, sizeof(buffer), f) == NULL) {
|
|
|
9a6c41 |
+ DEBUGMSGTL(("ucd-snmp/diskio", "Can't read %s, skipping", disks[i].syspath));
|
|
|
9a6c41 |
+ fclose(f);
|
|
|
9a6c41 |
+ continue;
|
|
|
9a6c41 |
+ }
|
|
|
9a6c41 |
+
|
|
|
9a6c41 |
+ linux_diskio* pTemp;
|
|
|
9a6c41 |
+ if (head.length == head.alloc) {
|
|
|
9a6c41 |
+ head.alloc += DISK_INCR;
|
|
|
9a6c41 |
+ head.indices = (linux_diskio *) realloc(head.indices, head.alloc*sizeof(linux_diskio));
|
|
|
9a6c41 |
+ }
|
|
|
9a6c41 |
+ pTemp = &head.indices[head.length];
|
|
|
9a6c41 |
+ pTemp->major = disks[i].major;
|
|
|
9a6c41 |
+ pTemp->minor = disks[i].minor;
|
|
|
9a6c41 |
+ strlcpy( pTemp->name, disks[i].shortname, sizeof(pTemp->name) - 1 );
|
|
|
9a6c41 |
+ if (sscanf (buffer, "%*[ \n\t]%lu%*[ \n\t]%lu%*[ \n\t]%lu%*[ \n\t]%lu%*[ \n\t]%lu%*[ \n\t]%lu%*[ \n\t]%lu%*[ \n\t]%lu%*[ \n\t]%lu%*[ \n\t]%lu%*[ \n\t]%lu\n",
|
|
|
9a6c41 |
+ &pTemp->rio, &pTemp->rmerge, &pTemp->rsect, &pTemp->ruse,
|
|
|
9a6c41 |
+ &pTemp->wio, &pTemp->wmerge, &pTemp->wsect, &pTemp->wuse,
|
|
|
9a6c41 |
+ &pTemp->running, &pTemp->use, &pTemp->aveq) != 11)
|
|
|
9a6c41 |
+ sscanf (buffer, "%*[ \n\t]%lu%*[ \n\t]%lu%*[ \n\t]%lu%*[ \n\t]%lu\n",
|
|
|
9a6c41 |
+ &pTemp->rio, &pTemp->rsect,
|
|
|
9a6c41 |
+ &pTemp->wio, &pTemp->wsect);
|
|
|
9a6c41 |
+ head.length++;
|
|
|
9a6c41 |
+ fclose(f);
|
|
|
9a6c41 |
+ }
|
|
|
9a6c41 |
+ return 0;
|
|
|
9a6c41 |
+}
|
|
|
9a6c41 |
+
|
|
|
9a6c41 |
static int
|
|
|
9a6c41 |
getstats(void)
|
|
|
9a6c41 |
{
|
|
|
9a6c41 |
@@ -995,6 +1189,14 @@ getstats(void)
|
|
|
9a6c41 |
|
|
|
9a6c41 |
memset(head.indices, 0, head.alloc*sizeof(linux_diskio));
|
|
|
9a6c41 |
|
|
|
9a6c41 |
+ if (numdisks>0) {
|
|
|
9a6c41 |
+ /* 'diskio' configuration is used - go through the whitelist only and
|
|
|
9a6c41 |
+ * read /sys/dev/block/xxx */
|
|
|
9a6c41 |
+ cache_time = now;
|
|
|
9a6c41 |
+ return get_sysfs_stats();
|
|
|
9a6c41 |
+ }
|
|
|
9a6c41 |
+ /* 'diskio' configuration is not used - report all devices */
|
|
|
9a6c41 |
+
|
|
|
9a6c41 |
/* Is this a 2.6 kernel? */
|
|
|
9a6c41 |
parts = fopen("/proc/diskstats", "r");
|
|
|
9a6c41 |
if (parts) {
|
|
|
9a6c41 |
@@ -1111,13 +1313,22 @@ var_diskio(struct variable * vp,
|
|
|
9a6c41 |
long_ret = head.indices[indx].wio & 0xffffffff;
|
|
|
9a6c41 |
return (u_char *) & long_ret;
|
|
|
9a6c41 |
case DISKIO_LA1:
|
|
|
9a6c41 |
- long_ret = la_head.indices[indx].la1;
|
|
|
9a6c41 |
+ if (la_head.length > indx)
|
|
|
9a6c41 |
+ long_ret = la_head.indices[indx].la1;
|
|
|
9a6c41 |
+ else
|
|
|
9a6c41 |
+ long_ret = 0;
|
|
|
9a6c41 |
return (u_char *) & long_ret;
|
|
|
9a6c41 |
case DISKIO_LA5:
|
|
|
9a6c41 |
- long_ret = la_head.indices[indx].la5;
|
|
|
9a6c41 |
+ if (la_head.length > indx)
|
|
|
9a6c41 |
+ long_ret = la_head.indices[indx].la5;
|
|
|
9a6c41 |
+ else
|
|
|
9a6c41 |
+ long_ret = 0;
|
|
|
9a6c41 |
return (u_char *) & long_ret;
|
|
|
9a6c41 |
case DISKIO_LA15:
|
|
|
9a6c41 |
- long_ret = la_head.indices[indx].la15;
|
|
|
9a6c41 |
+ if (la_head.length > indx)
|
|
|
9a6c41 |
+ long_ret = la_head.indices[indx].la15;
|
|
|
9a6c41 |
+ else
|
|
|
9a6c41 |
+ long_ret = 0;
|
|
|
9a6c41 |
return (u_char *) & long_ret;
|
|
|
9a6c41 |
case DISKIO_NREADX:
|
|
|
9a6c41 |
*var_len = sizeof(struct counter64);
|
|
|
9a6c41 |
diff -up net-snmp-5.7.2/man/snmpd.conf.5.def.test net-snmp-5.7.2/man/snmpd.conf.5.def
|
|
|
9a6c41 |
--- net-snmp-5.7.2/man/snmpd.conf.5.def.test 2015-06-18 15:13:31.249470179 +0200
|
|
|
9a6c41 |
+++ net-snmp-5.7.2/man/snmpd.conf.5.def 2015-06-18 15:16:45.481423115 +0200
|
|
|
9a6c41 |
@@ -715,6 +715,15 @@ e.g. "loop0"
|
|
|
9a6c41 |
.IP "diskio_exclude_ram yes"
|
|
|
9a6c41 |
Excludes all LInux ramdisk block devices, whose names start with "ram", e.g.
|
|
|
9a6c41 |
"ram0"
|
|
|
9a6c41 |
+.PP
|
|
|
9a6c41 |
+On Linux systems, it is possible to report only explicitly whitelisted
|
|
|
9a6c41 |
+devices. It may take significant amount of time to process diskIOTable data
|
|
|
9a6c41 |
+on systems with tens of thousands of block devices and whitelisting only the
|
|
|
9a6c41 |
+important ones avoids large CPU consumption.
|
|
|
9a6c41 |
+.IP "diskio <device>"
|
|
|
9a6c41 |
+Enables whitelisting of devices and adds the device to the whitelist. Only
|
|
|
9a6c41 |
+explicitly whitelisted devices will be reported. This option may be used
|
|
|
9a6c41 |
+multiple times.
|
|
|
9a6c41 |
.SS System Load Monitoring
|
|
|
9a6c41 |
This requires that the agent was built with support for either the
|
|
|
9a6c41 |
\fIucd\-snmp/loadave\fR module or the \fIucd\-snmp/memory\fR module
|
|
|
9a6c41 |
|
|
|
9a6c41 |
|
|
|
9a6c41 |
commit 59f9f3387dab4238114804a0be9e4c15667d868c
|
|
|
9a6c41 |
Author: Jan Safranek <jsafranek@users.sourceforge.net>
|
|
|
9a6c41 |
Date: Fri Jun 19 09:29:06 2015 +0200
|
|
|
9a6c41 |
|
|
|
9a6c41 |
Fixed memory leak on realloc failure.
|
|
|
9a6c41 |
|
|
|
9a6c41 |
Found by Coverity.
|
|
|
9a6c41 |
|
|
|
9a6c41 |
diff --git a/agent/mibgroup/ucd-snmp/diskio.c b/agent/mibgroup/ucd-snmp/diskio.c
|
|
|
9a6c41 |
index f04d5c5..58163d8 100644
|
|
|
9a6c41 |
--- a/agent/mibgroup/ucd-snmp/diskio.c
|
|
|
9a6c41 |
+++ b/agent/mibgroup/ucd-snmp/diskio.c
|
|
|
9a6c41 |
@@ -405,13 +405,17 @@ add_device(char *path, int addNewDisks )
|
|
|
9a6c41 |
}
|
|
|
9a6c41 |
memset(disks, 0, maxdisks * sizeof(struct diskiopart));
|
|
|
9a6c41 |
} else {
|
|
|
9a6c41 |
+ struct diskiopart *newdisks;
|
|
|
9a6c41 |
maxdisks *= 2;
|
|
|
9a6c41 |
- disks = realloc(disks, maxdisks * sizeof(struct diskiopart));
|
|
|
9a6c41 |
- if (!disks) {
|
|
|
9a6c41 |
+ newdisks = realloc(disks, maxdisks * sizeof(struct diskiopart));
|
|
|
9a6c41 |
+ if (!newdisks) {
|
|
|
9a6c41 |
+ free(disks);
|
|
|
9a6c41 |
+ disks = NULL;
|
|
|
9a6c41 |
config_perror("malloc failed for new disko allocation.");
|
|
|
9a6c41 |
netsnmp_config_error("\tignoring: %s", path);
|
|
|
9a6c41 |
return;
|
|
|
9a6c41 |
}
|
|
|
9a6c41 |
+ disks = newdisks;
|
|
|
9a6c41 |
memset(disks + maxdisks/2, 0, maxdisks/2 * sizeof(struct diskiopart));
|
|
|
9a6c41 |
}
|
|
|
9a6c41 |
}
|