Ejemplo n.º 1
0
def test_percentage():
    stat1 = cpustats.getstats()
    time.sleep(0.250)
    stat2 = cpustats.getstats()
    difference = cpustats.diff(stat1, stat2)
    percentage = {}
    for cpu, stats in difference.items():
        percentage[cpu] = cpustats.calcratio(stats)

    for cpu, stats in percentage.items():
        yield check_percentage, sum(stats.values())
Ejemplo n.º 2
0
import cpustats
import time

import graphite

BASEPATH = "angmar.stats"
graphite.connect()
while True:
    timestamp = int(time.time())
    stats = []
    stats.append(cpustats.getstats())
    #while time.time() <= timestamp + 1:
    time.sleep(0.250)
    stats.append(cpustats.getstats())
    result = cpustats.diff(stats[0], stats[1])
    percentages = {}
    for cpu, stats in result.items():
        percentages[cpu] = cpustats.calcratio(stats)
        if sum(percentages[cpu].values()) > 101 or sum(
                percentages[cpu].values()) < 99:
            print(percentages[cpu])

    for cpu, stats in percentages.items():
        #print(cpu,sum(stats.values()))
        for name, stat in stats.items():
            graphite.send_data(BASEPATH + ".%s.%s" % (cpu, name), stat,
                               timestamp)

graphite.close()
Ejemplo n.º 3
0
import cpustats
import time

import graphite

BASEPATH = "angmar.stats"
graphite.connect()
while True:
	timestamp = int(time.time())
	stats = []
	stats.append(cpustats.getstats())
	#while time.time() <= timestamp + 1:
	time.sleep(0.250)
	stats.append(cpustats.getstats())
	result = cpustats.diff(stats[0],stats[1])
	percentages = {}
	for cpu,stats in result.items():
		percentages[cpu] = cpustats.calcratio(stats)
		if sum(percentages[cpu].values()) > 101 or sum(percentages[cpu].values()) < 99:
			print(percentages[cpu])


	for cpu,stats in percentages.items():
		#print(cpu,sum(stats.values()))
		for name,stat in stats.items():
			graphite.send_data(BASEPATH+".%s.%s"%(cpu,name),stat,timestamp)

graphite.close()