-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcpuMonitor.py
More file actions
executable file
·56 lines (45 loc) · 1.31 KB
/
Copy pathcpuMonitor.py
File metadata and controls
executable file
·56 lines (45 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import re
from gi.repository import Gtk, GLib
from gi.repository import AppIndicator3 as appindicator
import os
def cb_exit(w, data):
Gtk.main_quit()
def get_numberCores():
numberCores=0
for line in open("/proc/cpuinfo", 'r'):
if re.search("cpu cores", line):
print line
m = re.search(r'(\d)',line)
numberCores = m.group()
break
print "Numero de cores = "+numberCores+"_\n"
return int(numberCores)
def refreshData(ind_app):
label=""
for core in range(0,numberCores):
label+= readcputemp(core)
if core < numberCores -1:
label+=" - "
ind_app.set_label(label,"")
return 1
def readcputemp(core):
# get CPU temp
file_core = open('/sys/class/hwmon/hwmon0/device/temp'+str(core+1)+'_input','r')
temp_core = file_core.read(2)+"º C"
file_core.close()
return temp_core
numberCores = get_numberCores()
ind_app = appindicator.Indicator.new ("cputemp-indicator","/usr/share/unity/icons/panel-shadow.png",appindicator.IndicatorCategory.HARDWARE)
ind_app.set_status (appindicator.IndicatorStatus.ACTIVE)
# create a menu
menu = Gtk.Menu()
menu_items = Gtk.MenuItem("Salir")
menu.append(menu_items)
menu_items.connect("activate", cb_exit, '')
menu_items.show()
ind_app.set_menu(menu)
GLib.timeout_add(500, refreshData, ind_app)
Gtk.main()