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