Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also .

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also .
...
  • 2 commits
  • 2 files changed
  • 0 commit comments
  • 2 contributors
Showing with 94 additions and 0 deletions.
  1. +27 −0 cmdline.py
  2. +67 −0 main.py
View
27 cmdline.py
@@ -0,0 +1,27 @@
+#!/usr/bin/python
+
+import socket
+import json
+import time
+
+while True:
+ try:
+ sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+ sock.connect(('', 6000))
+ data = sock.recv(10000)
+ sock.close()
+ #print data
+ stats = json.loads(data)
+ for stat in stats["Stats"]:
+ print "%s: %f" % (stat["type"] ,stat["value"])
+ print "----"
+ time.sleep(1)
+ except KeyboardInterrupt:
+ print "\nExiting..."
+ break
+ except:
+ print "\nError..."
+ break
+
+
+
View
67 main.py
@@ -0,0 +1,67 @@
+#!/usr/bin/python
+
+import socket
+import json
+from gi.repository import Gtk, Gdk, GObject
+
+
+class MenuExampleWindow(Gtk.Window):
+
+ def __init__(self):
+ Gtk.Window.__init__(self, title="Sys Monitor")
+
+ self.set_default_size(500, 500)
+
+ action_group = Gtk.ActionGroup("my_actions")
+
+ table = Gtk.Table(3,3,True)
+ self.add(table)
+
+ title = Gtk.Label("Current Stats")
+ cpu_title = Gtk.Label("CPU:")
+ mem_title = Gtk.Label("Mem:")
+ cpu_data = Gtk.Label()
+ mem_data = Gtk.Label()
+
+ table.attach(title,0,3,0,1)
+ table.attach(cpu_title,0,1,1,2)
+ table.attach(mem_title,0,1,2,3)
+ table.attach(cpu_data,1,3,1,2)
+ table.attach(mem_data,1,3,2,3)
+
+ self.stats = dict()
+ self.stats["Cpu"] = cpu_data
+ self.stats["Memory"] = mem_data
+
+ self.timeout_id = GObject.timeout_add(100, self.on_timeout, None)
+ self.activity_mode = False
+
+
+ def create_ui_manager(self):
+ uimanager = Gtk.UIManager()
+
+ # Throws exception if something went wrong
+ uimanager.add_ui_from_string(UI_INFO)
+
+ # Add the accelerator group to the toplevel window
+ accelgroup = uimanager.get_accel_group()
+ self.add_accel_group(accelgroup)
+ return uimanager
+
+ def on_timeout(self, data):
+ sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+ sock.connect(('', 6000))
+ data = sock.recv(10000)
+ sock.close()
+ #print data
+ stats = json.loads(data)
+ for stat in stats["Stats"]:
+ self.stats[stat["type"]].set_label("%f"%stat["value"])
+ return True
+
+
+
+window = MenuExampleWindow()
+window.connect("delete-event", Gtk.main_quit)
+window.show_all()
+Gtk.main()

No commit comments for this range

Something went wrong with that request. Please try again.