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