Permalink
Browse files

Update plugins/dstat_thermal.py

  • Loading branch information...
1 parent 04a3ead commit efb8bfa1eac0759c141fabbf8428f130d405f754 eugenio committed Mar 7, 2012
Showing with 27 additions and 4 deletions.
  1. +27 −4 plugins/dstat_thermal.py
@@ -6,26 +6,35 @@ def __init__(self):
self.type = 'd'
self.width = 3
self.scale = 20
- if os.path.exists('/proc/acpi/ibm/thermal'):
+ if os.path.exists('/sys/bus/acpi/devices/LNXTHERM:00/thermal_zone/'):
+ self.vars = os.listdir('/sys/bus/acpi/devices/LNXTHERM:00/thermal_zone/')
+ # self.nick = [name.lower() for name in self.vars]
+ self.nick = []
+ for name in self.vars:
+ self.nick.append(name.lower())
+
+ elif os.path.exists('/proc/acpi/ibm/thermal'):
self.namelist = ['cpu', 'pci', 'hdd', 'cpu', 'ba0', 'unk', 'ba1', 'unk']
self.nick = []
for line in dopen('/proc/acpi/ibm/thermal'):
l = line.split()
for i, name in enumerate(self.namelist):
if int(l[i+1]) > 0:
self.nick.append(name)
- self.vars = self.nick
+ self.vars = self.nick
+
elif os.path.exists('/proc/acpi/thermal_zone/'):
self.vars = os.listdir('/proc/acpi/thermal_zone/')
-# self.nick = [name.lower() for name in self.vars]
+ # self.nick = [name.lower() for name in self.vars]
self.nick = []
for name in self.vars:
self.nick.append(name.lower())
+
else:
raise Exception, 'Needs kernel ACPI or IBM-ACPI support'
def check(self):
- if not os.path.exists('/proc/acpi/ibm/thermal') and not os.path.exists('/proc/acpi/thermal_zone/'):
+ if not os.path.exists('/proc/acpi/ibm/thermal') and not os.path.exists('/proc/acpi/thermal_zone/') and not os.path.exists('/sys/bus/acpi/devices/LNXTHERM:00/thermal_zone/'):
raise Exception, 'Needs kernel ACPI or IBM-ACPI support'
def extract(self):
@@ -35,10 +44,24 @@ def extract(self):
for i, name in enumerate(self.namelist):
if int(l[i+1]) > 0:
self.val[name] = int(l[i+1])
+
elif os.path.exists('/proc/acpi/thermal_zone/'):
for zone in self.vars:
for line in dopen('/proc/acpi/thermal_zone/'+zone+'/temperature').readlines():
l = line.split()
self.val[zone] = int(l[1])
+ elif os.path.exists('/sys/bus/acpi/devices/LNXTHERM:00/thermal_zone/'):
+ for zone in self.vars:
+ if os.path.isdir('/sys/bus/acpi/devices/LNXTHERM:00/thermal_zone/'+zone) == False:
+ for line in dopen('/sys/bus/acpi/devices/LNXTHERM:00/thermal_zone/'+zone).readlines():
+ l = line.split()
+ if l[0].isdigit() == True:
+ self.val[zone] = int(l[0])
+ else:
+ self.val[zone] = 0
+
+
+
+
# vim:ts=4:sw=4:et

5 comments on commit efb8bfa

@dagwieers
Owner

I have a few remarks:

  • The order of testing what infrastructure is used is different in the init() and extract() phase, this could lead to problems if you have more than one infrastructure (e.g. I have ibm_acpi and /sys/bus/acpi)
  • On my system I have both a LNXTHERM:00 and LNXTHERM:01, where the first has no thermal_zone entry, and the second does
  • When changing to LNXTHERM:01, it works but I see too many counters that are useless:
    [root@moria dstat]# ./dstat --thermal ----------------------------------thermal---------------------------------- uev sub pow typ tem mod tri tri tri tri cde cde cde cde cde cde cde cde dev 0 0 0 0 50 0 0 100 0 91 0 1 0 1 0 1 0 1 0 0 0 0 0 50 0 0 100 0 91 0 1 0 1 0 1 0 1 0 0 0 0 0 50 0 0 100 0 91 0 1 0 1 0 1 0 1 0 0 0 0 0 50 0 0 100 0 91 0 1 0 1 0 1 0 1 0
@eugenio
  • The order of testing what infrastructure is used is different in the init() and extract() phase, this could lead to problems if you have more than one infrastructure (e.g. I have ibm_acpi and /sys/bus/acpi)

Ok , I didn't know that. If it's ok for you I'll correct this in next commit.

  • On my system I have both a LNXTHERM:00 and LNXTHERM:01, where the first has no thermal_zone entry, and the second does

I suspected that an issue like that could arise, but I had no way to know as I have only one system to test on. I asked a friend of mine to test the patched file but he forgot to do it up'til now.

  • When changing to LNXTHERM:01, it works but I see too many counters that are useless

Yes, I noticed that too but, at the time I didn't find a solution to, and I'm new to python and its lack of the switch-case construct ha left me a little out of ideas. I'll search for a solution to put in the next commit.
Thanks for the hints,
Eugenio.

@eugenio

I managed to find a solution to show only the temperature column on the output, but so far no clue on how to find out the correct path in /sys/bus/acpi/devices/LNXTHERM:XX where XX stands for the number of lnxtherm. the only solutions I can think of is to check every single lnxtherm for the the path to temp or hardcode every possible temp path, but both seem unpractical at the moment.

@dagwieers
Owner

The exact LNXTHERM instances to be used (yes plural) can be done using globs, the result of such a glob is a list of every entry. Afterwards, the list can be cleaned up further by iterating and checking conditions. An example of this is in dstat_cpufreq.

@eugenio

I think I have a candidate for a complete solution.

### Author: Dag Wieers <dag@wieers.com>

class dstat_plugin(dstat):
    def __init__(self):
        self.name = 'thermal'
        self.type = 'd'
        self.width = 3
        self.scale = 20

        if os.path.exists('/proc/acpi/ibm/thermal'):
            self.namelist = ['cpu', 'pci', 'hdd', 'cpu', 'ba0', 'unk', 'ba1', 'unk']
            self.nick = []
            for line in dopen('/proc/acpi/ibm/thermal'):
                l = line.split()
                for i, name in enumerate(self.namelist):
                    if int(l[i+1]) > 0:
                        self.nick.append(name)
                        self.vars = self.nick

        elif os.path.exists('/proc/acpi/thermal_zone/'):
            self.vars = os.listdir('/proc/acpi/thermal_zone/')
            # self.nick = [name.lower() for name in self.vars]
            self.nick = []
            for name in self.vars:
                self.nick.append(name.lower())

        elif os.path.exists('/sys/bus/acpi/devices/'):
            self.vars = []
            for dirnames in glob.glob('/sys/bus/acpi/devices/LNXTHERM:[0-9]*/'):
                if not os.access(dirnames+'/thermal_zone/temp', os.R_OK):
                    raise Exception, 'Cannot access acpi %s temperature information' % os.path.basename(dirnames)
                else:    
                    self.vars.append(dirnames+'thermal_zone/temp')
                    print self.vars
                    self.nick = []
                    for path in self.vars:

                        self.nick.append(os.path.basename(path))
        else:
            raise Exception, 'Needs kernel ACPI or IBM-ACPI support pippo'

    def check(self):
        if not os.path.exists('/proc/acpi/ibm/thermal') and not os.path.exists('/proc/acpi/thermal_zone/') and not self.check_dirnames:
            raise Exception, 'Needs kernel ACPI or IBM-ACPI support pluto'

    def check_dirnames(self):
        for dirnames in glob.glob('/sys/bus/acpi/devices/LNXTHERM:[0-9]*/'):
                if not os.access(dirnames+'/thermal_zone/temp', os.R_OK):
                    print 'Cannot access acpi %s temperature information' % os.path.basename(dirnames)
                else:
                    return True

    def extract(self):
        if os.path.exists('/proc/acpi/ibm/thermal'):
            for line in dopen('/proc/acpi/ibm/thermal'):
                l = line.split()
                for i, name in enumerate(self.namelist):
                    if int(l[i+1]) > 0:
                        self.val[name] = int(l[i+1])

        elif os.path.exists('/proc/acpi/thermal_zone/'):
            for zone in self.vars:
                for line in dopen('/proc/acpi/thermal_zone/'+zone+'/temperature').readlines():
                    l = line.split()
                    self.val[zone] = int(l[1])

        else:
            for entry in self.vars:
                    if os.access(entry, os.R_OK):
                           for line in dopen(entry).readlines():
                            l = line.split()
                            self.val[entry] = int(l[0])

 # vim:ts=4:sw=4:et

waiting for your comments :)
Eugenio.

Please sign in to comment.