2006-07-12 Esteban Sanchez <estebans@artica.es>

* modules/pandora_module_freememory.[cc,h]: Added to repository. Implements a module to the the amount of free memory.

        * modules/pandora_module.h, modules/pandora_module_factory.cc, modules/pandora_module_list.cc: Added support to Pandora_Module_Freememory.

        * modules/pandora_wmi.[cc,h]: Added getFreememory () to get the amount of free memory.

        * pandora_windows_service.h: Removed public specificator from some functions.

        * PandoraAgent.dev: Added new files.

        * bin/PandoraAgent.exe: Updated to the new commit.

        * bin/pandora_agent.conf: Added example of free memory module.



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@133 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
Esteban Sanchez 2006-07-13 10:38:32 +00:00
parent 86de96df72
commit 05df7536d4
13 changed files with 212 additions and 15 deletions

View File

@ -1,3 +1,24 @@
2006-07-12 Esteban Sanchez <estebans@artica.es>
* modules/pandora_module_freememory.[cc,h]: Added to repository.
Implements a module to the the amount of free memory.
* modules/pandora_module.h, modules/pandora_module_factory.cc,
modules/pandora_module_list.cc: Added support to
Pandora_Module_Freememory.
* modules/pandora_wmi.[cc,h]: Added getFreememory () to get the amount
of free memory.
* pandora_windows_service.h: Removed public specificator from some
functions.
* PandoraAgent.dev: Added new files.
* bin/PandoraAgent.exe: Updated to the new commit.
* bin/pandora_agent.conf: Added example of free memory module.
2006-07-11 Esteban Sanchez <estebans@artica.es> 2006-07-11 Esteban Sanchez <estebans@artica.es>
* bin/pandora_agent.conf: Added examples of CPU usage and free space * bin/pandora_agent.conf: Added examples of CPU usage and free space

View File

@ -1,7 +1,7 @@
[Project] [Project]
FileName=PandoraAgent.dev FileName=PandoraAgent.dev
Name=PandoraAgent Name=PandoraAgent
UnitCount=63 UnitCount=65
Type=1 Type=1
Ver=1 Ver=1
ObjFiles= ObjFiles=
@ -677,3 +677,23 @@ Priority=1000
OverrideBuildCmd=0 OverrideBuildCmd=0
BuildCmd= BuildCmd=
[Unit64]
FileName=modules\pandora_module_freememory.cc
CompileCpp=1
Folder=Modules
Compile=1
Link=1
Priority=1000
OverrideBuildCmd=0
BuildCmd=
[Unit65]
FileName=modules\pandora_module_freememory.h
CompileCpp=1
Folder=Modules
Compile=1
Link=1
Priority=1000
OverrideBuildCmd=0
BuildCmd=

View File

@ -80,3 +80,11 @@ module_cpuusage 0
module_description CPU#0 usage module_description CPU#0 usage
module_end module_end
module_begin
module_name FreeMemory
module_type generic_data
module_freememory
module_description Amount of free memory.
module_end

View File

@ -73,7 +73,7 @@ main (int argc, char *argv[]) {
} }
} }
service->run (); service->run ();
delete service; delete service;
return 0; return 0;
} }

View File

@ -47,13 +47,15 @@ namespace Pandora_Modules {
MODULE_PROC, MODULE_PROC,
MODULE_SERVICE, MODULE_SERVICE,
MODULE_FREEDISK, MODULE_FREEDISK,
MODULE_CPUUSAGE MODULE_CPUUSAGE,
MODULE_FREEMEMORY
}; };
const string module_exec_str = "module_exec"; const string module_exec_str = "module_exec";
const string module_proc_str = "module_proc"; const string module_proc_str = "module_proc";
const string module_service_str = "module_service"; const string module_service_str = "module_service";
const string module_freedisk_str = "module_freedisk"; const string module_freedisk_str = "module_freedisk";
const string module_freememory_str = "module_freememory";
const string module_cpuusage_str = "module_cpuusage"; const string module_cpuusage_str = "module_cpuusage";
class Output_Error : public Pandora::Pandora_Exception { }; class Output_Error : public Pandora::Pandora_Exception { };

View File

@ -24,6 +24,7 @@
#include "pandora_module_proc.h" #include "pandora_module_proc.h"
#include "pandora_module_service.h" #include "pandora_module_service.h"
#include "pandora_module_freedisk.h" #include "pandora_module_freedisk.h"
#include "pandora_module_freememory.h"
#include "pandora_module_cpuusage.h" #include "pandora_module_cpuusage.h"
#include "../pandora_strutils.h" #include "../pandora_strutils.h"
#include <list> #include <list>
@ -39,6 +40,7 @@ using namespace Pandora_Strutils;
#define TOKEN_PROC ("module_proc ") #define TOKEN_PROC ("module_proc ")
#define TOKEN_SERVICE ("module_service ") #define TOKEN_SERVICE ("module_service ")
#define TOKEN_FREEDISK ("module_freedisk ") #define TOKEN_FREEDISK ("module_freedisk ")
#define TOKEN_FREEMEMORY ("module_freememory")
#define TOKEN_CPUUSAGE ("module_cpuusage ") #define TOKEN_CPUUSAGE ("module_cpuusage ")
#define TOKEN_MAX ("module_max ") #define TOKEN_MAX ("module_max ")
#define TOKEN_MIN ("module_min ") #define TOKEN_MIN ("module_min ")
@ -48,11 +50,15 @@ string
parseLine (string line, string token) { parseLine (string line, string token) {
unsigned int pos; unsigned int pos;
string retstr = ""; string retstr = "";
pos = line.find (token); pos = line.find (token);
if (pos == 0) { if (pos == 0) {
retstr = line.substr (token.length ()); retstr = line.substr (token.length ());
if (retstr == "") {
retstr = " ";
}
} }
return retstr; return retstr;
} }
@ -63,7 +69,7 @@ Pandora_Module_Factory::getModuleFromDefinition (string definition) {
string module_name, module_type, module_exec; string module_name, module_type, module_exec;
string module_min, module_max, module_description; string module_min, module_max, module_description;
string module_interval, module_proc, module_service; string module_interval, module_proc, module_service;
string module_freedisk, module_cpuusage; string module_freedisk, module_cpuusage, module_freememory;
Pandora_Module *module; Pandora_Module *module;
bool numeric; bool numeric;
@ -108,6 +114,9 @@ Pandora_Module_Factory::getModuleFromDefinition (string definition) {
if (module_freedisk == "") { if (module_freedisk == "") {
module_freedisk = parseLine (line, TOKEN_FREEDISK); module_freedisk = parseLine (line, TOKEN_FREEDISK);
} }
if (module_freememory == "") {
module_freememory = parseLine (line, TOKEN_FREEMEMORY);
}
if (module_cpuusage == "") { if (module_cpuusage == "") {
module_cpuusage = parseLine (line, TOKEN_CPUUSAGE); module_cpuusage = parseLine (line, TOKEN_CPUUSAGE);
} }
@ -137,6 +146,10 @@ Pandora_Module_Factory::getModuleFromDefinition (string definition) {
module = new Pandora_Module_Freedisk (module_name, module = new Pandora_Module_Freedisk (module_name,
module_freedisk); module_freedisk);
} else if (module_freememory != "") {
pandoraDebug ("Freememory");
module = new Pandora_Module_Freememory (module_name);
} else if (module_cpuusage != "") { } else if (module_cpuusage != "") {
int cpu_id; int cpu_id;

View File

@ -0,0 +1,57 @@
/* Pandora freememory module. These modules check if a freememory is running in the
system.
Copyright (C) 2006 Artica ST.
Written by Esteban Sanchez.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "pandora_module_freememory.h"
#include "../windows/pandora_wmi.h"
#include "../pandora_strutils.h"
using namespace Pandora;
using namespace Pandora_Modules;
using namespace Pandora_Strutils;
Pandora_Module_Freememory::Pandora_Module_Freememory (string name)
: Pandora_Module (name) {
this->module_kind_str = module_freememory_str;
this->module_kind = MODULE_FREEMEMORY;
}
void
Pandora_Module_Freememory::run () {
long res;
try {
Pandora_Module::run ();
} catch (Interval_Not_Fulfilled e) {
return;
}
try {
res = Pandora_Wmi::getFreememory ();
output = longtostr (res);
} catch (Pandora_Wmi::Pandora_Wmi_Error e) {
this->has_output = false;
}
}

View File

@ -0,0 +1,35 @@
/* Pandora free memory module. These modules get amount of free memory.
Copyright (C) 2006 Artica ST.
Written by Esteban Sanchez.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __PANDORA_MODULE_FREEMEMORY_H__
#define __PANDORA_MODULE_FREEMEMORY_H__
#include "pandora_module.h"
namespace Pandora_Modules {
class Pandora_Module_Freememory : public Pandora_Module {
public:
Pandora_Module_Freememory (string name);
void run ();
};
}
#endif

View File

@ -24,6 +24,7 @@
#include "pandora_module_proc.h" #include "pandora_module_proc.h"
#include "pandora_module_service.h" #include "pandora_module_service.h"
#include "pandora_module_freedisk.h" #include "pandora_module_freedisk.h"
#include "pandora_module_freememory.h"
#include "pandora_module_cpuusage.h" #include "pandora_module_cpuusage.h"
#include <fstream> #include <fstream>
@ -93,12 +94,13 @@ Pandora_Module_List::~Pandora_Module_List () {
void void
Pandora_Module_List::parseModuleDefinition (string definition) { Pandora_Module_List::parseModuleDefinition (string definition) {
Pandora_Module *module; Pandora_Module *module;
Pandora_Module_Exec *module_exec; Pandora_Module_Exec *module_exec;
Pandora_Module_Proc *module_proc; Pandora_Module_Proc *module_proc;
Pandora_Module_Service *module_service; Pandora_Module_Service *module_service;
Pandora_Module_Freedisk *module_freedisk; Pandora_Module_Freedisk *module_freedisk;
Pandora_Module_Cpuusage *module_cpuusage; Pandora_Module_Cpuusage *module_cpuusage;
Pandora_Module_Freememory *module_freememory;
module = Pandora_Module_Factory::getModuleFromDefinition (definition); module = Pandora_Module_Factory::getModuleFromDefinition (definition);
@ -125,6 +127,11 @@ Pandora_Module_List::parseModuleDefinition (string definition) {
module_freedisk = (Pandora_Module_Freedisk *) module; module_freedisk = (Pandora_Module_Freedisk *) module;
modules->push_back (module_freedisk); modules->push_back (module_freedisk);
break;
case MODULE_FREEMEMORY:
module_freememory = (Pandora_Module_Freememory *) module;
modules->push_back (module_freememory);
break; break;
case MODULE_CPUUSAGE: case MODULE_CPUUSAGE:
module_cpuusage = (Pandora_Module_Cpuusage *) module; module_cpuusage = (Pandora_Module_Cpuusage *) module;

View File

@ -39,7 +39,7 @@ private:
string agent_name; string agent_name;
TiXmlElement * getXmlHeader (); TiXmlElement * getXmlHeader ();
public:
void pandora_run (); void pandora_run ();
void pandora_init (); void pandora_init ();
public: public:

View File

@ -163,12 +163,12 @@ Pandora_Wmi::getDiskFreeSpace (string disk_id) {
dhGetValue (L"%d", &fix.free_space, quickfix, dhGetValue (L"%d", &fix.free_space, quickfix,
L".FreeSpace"); L".FreeSpace");
return fix.free_space; return fix.free_space / 1024 / 1024;
} }
} NEXT_THROW (quickfix); } NEXT_THROW (quickfix);
} catch (string errstr) { } catch (string errstr) {
pandoraLog ("getOSName error. %s", errstr.c_str ()); pandoraLog ("getDiskFreeSpace error. %s", errstr.c_str ());
} }
throw Pandora_Wmi_Error (); throw Pandora_Wmi_Error ();
@ -213,12 +213,45 @@ Pandora_Wmi::getCpuUsagePercentage (int cpu_id) {
} NEXT_THROW (quickfix); } NEXT_THROW (quickfix);
} catch (string errstr) { } catch (string errstr) {
pandoraLog ("getOSName error. %s", errstr.c_str ()); pandoraLog ("getCpuUsagePercentage error. %s", errstr.c_str ());
} }
throw Pandora_Wmi_Error (); throw Pandora_Wmi_Error ();
} }
long
Pandora_Wmi::getFreememory () {
CDhInitialize init;
CDispPtr wmi_svc, quickfixes;
dhToggleExceptions (TRUE);
struct QFix {
long free_memory;
};
try {
dhCheck (dhGetObject (getWmiStr (L"."), NULL, &wmi_svc));
dhCheck (dhGetValue (L"%o", &quickfixes, wmi_svc,
L".ExecQuery(%S)",
L"SELECT * FROM Win32_PerfRawData_PerfOS_Memory "));
FOR_EACH (quickfix, quickfixes, NULL) {
QFix fix = { 0 };
dhGetValue (L"%d", &fix.free_memory, quickfix,
L".AvailableMBytes");
return fix.free_memory;
} NEXT_THROW (quickfix);
} catch (string errstr) {
pandoraLog ("getFreememory error. %s", errstr.c_str ());
}
throw Pandora_Wmi_Error ();
}
string string
Pandora_Wmi::getOSName () { Pandora_Wmi::getOSName () {
CDhInitialize init; CDhInitialize init;

View File

@ -36,6 +36,7 @@ namespace Pandora_Wmi {
int isServiceRunning (string service_name); int isServiceRunning (string service_name);
long getDiskFreeSpace (string disk_id); long getDiskFreeSpace (string disk_id);
int getCpuUsagePercentage (int cpu_id); int getCpuUsagePercentage (int cpu_id);
long getFreememory ();
string getOSName (); string getOSName ();
string getOSVersion (); string getOSVersion ();
string getOSBuild (); string getOSBuild ();