ACK for the parts that dont go with patch 1, but in future, please
separate new features from cleanups.
Ie.
- ifstream input;
-
- input.open("/proc/loadavg", ios::in);
- input >> one >> five >> fifteen;
- input.close();
+ ifstream input("/proc/loadavg");
+ if (!input.good())
+ return;
+
+ input >> la.load_average_1;
+ input >> la.load_average_5;
+ input >> la.load_average_15;
does not relate to the patch description.
On Mon, Nov 1, 2010 at 2:21 PM, Adam Stokes <astokes(a)fedoraproject.org> wrote:
- In order to replace an existing agent (sesame) we needed to add a
couple
of more properties which included the following:
* memory free
* swap
* swapfree
* number of running processes
---
src/host.cpp | 85 ++++++++++++++++++++++++++++++++++++-------------
src/host.h | 21 +++++++++++-
src/qmf/hostagent.cpp | 29 ++++++++++++-----
src/qmf/hostagent.h | 5 +--
4 files changed, 105 insertions(+), 35 deletions(-)
diff --git a/src/host.cpp b/src/host.cpp
index c2aa131..58d5e96 100644
--- a/src/host.cpp
+++ b/src/host.cpp
@@ -287,47 +287,88 @@ host_get_architecture()
return architecture;
}
-unsigned int
-host_get_memory()
+void
+host_get_memory(Mem& mem)
{
- static unsigned int memory = 0;
- if(!memory)
- {
#ifdef __linux__
-
- struct sysinfo sysinf;
- if(!sysinfo(&sysinf))
- {
- memory = sysinf.totalram / 1024L;
- }
+ ifstream input("/proc/meminfo");
+ if(!input.good())
+ return;
+
+ while (!input.eof())
+ {
+ string key;
+ input >> key;
+ if (key == "MemTotal:")
+ input >> mem.memory;
+ else if (key == "MemFree:")
+ input >> mem.memFree;
+ else if (key == "SwapTotal:")
+ input >> mem.swap;
+ else if (key == "SwapFree:")
+ input >> mem.swapFree;
+ }
+ input.close();
#elif defined WIN32
MEMORYSTATUS status;
+ int memory;
GlobalMemoryStatus(&status);
memory = status.dwTotalPhys / 1024L;
#endif
- }
+}
+
+string
+host_get_cpu_model()
+{
+ return Platform::instance()->getCPUModel();
+}
- return memory;
+unsigned int
+host_get_number_of_cpu_cores()
+{
+ return Platform::instance()->getNumberOfCPUCores();
+}
+
+double
+host_get_load_average()
+{
+ return Platform::instance()->getLoadAverage();
}
void
-host_get_load_averages(double& one, double& five, double& fifteen)
+host_get_load_averages(LoadAverage& la)
{
#ifdef __linux__
- ifstream input;
-
- input.open("/proc/loadavg", ios::in);
- input >> one >> five >> fifteen;
- input.close();
+ ifstream input("/proc/loadavg");
+ if (!input.good())
+ return;
+
+ input >> la.load_average_1;
+ input >> la.load_average_5;
+ input >> la.load_average_15;
+
+ string procs;
+ input >> procs;
+ input.close();
+
+ la.procTotal = 0;
+ la.procRunning = 0;
+
+ size_t slashPos = procs.find('/');
+ if(slashPos == string::npos)
+ return;
+
+ la.procRunning = ::atoi(procs.substr(0, slashPos).c_str());
+ la.procTotal = ::atoi(procs.substr(slashPos + 1).c_str());
#else
- one = 0.0;
- five = 0.0;
- fifteen = 0.0;
+ la.load_average_1 = 0.0;
+ la.load_average_5 = 0.0;
+ la.load_average_15 = 0.0;
#endif
}
diff --git a/src/host.h b/src/host.h
index 4852230..f2b41bb 100644
--- a/src/host.h
+++ b/src/host.h
@@ -25,6 +25,23 @@
#include "hostlistener.h"
+struct Mem
+{
+ uint64_t memory;
+ uint64_t memFree;
+ uint64_t swap;
+ uint64_t swapFree;
+};
+
+struct LoadAverage
+{
+ double load_average_1;
+ double load_average_5;
+ double load_average_15;
+ uint64_t procTotal;
+ uint64_t procRunning;
+};
+
using namespace std;
void host_register_listener(HostListener* listener);
@@ -45,9 +62,9 @@ unsigned int host_get_platform();
string host_get_architecture();
-unsigned int host_get_memory();
+void host_get_memory(Mem& mem);
-void host_get_load_averages(double& one, double& five, double& fifteen);
+void host_get_load_averages(LoadAverage& la);
void host_identify(const unsigned int iterations);
diff --git a/src/qmf/hostagent.cpp b/src/qmf/hostagent.cpp
index f9307f9..34bf3c4 100644
--- a/src/qmf/hostagent.cpp
+++ b/src/qmf/hostagent.cpp
@@ -25,7 +25,7 @@
#include "processor.h"
#include <qpid/agent/ManagementAgent.h>
-#include "qmf/com/redhat/matahari/host/EventHeartbeat.h"
+#include "qmf/com/redhat/matahari/EventHeartbeat.h"
HostAgent::HostAgent()
{
@@ -50,7 +50,6 @@ HostAgent::setup(ManagementAgent* agent)
_management_object->set_hypervisor(host_get_hypervisor());
_management_object->set_platform(host_get_platform());
_management_object->set_arch(host_get_architecture());
- _management_object->set_memory(host_get_memory());
_management_object->set_processors(cpu_get_count());
_management_object->set_cores(cpu_get_number_of_cores());
_management_object->set_model(cpu_get_model());
@@ -84,11 +83,25 @@ HostAgent::heartbeat(uint64_t timestamp, uint32_t sequence)
void
HostAgent::updated()
{
- // update the load averages
- double one, five, fifteen;
+ LoadAverage la;
+ Mem mem;
- host_get_load_averages(one, five, fifteen);
- _management_object->set_load_average_1(one);
- _management_object->set_load_average_5(five);
- _management_object->set_load_average_15(fifteen);
+ host_get_load_averages(la);
+ host_get_memory(mem);
+ _management_object->set_load_average_1(la.load_average_1);
+ _management_object->set_load_average_5(la.load_average_5);
+ _management_object->set_load_average_15(la.load_average_15);
+ _management_object->set_procTotal(la.procTotal);
+ _management_object->set_procRunning(la.procRunning);
+ _management_object->set_memFree(mem.memFree);
+ _management_object->set_swapFree(mem.swapFree);
+ _management_object->set_memory(mem.memory);
+ _management_object->set_swap(mem.swap);
+
+}
+
+void
+HostAgent::updated()
+{
+ _management_object->set_load_average(host_get_load_average());
}
diff --git a/src/qmf/hostagent.h b/src/qmf/hostagent.h
index 498f1be..3f31bfc 100644
--- a/src/qmf/hostagent.h
+++ b/src/qmf/hostagent.h
@@ -26,12 +26,12 @@
#include "host.h"
#include "hostlistener.h"
-#include "qmf/com/redhat/matahari/host/Host.h"
+#include "qmf/com/redhat/matahari/Host.h"
using namespace qpid::management;
using namespace std;
-namespace _qmf = qmf::com::redhat::matahari::host;
+namespace _qmf = qmf::com::redhat::matahari;
class HostAgent : public Manageable, public HostListener
{
@@ -48,7 +48,6 @@ class HostAgent : public Manageable, public HostListener
status_t ManagementMethod(uint32_t method, Args& arguments, string& text);
virtual void heartbeat(uint64_t timestamp, unsigned int sequence);
-
virtual void updated();
};
--
1.7.2.3
_______________________________________________
Matahari mailing list
Matahari(a)lists.fedorahosted.org
https://fedorahosted.org/mailman/listinfo/matahari