2011-12-09 Ramon Novoa <rnovoa@artica.es>
* windows/pandora_wmi.cc: Added a debug message. * modules/pandora_module_perfcounter.cc, modules/pandora_module_perfcounter.h, modules/pandora_module_factory.cc: Added support to read the 'cooked' value of a performance counter. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@5244 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
parent
5a7df039d0
commit
345c3de2cd
|
@ -1,3 +1,12 @@
|
|||
2011-12-09 Ramon Novoa <rnovoa@artica.es>
|
||||
|
||||
* windows/pandora_wmi.cc: Added a debug message.
|
||||
|
||||
* modules/pandora_module_perfcounter.cc,
|
||||
modules/pandora_module_perfcounter.h,
|
||||
modules/pandora_module_factory.cc: Added support to read the
|
||||
'cooked' value of a performance counter.
|
||||
|
||||
2011-11-30 Ramon Novoa <rnovoa@artica.es>
|
||||
|
||||
* modules/pandora_module_logevent.cc,
|
||||
|
|
|
@ -84,6 +84,7 @@ using namespace Pandora_Strutils;
|
|||
#define TOKEN_STARTDELAY ("module_startdelay ")
|
||||
#define TOKEN_RETRYDELAY ("module_retrydelay ")
|
||||
#define TOKEN_PERFCOUNTER ("module_perfcounter ")
|
||||
#define TOKEN_COOKED ("module_cooked ")
|
||||
#define TOKEN_TCPCHECK ("module_tcpcheck ")
|
||||
#define TOKEN_PORT ("module_port ")
|
||||
#define TOKEN_TIMEOUT ("module_timeout ")
|
||||
|
@ -101,7 +102,7 @@ using namespace Pandora_Strutils;
|
|||
#define TOKEN_SNMPGET ("module_snmpget")
|
||||
#define TOKEN_SNMPVERSION ("module_snmp_version ")
|
||||
#define TOKEN_SNMPCOMMUNITY ("module_snmp_community ")
|
||||
#define TOKEN_SNMPAGENT ("module_snmp_agent ")
|
||||
#define TOKEN_SNMPAGENT ("module_snmp_agent ")
|
||||
#define TOKEN_SNMPOID ("module_snmp_oid ")
|
||||
#define TOKEN_ADVANCEDOPTIONS ("module_advanced_options ")
|
||||
|
||||
|
@ -152,7 +153,7 @@ Pandora_Module_Factory::getModuleFromDefinition (string definition) {
|
|||
string module_disabled, module_min_ff_event, module_noseekeof;
|
||||
string module_ping, module_ping_count, module_ping_timeout;
|
||||
string module_snmpget, module_snmp_version, module_snmp_community, module_snmp_agent, module_snmp_oid;
|
||||
string module_advanced_options;
|
||||
string module_advanced_options, module_cooked;
|
||||
Pandora_Module *module;
|
||||
bool numeric;
|
||||
Module_Type type;
|
||||
|
@ -215,6 +216,7 @@ Pandora_Module_Factory::getModuleFromDefinition (string definition) {
|
|||
module_snmp_agent = "";
|
||||
module_snmp_oid = "";
|
||||
module_advanced_options = "";
|
||||
module_cooked = "";
|
||||
|
||||
stringtok (tokens, definition, "\n");
|
||||
|
||||
|
@ -414,6 +416,9 @@ Pandora_Module_Factory::getModuleFromDefinition (string definition) {
|
|||
if (module_advanced_options == "") {
|
||||
module_advanced_options = parseLine (line, TOKEN_ADVANCEDOPTIONS);
|
||||
}
|
||||
if (module_cooked == "") {
|
||||
module_cooked = parseLine (line, TOKEN_COOKED);
|
||||
}
|
||||
iter++;
|
||||
}
|
||||
|
||||
|
@ -497,7 +502,7 @@ Pandora_Module_Factory::getModuleFromDefinition (string definition) {
|
|||
module = new Pandora_Module_WMIQuery (module_name,
|
||||
module_wmiquery, module_wmicolumn);
|
||||
} else if (module_perfcounter != "") {
|
||||
module = new Pandora_Module_Perfcounter (module_name, module_perfcounter);
|
||||
module = new Pandora_Module_Perfcounter (module_name, module_perfcounter, module_cooked);
|
||||
} else if (module_tcpcheck != "") {
|
||||
module = new Pandora_Module_Tcpcheck (module_name, module_tcpcheck, module_port, module_timeout);
|
||||
} else if (module_regexp != "") {
|
||||
|
|
|
@ -34,6 +34,7 @@ static PdhOpenQueryT PdhOpenQuery = NULL;
|
|||
static PdhAddCounterT PdhAddCounter = NULL;
|
||||
static PdhCollectQueryDataT PdhCollectQueryData = NULL;
|
||||
static PdhGetRawCounterValueT PdhGetRawCounterValue = NULL;
|
||||
static PdhGetFormattedCounterValueT PdhGetFormattedCounterValue = NULL;
|
||||
static PdhCloseQueryT PdhCloseQuery = NULL;
|
||||
|
||||
/**
|
||||
|
@ -42,7 +43,7 @@ static PdhCloseQueryT PdhCloseQuery = NULL;
|
|||
* @param name Module name.
|
||||
* @param service_name Service internal name to check.
|
||||
*/
|
||||
Pandora_Module_Perfcounter::Pandora_Module_Perfcounter (string name, string source)
|
||||
Pandora_Module_Perfcounter::Pandora_Module_Perfcounter (string name, string source, string cooked)
|
||||
: Pandora_Module (name) {
|
||||
|
||||
this->source = source;
|
||||
|
@ -87,7 +88,15 @@ Pandora_Module_Perfcounter::Pandora_Module_Perfcounter (string name, string sour
|
|||
PDH = NULL;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
PdhGetFormattedCounterValue = (PdhGetFormattedCounterValueT) GetProcAddress (PDH, "PdhGetFormattedCounterValue");
|
||||
if (PdhGetFormattedCounterValue == NULL) {
|
||||
pandoraLog ("Error loading function PdhGetFormattedCounterValue");
|
||||
FreeLibrary (PDH);
|
||||
PDH = NULL;
|
||||
return;
|
||||
}
|
||||
|
||||
PdhCloseQuery = (PdhCloseQueryT) GetProcAddress (PDH, "PdhCloseQuery");
|
||||
if (PdhCloseQuery == NULL) {
|
||||
pandoraLog ("Error loading function PdhCloseQuery");
|
||||
|
@ -96,6 +105,12 @@ Pandora_Module_Perfcounter::Pandora_Module_Perfcounter (string name, string sour
|
|||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (cooked == "1") {
|
||||
this->cooked = 1;
|
||||
} else {
|
||||
this->cooked = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -111,7 +126,8 @@ Pandora_Module_Perfcounter::run () {
|
|||
HQUERY query;
|
||||
PDH_STATUS status;
|
||||
HCOUNTER counter;
|
||||
PDH_RAW_COUNTER value;
|
||||
PDH_RAW_COUNTER raw_value;
|
||||
PDH_FMT_COUNTER fmt_value;
|
||||
ostringstream string_value;
|
||||
|
||||
// Run
|
||||
|
@ -149,12 +165,31 @@ Pandora_Module_Perfcounter::run () {
|
|||
return;
|
||||
}
|
||||
|
||||
// Retrieve the counter value
|
||||
status = PdhGetRawCounterValue(counter, NULL, &value);
|
||||
// Retrieve the counter value
|
||||
if (this->cooked == 1) {
|
||||
|
||||
// Some counters require to samples
|
||||
Sleep (100);
|
||||
status = PdhCollectQueryData (query);
|
||||
if (status != ERROR_SUCCESS) {
|
||||
// No data
|
||||
PdhCloseQuery (query);
|
||||
return;
|
||||
}
|
||||
|
||||
status = PdhGetFormattedCounterValue(counter, PDH_FMT_LONG, NULL, &fmt_value);
|
||||
} else {
|
||||
status = PdhGetRawCounterValue(counter, NULL, &raw_value);
|
||||
}
|
||||
|
||||
// Close the query object
|
||||
PdhCloseQuery (query);
|
||||
|
||||
string_value << value.FirstValue;
|
||||
if (cooked == 1) {
|
||||
string_value << fmt_value.longValue;
|
||||
} else {
|
||||
string_value << raw_value.FirstValue;
|
||||
}
|
||||
|
||||
this->setOutput (string_value.str ());
|
||||
}
|
||||
|
|
|
@ -38,11 +38,26 @@ typedef struct _PDH_RAW_COUNTER {
|
|||
DWORD MultiCount;
|
||||
} PDH_RAW_COUNTER, *PPDH_RAW_COUNTER;
|
||||
|
||||
typedef struct _PDH_FMT_COUNTER {
|
||||
DWORD CStatus;
|
||||
union {
|
||||
LONG longValue;
|
||||
double doubleValue;
|
||||
LONGLONG largeValue;
|
||||
LPCSTR AnsiStringValue;
|
||||
LPCWSTR WideStringValue;
|
||||
};
|
||||
} PDH_FMT_COUNTER, *PPDH_FMT_COUNTER;
|
||||
|
||||
#define PDH_FMT_LONG 0x00000100
|
||||
#define PDH_FMT_DOUBLE 0x00000200
|
||||
#define PDH_FUNCTION PDH_STATUS __stdcall
|
||||
|
||||
typedef PDH_FUNCTION (*PdhOpenQueryT) (IN LPCSTR szDataSource, IN DWORD_PTR dwUserData, IN HQUERY *phQuery);
|
||||
typedef PDH_FUNCTION (*PdhAddCounterT) (IN HQUERY hQuery, IN LPCSTR szFullCounterPath, IN DWORD_PTR dwUserData, IN HCOUNTER *phCounter);
|
||||
typedef PDH_FUNCTION (*PdhCollectQueryDataT) (IN HQUERY hQuery);
|
||||
typedef PDH_FUNCTION (*PdhGetRawCounterValueT) (IN HCOUNTER, IN LPDWORD lpdwType, IN PPDH_RAW_COUNTER pValue);
|
||||
typedef PDH_FUNCTION (*PdhGetFormattedCounterValueT) (IN HCOUNTER, IN DWORD dwFormat, IN LPDWORD lpdwType, IN PPDH_FMT_COUNTER pValue);
|
||||
typedef PDH_FUNCTION (*PdhCloseQueryT) (IN HQUERY hQuery);
|
||||
|
||||
namespace Pandora_Modules {
|
||||
|
@ -54,9 +69,10 @@ namespace Pandora_Modules {
|
|||
class Pandora_Module_Perfcounter : public Pandora_Module {
|
||||
private:
|
||||
string source;
|
||||
unsigned char cooked;
|
||||
|
||||
public:
|
||||
Pandora_Module_Perfcounter (string name, string source);
|
||||
Pandora_Module_Perfcounter (string name, string source, string cooked);
|
||||
virtual ~Pandora_Module_Perfcounter ();
|
||||
void run ();
|
||||
};
|
||||
|
|
|
@ -130,6 +130,7 @@ Pandora_Wmi::isServiceRunning (string service_name) {
|
|||
pandoraLog ("isServiceRunning error. %s", errstr.c_str ());
|
||||
}
|
||||
|
||||
pandoraDebug ("Service %s not found.", service_name.c_str ());
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue