configure collectd
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/python
|
||||
#!/usr/bin/python3
|
||||
|
||||
#
|
||||
# Imports
|
||||
@@ -6,61 +6,58 @@
|
||||
import sys
|
||||
import time
|
||||
import argparse
|
||||
import pylikwid
|
||||
import pmt
|
||||
|
||||
#
|
||||
# Configuration
|
||||
#
|
||||
hostname = 'server'
|
||||
cpuid = 0
|
||||
pinfo = pylikwid.getpowerinfo()
|
||||
domainid = pinfo.get('domains').get('PKG').get('ID')
|
||||
measurement_duration = 10
|
||||
measurement_interval = 60
|
||||
dinfo = pinfo.get('domains')
|
||||
domain_names = dinfo.keys()
|
||||
domain_ids = [domain['ID'] for domain in dinfo.values()]
|
||||
hostname = "shuttle"
|
||||
measurement_duration = 5
|
||||
measurement_interval = 15
|
||||
pm = pmt.create("rapl")
|
||||
|
||||
#
|
||||
# Command line arguments
|
||||
#
|
||||
parser = argparse.ArgumentParser(description='Get CPU power consumption')
|
||||
parser.add_argument('-s', action='store_true', help='print in human readable format')
|
||||
parser = argparse.ArgumentParser(description="Get CPU power consumption")
|
||||
parser.add_argument("-s", action="store_true", help="print in human readable format")
|
||||
args = parser.parse_args()
|
||||
human_readable = args.s
|
||||
|
||||
#
|
||||
# Methods
|
||||
#
|
||||
def get_power():
|
||||
#print dict(zip(domain_names, domain_ids))
|
||||
start = list()
|
||||
end = list()
|
||||
power = list()
|
||||
for domain_id in domain_ids:
|
||||
e_start = pylikwid.startpower(cpuid, domain_id)
|
||||
start.append(e_start)
|
||||
time.sleep(measurement_duration)
|
||||
for domain_id in domain_ids:
|
||||
e_stop = pylikwid.stoppower(cpuid, domain_id)
|
||||
end.append(e_stop)
|
||||
for events in zip(start, end, domain_ids):
|
||||
power.append(pylikwid.getpower(events[0], events[1], events[2]))
|
||||
|
||||
return dict(zip(domain_names, power))
|
||||
#
|
||||
# Methods
|
||||
#
|
||||
def get_power():
|
||||
time.sleep(measurement_duration)
|
||||
measurements = dict()
|
||||
state = pm.read()
|
||||
for i in range(state.nr_measurements()):
|
||||
name = state.name(i)
|
||||
watts = state.watts(i)
|
||||
measurements[name] = watts
|
||||
return measurements
|
||||
|
||||
|
||||
def print_rrd(measurements):
|
||||
timestamp = int(time.time())
|
||||
for measurement in measurements.items():
|
||||
for measurement in list(measurements.items()):
|
||||
name = measurement[0].lower()
|
||||
power = measurement[1]
|
||||
print('PUTVAL {}/exec-power/gauge-{} {}:{:.1f}'.format(hostname, name, timestamp, power))
|
||||
print(
|
||||
(
|
||||
"PUTVAL {}/exec-power/gauge-{} {}:{:.1f}".format(
|
||||
hostname, name, timestamp, power
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
#
|
||||
# Main
|
||||
#
|
||||
if (human_readable):
|
||||
print get_power()
|
||||
if human_readable:
|
||||
print(get_power())
|
||||
else:
|
||||
while True:
|
||||
power = get_power()
|
||||
|
||||
Reference in New Issue
Block a user