|
|
8a419f |
commit e3fc76e0ae502fb8ef0aac87eee237db9d9690f5
|
|
|
8a419f |
Author: Jan Safranek <jsafranek@users.sourceforge.net>
|
|
|
8a419f |
Date: Tue Jul 9 14:26:59 2013 +0200
|
|
|
8a419f |
|
|
|
8a419f |
CHANGES: snmpd: Make UCD-SNMP::dskTable dynamic if includeAllDisks is set.
|
|
|
8a419f |
|
|
|
8a419f |
diff --git a/agent/mibgroup/ucd-snmp/disk_hw.c b/agent/mibgroup/ucd-snmp/disk_hw.c
|
|
|
8a419f |
index ea37610..f7911d9 100644
|
|
|
8a419f |
--- a/agent/mibgroup/ucd-snmp/disk_hw.c
|
|
|
8a419f |
+++ b/agent/mibgroup/ucd-snmp/disk_hw.c
|
|
|
8a419f |
@@ -55,6 +55,7 @@ static netsnmp_fsys_info ** _expand_disk_array( char *cptr );
|
|
|
8a419f |
|
|
|
8a419f |
int numdisks;
|
|
|
8a419f |
int allDisksIncluded = 0;
|
|
|
8a419f |
+int allDisksMinPercent = 0;
|
|
|
8a419f |
int maxdisks = 0;
|
|
|
8a419f |
netsnmp_fsys_info **disks = NULL;
|
|
|
8a419f |
|
|
|
8a419f |
@@ -119,6 +120,7 @@ init_disk_hw(void)
|
|
|
8a419f |
disk_free_config,
|
|
|
8a419f |
"minpercent%");
|
|
|
8a419f |
allDisksIncluded = 0;
|
|
|
8a419f |
+ allDisksMinPercent = 0;
|
|
|
8a419f |
}
|
|
|
8a419f |
|
|
|
8a419f |
static void
|
|
|
8a419f |
@@ -140,6 +142,7 @@ disk_free_config(void)
|
|
|
8a419f |
maxdisks = numdisks = 0;
|
|
|
8a419f |
}
|
|
|
8a419f |
allDisksIncluded = 0;
|
|
|
8a419f |
+ allDisksMinPercent = 0;
|
|
|
8a419f |
}
|
|
|
8a419f |
|
|
|
8a419f |
static void
|
|
|
8a419f |
@@ -199,8 +202,7 @@ static void
|
|
|
8a419f |
disk_parse_config_all(const char *token, char *cptr)
|
|
|
8a419f |
{
|
|
|
8a419f |
int minpercent = DISKMINPERCENT;
|
|
|
8a419f |
- netsnmp_fsys_info *entry;
|
|
|
8a419f |
-
|
|
|
8a419f |
+
|
|
|
8a419f |
/*
|
|
|
8a419f |
* read the minimum disk usage percent
|
|
|
8a419f |
*/
|
|
|
8a419f |
@@ -220,30 +222,36 @@ disk_parse_config_all(const char *token, char *cptr)
|
|
|
8a419f |
netsnmp_config_error("\tignoring: includeAllDisks %s", cptr);
|
|
|
8a419f |
}
|
|
|
8a419f |
else {
|
|
|
8a419f |
-
|
|
|
8a419f |
- netsnmp_fsys_load( NULL, NULL ); /* Prime the fsys H/W module */
|
|
|
8a419f |
- for ( entry = netsnmp_fsys_get_first();
|
|
|
8a419f |
- entry != NULL;
|
|
|
8a419f |
- entry = netsnmp_fsys_get_next( entry )) {
|
|
|
8a419f |
-
|
|
|
8a419f |
- if ( !(entry->flags & NETSNMP_FS_FLAG_ACTIVE ))
|
|
|
8a419f |
- continue;
|
|
|
8a419f |
- entry->minspace = -1;
|
|
|
8a419f |
- entry->minpercent = minpercent;
|
|
|
8a419f |
- entry->flags |= NETSNMP_FS_FLAG_UCD;
|
|
|
8a419f |
- /*
|
|
|
8a419f |
- * Ensure there is space for the new entry
|
|
|
8a419f |
- */
|
|
|
8a419f |
- if (numdisks == maxdisks) {
|
|
|
8a419f |
- if (!_expand_disk_array( entry->device ))
|
|
|
8a419f |
- return;
|
|
|
8a419f |
- }
|
|
|
8a419f |
- disks[numdisks++] = entry;
|
|
|
8a419f |
- }
|
|
|
8a419f |
allDisksIncluded = 1;
|
|
|
8a419f |
+ allDisksMinPercent = minpercent;
|
|
|
8a419f |
}
|
|
|
8a419f |
}
|
|
|
8a419f |
|
|
|
8a419f |
+/* add new entries to dskTable dynamically */
|
|
|
8a419f |
+static void _refresh_disks(int minpercent)
|
|
|
8a419f |
+{
|
|
|
8a419f |
+ netsnmp_fsys_info *entry;
|
|
|
8a419f |
+
|
|
|
8a419f |
+ for ( entry = netsnmp_fsys_get_first();
|
|
|
8a419f |
+ entry != NULL;
|
|
|
8a419f |
+ entry = netsnmp_fsys_get_next( entry )) {
|
|
|
8a419f |
+
|
|
|
8a419f |
+ if (!(entry->flags & NETSNMP_FS_FLAG_UCD)) {
|
|
|
8a419f |
+ /* this is new disk, add it to the table */
|
|
|
8a419f |
+ entry->minspace = -1;
|
|
|
8a419f |
+ entry->minpercent = minpercent;
|
|
|
8a419f |
+ entry->flags |= NETSNMP_FS_FLAG_UCD;
|
|
|
8a419f |
+ /*
|
|
|
8a419f |
+ * Ensure there is space for the new entry
|
|
|
8a419f |
+ */
|
|
|
8a419f |
+ if (numdisks == maxdisks) {
|
|
|
8a419f |
+ if (!_expand_disk_array( entry->device ))
|
|
|
8a419f |
+ return;
|
|
|
8a419f |
+ }
|
|
|
8a419f |
+ disks[numdisks++] = entry;
|
|
|
8a419f |
+ }
|
|
|
8a419f |
+ }
|
|
|
8a419f |
+}
|
|
|
8a419f |
|
|
|
8a419f |
static int _percent( unsigned long long value, unsigned long long total ) {
|
|
|
8a419f |
float v=value, t=total, pct;
|
|
|
8a419f |
@@ -301,7 +309,7 @@ var_extensible_disk(struct variable *vp,
|
|
|
8a419f |
size_t * var_len, WriteMethod ** write_method)
|
|
|
8a419f |
{
|
|
|
8a419f |
int disknum = 0;
|
|
|
8a419f |
- netsnmp_fsys_info *entry;
|
|
|
8a419f |
+ netsnmp_fsys_info *entry;
|
|
|
8a419f |
unsigned long long val;
|
|
|
8a419f |
static long long_ret;
|
|
|
8a419f |
static char errmsg[300];
|
|
|
8a419f |
@@ -310,6 +318,8 @@ var_extensible_disk(struct variable *vp,
|
|
|
8a419f |
/* Update the fsys H/W module */
|
|
|
8a419f |
cache = netsnmp_fsys_get_cache();
|
|
|
8a419f |
netsnmp_cache_check_and_reload(cache);
|
|
|
8a419f |
+ if (allDisksIncluded)
|
|
|
8a419f |
+ _refresh_disks(allDisksMinPercent);
|
|
|
8a419f |
|
|
|
8a419f |
tryAgain:
|
|
|
8a419f |
if (header_simple_table
|
|
|
8a419f |
@@ -318,9 +328,14 @@ tryAgain:
|
|
|
8a419f |
disknum = name[*length - 1] - 1;
|
|
|
8a419f |
entry = disks[disknum];
|
|
|
8a419f |
if ( !entry ) {
|
|
|
8a419f |
- if (!exact || !(entry->flags & NETSNMP_FS_FLAG_UCD))
|
|
|
8a419f |
- goto tryAgain;
|
|
|
8a419f |
- return NULL;
|
|
|
8a419f |
+ if (exact)
|
|
|
8a419f |
+ return NULL;
|
|
|
8a419f |
+ goto tryAgain;
|
|
|
8a419f |
+ }
|
|
|
8a419f |
+ if (!(entry->flags & NETSNMP_FS_FLAG_ACTIVE) || !(entry->flags & NETSNMP_FS_FLAG_UCD)) {
|
|
|
8a419f |
+ if (exact)
|
|
|
8a419f |
+ return NULL;
|
|
|
8a419f |
+ goto tryAgain;
|
|
|
8a419f |
}
|
|
|
8a419f |
|
|
|
8a419f |
switch (vp->magic) {
|
|
|
8a419f |
diff --git a/man/snmpd.conf.5.def b/man/snmpd.conf.5.def
|
|
|
8a419f |
index 5f85f72..d2caf9c 100644
|
|
|
8a419f |
--- a/man/snmpd.conf.5.def
|
|
|
8a419f |
+++ b/man/snmpd.conf.5.def
|
|
|
8a419f |
@@ -652,6 +652,8 @@ This requires that the agent was built with support for the
|
|
|
8a419f |
default build configuration).
|
|
|
8a419f |
.IP "disk PATH [ MINSPACE | MINPERCENT% ]"
|
|
|
8a419f |
monitors the disk mounted at PATH for available disk space.
|
|
|
8a419f |
+Disks mounted after the agent has started will not be monitored,
|
|
|
8a419f |
+unless \fIincludeAllDisks\fR option is specified.
|
|
|
8a419f |
.IP
|
|
|
8a419f |
The minimum threshold can either be specified in kB (MINSPACE) or
|
|
|
8a419f |
as a percentage of the total disk (MINPERCENT% with a '%' character),
|
|
|
8a419f |
@@ -668,6 +670,9 @@ the problem - see the DisMan Event MIB section later.
|
|
|
8a419f |
.IP "includeAllDisks MINPERCENT%"
|
|
|
8a419f |
configures monitoring of all disks found on the system,
|
|
|
8a419f |
using the specified (percentage) threshold.
|
|
|
8a419f |
+The \fCdskTable\fR is dynamically updated, unmounted disks
|
|
|
8a419f |
+disappear from the table and newly mounted disks are
|
|
|
8a419f |
+added to the table.
|
|
|
8a419f |
The threshold for individual disks can be adjusted using suitable
|
|
|
8a419f |
\fIdisk\fR directives (which can come either before or after the
|
|
|
8a419f |
\fIincludeAllDisks\fR directive).
|
|
|
8a419f |
@@ -680,12 +685,8 @@ may affect the indexing of the \fCdskTable\fR.
|
|
|
8a419f |
Only one \fIincludeAllDisks\fR directive should be specified - any
|
|
|
8a419f |
subsequent copies will be ignored.
|
|
|
8a419f |
.IP
|
|
|
8a419f |
-The list of mounted disks will be determined when the agent starts using the
|
|
|
8a419f |
-setmntent(3) and getmntent(3), or fopen(3) and getmntent(3), or
|
|
|
8a419f |
-setfsent(3) and getfsent(3) system calls. If none of the above
|
|
|
8a419f |
-system calls are available then the root partition "/"
|
|
|
8a419f |
-(which is assumed to exist on any UNIX based system) will be monitored.
|
|
|
8a419f |
-Disks mounted after the agent has started will not be monitored.
|
|
|
8a419f |
+The list of mounted disks will be determined from
|
|
|
8a419f |
+HOST-RESOURCES-MIB::hrFSTable.
|
|
|
8a419f |
.\"
|
|
|
8a419f |
.\" XXX - unless the config is re-read ??
|
|
|
8a419f |
.\"
|