[vlma-devel] commit: Expose system metrics. (Adrien Grand )

git version control git at videolan.org
Fri Nov 27 12:10:15 CET 2009


vlma | branch: master | Adrien Grand <jpountz at jpountz.net> | Fri Nov 27 12:09:33 2009 +0100| [2fbf5f1a819e30318edf237cb1ca365ed9e020aa] | committer: Adrien Grand 

Expose system metrics.

> http://git.videolan.org/gitweb.cgi/vlma.git/?a=commit;h=2fbf5f1a819e30318edf237cb1ca365ed9e020aa
---

 vlma-watchdog/src/serialization.py |    7 +++++++
 vlma-watchdog/src/utils.py         |   16 ++++++++++++++++
 vlma-watchdog/src/web.py           |   17 +++++++++++++++--
 3 files changed, 38 insertions(+), 2 deletions(-)

diff --git a/vlma-watchdog/src/serialization.py b/vlma-watchdog/src/serialization.py
index bf82299..2818efa 100644
--- a/vlma-watchdog/src/serialization.py
+++ b/vlma-watchdog/src/serialization.py
@@ -31,3 +31,10 @@ def streamer_logs_to_xml(logs, writer):
     writer.write("<log level=\"%s\">%s</log>" %(log[0], log[1]))
   writer.write("</logs>")
 
+def system_metrics_to_xml(metrics, writer):
+  writer.write("<system-metrics%s>" %NS)
+  writer.write("<cpu-load>%f</cpu-load>" %metrics.cpu_load)
+  writer.write("<inbound-traffic>%f</inbound-traffic>" %metrics.traffic_in)
+  writer.write("<outbound-traffic>%f</outbound-traffic>" %metrics.traffic_out)
+  writer.write("</system-metrics>")
+
diff --git a/vlma-watchdog/src/utils.py b/vlma-watchdog/src/utils.py
index 95174bf..5f64cb9 100644
--- a/vlma-watchdog/src/utils.py
+++ b/vlma-watchdog/src/utils.py
@@ -83,6 +83,22 @@ def getTrafficOut():
     return _getTrafficX(9)
 
 
+class SystemMetrics:
+
+  def __init__(self):
+    self.cpu_load = 0.
+    self.traffic_in = 0.
+    self.traffic_out = 0.
+
+
+def get_system_metrics():
+  metrics = SystemMetrics()
+  metrics.cpu_load = getCpuLoad()
+  metrics.traffic_in = getTrafficIn()
+  metrics.traffic_out = getTrafficOut()
+  return metrics
+
+
 def signalHandler(signum, frame):
   """Triggered when a signal is sent."""
   logger.warn("Signal %i received", signum)
diff --git a/vlma-watchdog/src/web.py b/vlma-watchdog/src/web.py
index 7473f4d..fa9bf62 100644
--- a/vlma-watchdog/src/web.py
+++ b/vlma-watchdog/src/web.py
@@ -1,7 +1,7 @@
 #! /usr/bin/env python
 # -*- coding: utf-8 -*-
 
-import conf, logging, threading, serialization, sys
+import conf, logging, threading, serialization, sys, utils
 try:
   from twisted.web import server, resource, static
   from twisted.internet import reactor
@@ -25,6 +25,8 @@ class Server(threading.Thread):
     root.putChild("", IndexResource(self.__streamers))
     root.putChild("schema.xsd", static.File("schema.xsd", defaultType='text/xml'))
     system = resource.Resource()
+    root.putChild("system", system)
+    system.putChild("metric", SystemMetricsResource())
     streamers = StreamersResource(self.__streamers)
     root.putChild("streamer", streamers)
     for streamer in self.__streamers:
@@ -78,7 +80,8 @@ class IndexResource(AuthenticationRequiredResource):
   def __init__(self, streamers):
     AuthenticationRequiredResource.__init__(self)
     self.links = [
-      ("/streamer", "Streamers")
+      ("/streamer", "Streamers"),
+      ("/system/metric", "System metrics")
     ]
     for streamer in streamers:
      self.links.append(("/streamer/%s" %streamer.id, "Streamer %s (%s)" %(streamer.id, streamer.type)))
@@ -125,6 +128,7 @@ class StreamerMetricsResource(AuthenticationRequiredResource):
     prepare_xml_response(request)
     serialization.streamer_metrics_to_xml(self.streamer, request)
 
+
 class StreamerLogsResource(AuthenticationRequiredResource):
 
   def __init__(self, streamer):
@@ -136,3 +140,12 @@ class StreamerLogsResource(AuthenticationRequiredResource):
     serialization.streamer_logs_to_xml(self.streamer.logs, request)
 
 
+class SystemMetricsResource(AuthenticationRequiredResource):
+
+  def __init__(self):
+    AuthenticationRequiredResource.__init__(self)
+
+  def render_GET_authenticated(self, request):
+    prepare_xml_response(request)
+    serialization.system_metrics_to_xml(utils.get_system_metrics(), request)
+



More information about the vlma-devel mailing list