English 中文(简体)
用沙尘
原标题:Get hard disk temperature using Python

我愿获得使用硬磁盘(低于LC)。 I m目前称作hdtemp with subprocess.popen,但我经常说,这只是我的文字中的一个业绩瓶颈。 我认为,应当能够做类似于?

最佳回答
问题回答

Expanding on what @gnibbler suggested in his main comment, what about a cached approach? This is a stupidly simple example just to show the concept:

from collection import defaultdict

class CachedValue(object):
    def __init__(self):
        self.timestamp = -1
        self._value = None

    @property 
    def value(self):
        return self._value

    @value.setter 
    def value(self, val):
        self._value = val 
        self.timestamp = time.time()

    def isOld(self, seconds):
        return (time.time() - self.timestamp) >= seconds

>>> _cached = defaultdict(CachedValue)
>>> _cached[ hddtemp ].isOld(10)
True
>>> _cached[ hddtemp ].value =  Foo 
>>> _cached[ hddtemp ].isOld(10)
False
# (wait 10 seconds)
>>> _cached[ hddtemp ].isOld(10)
True

在你的具体情况下:

def reportHDD(self):
    if self._cached[ hddtemp ].isOld(10):
        self._cached[ hddtemp ].value = self.getNewHDDValue()
    return self._cached[ hddtemp ].value

这种做法实际上更是一般的解决办法,以开展昂贵的行动。 在较大的申请中,可以轻松地用简单明了的电传/再处理来取代CalotValue,这为你保留了自己的TTL值。 但是,从小看,这只是组织地方贴切价值观的原始方法。

我在坐着一个小时,这只击中了近顶点,不管我是如何安排我的搜索。 我所有的东道国都安装了智能mont器,至少安装了2.7.6 p,我不想安装新的包裹,以掌握图表/数据。

我不是开发商,我不知道 p(很显然),因此,这是我每天试图把它混为一谈的。 我非常难于在这里公布所有法典,但这里主要有:

enter code here
#!/usr/bin/env python
import os

import subprocess

import multiprocessing

def grab_hdd_temp(hdd, queue):
  for line in subprocess.Popen([ smartctl ,  -a , str( /dev/  + hdd)], stdout=subprocess.PIPE).stdout.read().split( 
 ):
    if (  Temperature_Celsius  in line.split() ) or ( Temperature_Internal  in line.split() ):
      queue.put([hdd, line.split()[9]])

def hddtmp_dict(hdds_list):
  procs = []
  queue = multiprocessing.Queue()
  hddict={}
  for hdd in hdds_list:
    p = multiprocessing.Process(target=grab_hdd_temp, args=(hdd, queue))
    procs.append(p)
    p.start()
  for _ in procs:
    val = queue.get()
    hddict[val[0]]=val[1]
    p.join()
  return hddict

if __name__ ==  __main__ :
  hdds_list = [ x for x in os.listdir( /sys/block/ ) if x.startswith( sd ) ]
  hddict = hddtmp_dict(hdds_list)
  for k in hddict:
      print(k, hddict[k])

在我的储存服务器上,这把38个驱动器的完整清单从2秒起即50秒通过所有系列磁盘旋。 也就是说,在40个核心箱子上,负荷从1.08 around升至3.50.。 因此,正如你所希望的那样。 我正试图找到一种办法,在另一个批量超支的基础上使用

第2点:22am在这里,我需要开始在家里工作。 一旦到场,我就尝试并概述上述幻灯片,并说我认为一切都做了些什么,但我希望它稍作解释。

法官法典职业。 我认为,此时此刻,缓冲是更好的途径,但它是一种冷却行动。 如果你不想安装头盔,我认为这是最好的选择。 尽管如此,我还是试图说明这一点,而且我也不知道如何办课。

我希望这能帮助某人。





相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签