[Ovirt-devel] [PATCH] Added the new Processors agent.

Darryl L. Pierce dpierce at redhat.com
Mon Mar 22 20:05:59 UTC 2010


The Processors agent reports details regarding the processing power for
the managed node.

Defined the agent within schema.xml. Wrote the wrapper code to create
and populate an instance of the agent.

The properties for the Processors agent have also been trimmed back to
what is readily available via HAL. A future fix will replace this with
calls to sysfs.

Signed-off-by: Darryl L. Pierce <dpierce at redhat.com>
---
 src/Makefile.am    |   26 +++++++++++--------
 src/host.cpp       |    6 ++++
 src/host.h         |    3 ++
 src/processors.cpp |   70 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/processors.h   |   47 +++++++++++++++++++++++++++++++++++
 src/schema.xml     |    9 ++++++
 6 files changed, 150 insertions(+), 11 deletions(-)
 create mode 100644 src/processors.cpp
 create mode 100644 src/processors.h

diff --git a/src/Makefile.am b/src/Makefile.am
index 8c94fba..ee30443 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -5,14 +5,16 @@ sbin_PROGRAMS = matahari
 first = qmf/com/redhat/matahari/Host.cpp
 
 generated_file_list = \
-	qmf/com/redhat/matahari/CPU.cpp\
-	qmf/com/redhat/matahari/NIC.cpp\
-	qmf/com/redhat/matahari/Package.cpp\
-	qmf/com/redhat/matahari/Host.h\
-	qmf/com/redhat/matahari/CPU.h\
-	qmf/com/redhat/matahari/NIC.h\
-	qmf/com/redhat/matahari/Package.h\
-	qmf/com/redhat/matahari/ArgsNICIdentify_nic.h
+	qmf/com/redhat/matahari/ArgsNICIdentify_nic.h \
+	qmf/com/redhat/matahari/CPU.cpp \
+	qmf/com/redhat/matahari/CPU.h \
+	qmf/com/redhat/matahari/Host.h \
+	qmf/com/redhat/matahari/NIC.cpp \
+	qmf/com/redhat/matahari/NIC.h \
+	qmf/com/redhat/matahari/Package.cpp \
+	qmf/com/redhat/matahari/Package.h \
+	qmf/com/redhat/matahari/Processors.cpp \
+	qmf/com/redhat/matahari/Processors.h
 
 nodist_matahari_SOURCES = $(generated_file_list) $(first)
 
@@ -25,11 +27,13 @@ matahari_SOURCES = \
 	host.h \
 	main.cpp \
 	nic.cpp \
-	nic.h
+	nic.h \
+	processors.cpp \
+	processors.h
 
-$(generated_file_list): $(first)
+$(generated_file_list): $(generated_file_list)
 
-$(first): schema.xml
+$(first): schema.xml $(generated_file_list)
 	qmf-gen -o ./qmf ./schema.xml
 
 BUILT_SOURCES = $(generated_file_list) $(first)
diff --git a/src/host.cpp b/src/host.cpp
index 0d22211..44c7717 100644
--- a/src/host.cpp
+++ b/src/host.cpp
@@ -68,7 +68,11 @@ void HostWrapper::doLoop(void)
 {
     // Someday we might update statistics too!
     while(1)
+      {
+        // update all statistics
+        processors.update_load_averages();
         sleep(5);
+      }
 }
 
 void HostWrapper::setupQMFObjects(ManagementAgent *agent)
@@ -78,6 +82,8 @@ void HostWrapper::setupQMFObjects(ManagementAgent *agent)
     agent->addObject(mgmt_object);
     syncQMFHostObject();
 
+    processors.setup(agent);
+
     // Iterate over list and set up CPU objects
     for (vector<CPUWrapper*>::iterator iter = cpus.begin();
          iter!= cpus.end();
diff --git a/src/host.h b/src/host.h
index 06bdbf0..148c91f 100644
--- a/src/host.h
+++ b/src/host.h
@@ -25,6 +25,7 @@
 
 #include "cpu.h"
 #include "nic.h"
+#include "processors.h"
 
 using namespace qpid::management;
 using namespace std;
@@ -49,6 +50,8 @@ class HostWrapper : public Manageable
     vector<CPUWrapper*> cpus;
     vector<NICWrapper*> nics;
 
+    ProcessorsAgent processors;
+
     // QMF related fields
     ManagementAgent *agent;
     qmf::com::redhat::matahari::Host *mgmt_object;
diff --git a/src/processors.cpp b/src/processors.cpp
new file mode 100644
index 0000000..3edc417
--- /dev/null
+++ b/src/processors.cpp
@@ -0,0 +1,70 @@
+/* processor.cpp - Copyright (C) 2010 Red Hat, Inc.
+ * Written by Darryl L. Pierce <dpierce at redhat.com>
+ *
+ * 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; version 2 of the License.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston,
+ * MA  02110-1301, USA.  A copy of the GNU General Public License is
+ * also available at http://www.gnu.org/copyleft/gpl.html.
+ */
+
+#include <iostream>
+#include <fstream>
+#include <sstream>
+#include <string>
+#include <vector>
+#include <stdexcept>
+
+#include <hal/libhal.h>
+
+#include <pcre.h>
+
+#include "hal.h"
+#include "processors.h"
+
+using namespace std;
+namespace _qmf = qmf::com::redhat::matahari;
+
+extern DBusError dbus_error;
+
+void
+ProcessorsAgent::setup(ManagementAgent* agent)
+{
+  // setup the management object
+  management_object = new _qmf::Processors(agent, this);
+  agent->addObject(management_object);
+
+  LibHalContext* context = get_hal_ctx();
+
+  int num_results;
+  char** processors = libhal_find_device_by_capability(context,"processor", &num_results, &dbus_error);
+
+  if (!processors)
+    throw runtime_error("Error: could not query processors via HAL.");
+
+  // populate the managed object's values
+  management_object->set_model(libhal_device_get_property_string(context, processors[0], "info.product", &dbus_error));
+  management_object->set_cores(num_results);
+}
+
+void
+ProcessorsAgent::update_load_averages(void) const
+{
+  double load_average;
+  ifstream input;
+
+  input.open("/proc/loadavg", ios::in);
+  input >> load_average;
+  input.close();
+
+  management_object->set_load_average(load_average);
+}
diff --git a/src/processors.h b/src/processors.h
new file mode 100644
index 0000000..008ce11
--- /dev/null
+++ b/src/processors.h
@@ -0,0 +1,47 @@
+/* processor.h - Copyright (C) 2010 Red Hat, Inc.
+ * Written by Darryl L. Pierce <dpierce at redhat.com>
+ *
+ * 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; version 2 of the License.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston,
+ * MA  02110-1301, USA.  A copy of the GNU General Public License is
+ * also available at http://www.gnu.org/copyleft/gpl.html.
+ */
+
+#include <qpid/agent/ManagementAgent.h>
+#include <qpid/management/Manageable.h>
+#include <qpid/management/ManagementObject.h>
+#include <qpid/agent/ManagementAgent.h>
+
+#include "qmf/com/redhat/matahari/Processors.h"
+
+using namespace qpid::management;
+using namespace std;
+
+using qpid::management::Manageable;
+
+class ProcessorsAgent : public Manageable
+{
+ private:
+  qmf::com::redhat::matahari::Processors* management_object;
+
+ public:
+  ProcessorsAgent() {}
+  virtual ~ProcessorsAgent() {}
+
+  ManagementObject* GetManagementObject(void) const { return management_object; }
+
+  void setup(ManagementAgent* agent);
+
+  // agent methods
+  void update_load_averages(void) const;
+};
diff --git a/src/schema.xml b/src/schema.xml
index 5fb683f..48e9576 100644
--- a/src/schema.xml
+++ b/src/schema.xml
@@ -14,6 +14,15 @@
 
   </class>
 
+  <!-- The processor for the node. -->
+  <class name="Processors">
+    <property name="node"   type="objId" access="RO" desc="The managed node." />
+    <property name="model"  type="lstr"  access="RO" desc="The processor label." />
+    <property name="cores"  type="int8"  access="RO" desc="The number of cores." />
+
+    <statistic name="load_average" type="float" desc="The processing load average." />
+  </class>
+
   <class name="CPU">
 
     <property name="host"      type="objId"  access="RO" desc="Host that this cpu belongs to" index="y" references="Host" parentRef="y"/>
-- 
1.6.6.1




More information about the ovirt-devel mailing list