diff --git a/agent/mibgroup/host/data_access/swrun.c b/agent/mibgroup/host/data_access/swrun.c index d18ea5f..60ad5b4 100644 --- agent/mibgroup/host/data_access/swrun.c +++ agent/mibgroup/host/data_access/swrun.c @@ -75,10 +75,27 @@ shutdown_swrun(void) } int -swrun_count_processes( void ) +swrun_count_processes(int include_kthreads) { + netsnmp_swrun_entry *entry; + netsnmp_iterator *it; + int i = 0; + netsnmp_cache_check_and_reload(swrun_cache); - return ( swrun_container ? CONTAINER_SIZE(swrun_container) : 0 ); + if ( !swrun_container ) + return 0; /* or -1 */ + + if (include_kthreads) + return ( swrun_container ? CONTAINER_SIZE(swrun_container) : 0 ); + + it = CONTAINER_ITERATOR( swrun_container ); + while ((entry = (netsnmp_swrun_entry*)ITERATOR_NEXT( it )) != NULL) { + if (4 == entry->hrSWRunType) + i++; + } + ITERATOR_RELEASE( it ); + + return i; } #ifndef NETSNMP_FEATURE_REMOVE_SWRUN_MAX_PROCESSES diff --git a/agent/mibgroup/host/hr_system.c b/agent/mibgroup/host/hr_system.c index d99cc7d..e853779 100644 --- agent/mibgroup/host/hr_system.c +++ agent/mibgroup/host/hr_system.c @@ -24,6 +24,7 @@ #include #include +#include #include "host.h" #include "host_res.h" @@ -114,7 +115,14 @@ static long get_max_solaris_processes(void); static int get_load_dev(void); static int count_users(void); extern int count_processes(void); -extern int swrun_count_processes(void); +#if USING_HOST_DATA_ACCESS_SWRUN_MODULE +static int count_kthreads = 0; + +static void parse_count_kthreads(const char *token, const char *line) +{ + count_kthreads = atoi(line); +} +#endif /********************* * @@ -194,6 +202,11 @@ init_hr_system(void) #ifdef NPROC_SYMBOL auto_nlist(NPROC_SYMBOL, 0, 0); #endif +#if USING_HOST_DATA_ACCESS_SWRUN_MODULE + snmpd_register_const_config_handler("count_kthreads", + parse_count_kthreads, NULL, + "0|1 0 to exclude kernel threads from hrSystemProcesses.0"); +#endif REGISTER_MIB("host/hr_system", hrsystem_variables, variable2, hrsystem_variables_oid); @@ -317,7 +330,7 @@ var_hrsys(struct variable * vp, return (u_char *) & long_return; case HRSYS_PROCS: #if USING_HOST_DATA_ACCESS_SWRUN_MODULE - long_return = swrun_count_processes(); + long_return = swrun_count_processes(count_kthreads); #elif USING_HOST_HR_SWRUN_MODULE long_return = count_processes(); #else diff --git a/include/net-snmp/data_access/swrun.h b/include/net-snmp/data_access/swrun.h index 3e15c41..4f768ac 100644 --- include/net-snmp/data_access/swrun.h +++ include/net-snmp/data_access/swrun.h @@ -85,7 +85,7 @@ extern "C" { void netsnmp_swrun_entry_free(netsnmp_swrun_entry *entry); - int swrun_count_processes( void ); + int swrun_count_processes( int include_kthreads ); int swrun_max_processes( void ); int swrun_count_processes_by_name( char *name );