add bundle:telegraf-battery-usage
Some checks failed
kunsi/bundlewrap/pipeline/head There was a failure building this commit

This commit is contained in:
Franzi 2021-11-15 21:18:42 +01:00
parent 330ce6d3a2
commit e17d1ab02f
Signed by: kunsi
GPG key ID: 12E3D2136B818350
7 changed files with 298 additions and 1 deletions

View file

@ -0,0 +1,236 @@
def dashboard_row_battery(panel_id, node):
return {
'title': 'battery',
'collapse': False,
'editable': False,
'height': '250px',
'panels': [
{
'aliasColors': {},
'bars': False,
'dashLength': 10,
'dashes': False,
'datasource': None,
'fieldConfig': {
'defaults': {
'displayName': '${__field.labels.name}'
},
'overrides': []
},
'fill': 0,
'fillGradient': 0,
'hiddenSeries': False,
'id': next(panel_id),
'legend': {
'alignAsTable': False,
'avg': False,
'current': False,
'hideEmpty': True,
'hideZero': True,
'max': False,
'min': False,
'rightSide': False,
'show': True,
'total': False,
'values': False
},
'lines': True,
'linewidth': 1,
'NonePointMode': 'None',
'options': {
'alertThreshold': True
},
'percentage': False,
'pluginVersion': '7.5.5',
'pointradius': 2,
'points': False,
'renderer': 'flot',
'seriesOverrides': [],
'spaceLength': 10,
'span': 8,
'stack': False,
'steppedLine': False,
'targets': [
{
'groupBy': [
{'type': 'time', 'params': ['$__interval']},
{'type': 'fill', 'params': ['linear']},
],
'orderByTime': "ASC",
'policy': "default",
'query': f"""from(bucket: "telegraf")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) =>
r["_measurement"] == "battery" and
r["host"] == "{node.name}" and
(
r["_field"] == "energy_full" or
r["_field"] == "energy_now"
)
)
|> pivot(rowKey:["_time"], columnKey: ["_field"], valueColumn: "_value")
|> map(fn: (r) => ({{
r with
_value: float(v: r.energy_now) / float(v: r.energy_full) * 100.0
}}))
|> drop(columns: ["energy_now", "energy_full"])""",
'resultFormat': 'time_series',
'select': [[
{'type': 'field', 'params': ['value']},
{'type': 'mean', 'params': []},
]],
"tags": []
},
],
'thresholds': [],
'timeRegions': [],
'title': 'battery charge',
'tooltip': {
'shared': True,
'sort': 0,
'value_type': 'individual'
},
'type': 'graph',
'xaxis': {
'buckets': None,
'mode': 'time',
'name': None,
'show': True,
'values': []
},
'yaxes': [
{
'format': 'percent',
'label': None,
'logBase': 1,
'max': 100,
'min': 0,
'show': True,
'decimals': 2,
},
{
'format': 'short',
'label': None,
'logBase': 1,
'max': None,
'min': None,
'show': False,
}
],
'yaxis': {
'align': False,
'alignLevel': None
}
},
{
'aliasColors': {},
'bars': False,
'dashLength': 10,
'dashes': False,
'datasource': None,
'fieldConfig': {
'defaults': {
'displayName': '${__field.labels.name}'
},
'overrides': []
},
'fill': 0,
'fillGradient': 0,
'hiddenSeries': False,
'id': next(panel_id),
'legend': {
'alignAsTable': False,
'avg': False,
'current': False,
'hideEmpty': True,
'hideZero': True,
'max': False,
'min': False,
'rightSide': False,
'show': True,
'total': False,
'values': False
},
'lines': True,
'linewidth': 1,
'NonePointMode': 'None',
'options': {
'alertThreshold': True
},
'percentage': False,
'pluginVersion': '7.5.5',
'pointradius': 2,
'points': False,
'renderer': 'flot',
'seriesOverrides': [],
'spaceLength': 10,
'span': 4,
'stack': False,
'steppedLine': False,
'targets': [
{
'groupBy': [
{'type': 'time', 'params': ['$__interval']},
{'type': 'fill', 'params': ['linear']},
],
'orderByTime': "ASC",
'policy': "default",
'query': f"""from(bucket: "telegraf")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) =>
r["_measurement"] == "battery" and
r["_field"] == "power_now" and
r["host"] == "{node.name}"
)
|> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)
|> yield(name: "fan")""",
'resultFormat': 'time_series',
'select': [[
{'type': 'field', 'params': ['value']},
{'type': 'mean', 'params': []},
]],
"tags": []
},
],
'thresholds': [],
'timeRegions': [],
'title': 'power draw from battery',
'tooltip': {
'shared': True,
'sort': 0,
'value_type': 'individual'
},
'type': 'graph',
'xaxis': {
'buckets': None,
'mode': 'time',
'name': None,
'show': True,
'values': []
},
'yaxes': [
{
'format': 'watts',
'label': None,
'logBase': 1,
'max': None,
'min': 0,
'show': True,
'decimals': 1,
},
{
'format': 'short',
'label': None,
'logBase': 1,
'max': None,
'min': None,
'show': False,
}
],
'yaxis': {
'align': False,
'alignLevel': None
}
},
],
}

View file

@ -104,6 +104,9 @@ for rnode in repo.nodes:
dashboard['rows'].append(dashboard_row_sensors(panel_id, rnode)) dashboard['rows'].append(dashboard_row_sensors(panel_id, rnode))
dashboard['tags'].add('lm-sensors') dashboard['tags'].add('lm-sensors')
if rnode.has_bundle('telegraf-battery-usage'):
dashboard['rows'].append(dashboard_row_battery(panel_id, rnode))
dashboard['rows'].append(dashboard_row_disk_space(panel_id, rnode)) dashboard['rows'].append(dashboard_row_disk_space(panel_id, rnode))
dashboard['rows'].append(dashboard_row_disk_iops(panel_id, rnode)) dashboard['rows'].append(dashboard_row_disk_iops(panel_id, rnode))

View file

@ -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)

View file

@ -0,0 +1,5 @@
files = {
'/usr/local/bin/telegraf-plugin-battery-usage': {
'mode': '0700',
},
}

View 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',
},
},
}

View file

@ -1,7 +1,8 @@
# work laptop. Only apply interactively. # work laptop. Only apply interactively.
nodes['kunsi-seibert-x1'] = { nodes['kunsi-seibert-x1'] = {
'hostname': '172.19.138.243', 'dummy': True,
'hostname': '172.19.138.240',
'bundles': { 'bundles': {
'basic', 'basic',
'lldp', 'lldp',
@ -12,6 +13,7 @@ nodes['kunsi-seibert-x1'] = {
'sudo', 'sudo',
'systemd', 'systemd',
'telegraf', 'telegraf',
'telegraf-battery-usage',
'users', 'users',
}, },
'groups': set(), 'groups': set(),

View file

@ -6,6 +6,7 @@ nodes['kunsi-t470'] = {
'lldp', 'lldp',
'lm-sensors', 'lm-sensors',
'nfs-client', 'nfs-client',
'telegraf-battery-usage',
}, },
'groups': { 'groups': {
'arch', 'arch',