add bundle:telegraf-battery-usage
Some checks failed
kunsi/bundlewrap/pipeline/head There was a failure building this commit
Some checks failed
kunsi/bundlewrap/pipeline/head There was a failure building this commit
This commit is contained in:
parent
330ce6d3a2
commit
e17d1ab02f
7 changed files with 298 additions and 1 deletions
|
@ -0,0 +1,33 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
from os import listdir
|
||||
from os.path import join
|
||||
from sys import exit, stderr
|
||||
|
||||
try:
|
||||
for power_supply in listdir('/sys/class/power_supply/'):
|
||||
if power_supply.startswith('BAT'):
|
||||
out = {}
|
||||
|
||||
for measurement in {
|
||||
'capacity',
|
||||
'cycle_count',
|
||||
'energy_full',
|
||||
'energy_full_design',
|
||||
'energy_now',
|
||||
'power_now',
|
||||
'voltage_now',
|
||||
}:
|
||||
try:
|
||||
with open(join('/sys/class/power_supply', power_supply, measurement)) as f:
|
||||
out[measurement] = f.read().splitlines()[0].strip()
|
||||
except Exception as e:
|
||||
print(repr(e), file=stderr)
|
||||
|
||||
print('battery,name={} {}'.format(
|
||||
power_supply,
|
||||
','.join([f'{k}={v}' for k, v in sorted(out.items())]),
|
||||
))
|
||||
except Exception as e:
|
||||
print(repr(e), file=stderr)
|
||||
exit(1)
|
5
bundles/telegraf-battery-usage/items.py
Normal file
5
bundles/telegraf-battery-usage/items.py
Normal file
|
@ -0,0 +1,5 @@
|
|||
files = {
|
||||
'/usr/local/bin/telegraf-plugin-battery-usage': {
|
||||
'mode': '0700',
|
||||
},
|
||||
}
|
17
bundles/telegraf-battery-usage/metadata.py
Normal file
17
bundles/telegraf-battery-usage/metadata.py
Normal file
|
@ -0,0 +1,17 @@
|
|||
defaults = {
|
||||
'telegraf': {
|
||||
'input_plugins': {
|
||||
'exec': {
|
||||
'battery-usage': {
|
||||
'commands': ['sudo /usr/local/bin/telegraf-plugin-battery-usage'],
|
||||
'data_format': 'influx',
|
||||
'timeout': '5s',
|
||||
'interval': '15s',
|
||||
},
|
||||
},
|
||||
},
|
||||
'sudo_commands': {
|
||||
'/usr/local/bin/telegraf-plugin-battery-usage',
|
||||
},
|
||||
},
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue