Skip to content

Instantly share code, notes, and snippets.

Created July 7, 2015 21:35
Show Gist options
  • Save anonymous/1fd4599e6cca293274f2 to your computer and use it in GitHub Desktop.
Save anonymous/1fd4599e6cca293274f2 to your computer and use it in GitHub Desktop.
diff --git a/ptop/interfaces/GUI.py b/ptop/interfaces/GUI.py
index 897bef3..c045fe7 100644
--- a/ptop/interfaces/GUI.py
+++ b/ptop/interfaces/GUI.py
@@ -305,6 +305,9 @@ class PtopGUI(npyscreen.NPSApp):
self.CHART_LENGTH = int(self.CHART_LENGTH*self.X_SCALING_FACTOR)
self.CHART_HEIGHT = int(self.CHART_HEIGHT*self.Y_SCALING_FACTOR)
+ self.cpu_array = [0]*self.CHART_LENGTH
+ self.memory_array = [0]*self.CHART_LENGTH
+
# add subwidgets to the parent widget
self.window.edit()
diff --git a/ptop/plugins/memory_sensor.py b/ptop/plugins/memory_sensor.py
index 6fd11f8..0d90e3b 100644
--- a/ptop/plugins/memory_sensor.py
+++ b/ptop/plugins/memory_sensor.py
@@ -27,7 +27,12 @@ class MemorySensor(Plugin):
smem = psutil.swap_memory()
self.currentValue['text']['swap_memory']['total'] = int(float(smem.total)/(1024*1024))
self.currentValue['text']['swap_memory']['active'] = int(float(smem.used)/(1024*1024))
- self.currentValue['text']['swap_memory']['percentage'] = int(float(smem.used)/smem.total)*100
+
+ if smem.total:
+ self.currentValue['text']['swap_memory']['percentage'] = int(float(smem.used)/smem.total)*100
+ else:
+ self.currentValue['text']['swap_memory']['percentage'] = 0
+
memory_sensor = MemorySensor(name='Memory',sensorType='chart',interval=0.5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment