Python,rrdtool创建 - 时间戳,时区

时间:2012-07-18 15:03:39

标签: python timezone ubuntu-10.04 epoch rrdtool

大家好,欢迎大家!

我的python脚本创建了一个rrd文件。 create_rrd和update函数以值“interval”和“starttime”(当前纪元)启动。使用这些功能时,纪元时间是正确的。但是:在rrd文件上执行rrdtool fetch,最后一个时间戳是每次2小时前。我使用ENV'TZ'调用subprocess.Popen的技巧不起作用。 所以所有rrd文件更新都失败了。 有谁知道为什么,我做错了什么?

祝你好运 斯蒂芬

    def create_rrd(self, interval, starttime):
    interval = str(interval)
    interval_mins = float(interval) / 60
    heartbeat = str(int(interval) * 2)
    ds_string = 'DS:test:GAUGE:%s:U:U' % heartbeat
    rra_1 = 'RRA:AVERAGE:0.5:1:' + str(int(4000 / interval_mins))
    rra_2 = 'RRA:AVERAGE:0.5:' +  str(int(30 / interval_mins)) + ':800'
    rra_3 = 'RRA:AVERAGE:0.5:' + str(int(120 / interval_mins)) + ':800'
    rra_4 = 'RRA:AVERAGE:0.5:' + str(int(1440 / interval_mins)) + ':800'
    cmd_create = [
        '/omd/versions/default/bin/rrdtool',
        'create',
        self.rrd_name,
        '-b',
        str(starttime-10),
        '--step',
        interval,
        ds_string,
        rra_1,
        rra_2,
        rra_3 ,
        rra_4,
    ]
    print cmd_create
    cmd = Popen(cmd_create, stdout=PIPE, stderr=PIPE, env={'LANG':'de_DE@euro','TZ':'Europe/Berlin'})
    cmd_output = cmd.communicate()
    self.errorprint(cmd_output)
    #p = Popen(["date"], env={'TZ':'America/New_York'})
    #p.wait()
    #p = Popen(["date"], env={'TZ':'Europe/Berlin'})
    #p.wait()


def update(self, starttime, *values):
    values_args = ''.join([str(value) + ':' for value in values])[:-1]
    values_final = '%s:%s' % (str(starttime), values_args)
    cmd_update = [
                '/omd/versions/default/bin/rrdtool',
                'update',
                self.rrd_name,
                values_final,
    ]
    print cmd_update
    cmd = Popen(cmd_update, stdout=PIPE, stderr=PIPE, env={'LANG':'de_DE@euro','TZ':'Europe/Berlin'})
    cmd_output = cmd.communicate()
    self.errorprint(cmd_output

以下是用于创建和更新的Popen的命令列表:

rrd create
['/omd/versions/default/bin/rrdtool', 'create', '/tmp/test1/CPU_utilization_util.rrd', '-b', '1342630417', '--step', '300', 'DS:test:GAUGE:600:U:U', 'RRA:AVERAGE:0.5:1:800', 'RRA:AVERAGE:0.5:6:800', 'RRA:AVERAGE:0.5:24:800', 'RRA:AVERAGE:0.5:288:800']
rrd update
['/omd/versions/default/bin/rrdtool', 'update', '/tmp/test1/CPU_utilization_util.rrd', '1342630427:8.37649086759']

0 个答案:

没有答案