bundles/telegraf/items.py: use new bundle from isac

This commit is contained in:
CroneKorkN 2026-01-11 09:44:16 +01:00
parent 982a27739a
commit 49594610d3
Signed by: cronekorkn
SSH key fingerprint: SHA256:v0410ZKfuO1QHdgKBsdQNF64xmTxOF8osF1LIqwTcVw
12 changed files with 520 additions and 462 deletions

View file

@ -13,16 +13,14 @@ defaults = {
}, },
}, },
'telegraf': { 'telegraf': {
'config': {
'inputs': { 'inputs': {
'exec': { 'exec': {
repo.libs.hashable.hashable({ 'apcupsd': {
'commands': ["sudo /usr/local/share/telegraf/apcupsd"], 'commands': ["sudo /usr/local/share/telegraf/apcupsd"],
'name_override': "apcupsd", 'name_override': "apcupsd",
'data_format': "influx", 'data_format': "influx",
'interval': '30s', 'interval': '30s',
'flush_interval': '30s', 'flush_interval': '30s',
}),
}, },
}, },
}, },

View file

@ -49,13 +49,13 @@ defaults = {
}, },
}, },
'telegraf': { 'telegraf': {
'config': {
'inputs': { 'inputs': {
'bind': [{ 'bind': {
'default': {
'urls': ['http://localhost:8053/xml/v3'], 'urls': ['http://localhost:8053/xml/v3'],
'gather_memory_contexts': False, 'gather_memory_contexts': False,
'gather_views': True, 'gather_views': True,
}], },
}, },
}, },
}, },

View file

@ -14,17 +14,18 @@ defaults = {
}, },
}, },
'telegraf': { 'telegraf': {
'config': {
'inputs': { 'inputs': {
'sensors': {repo.libs.hashable.hashable({ 'sensors': {
'default': {
'timeout': '2s', 'timeout': '2s',
})}, },
},
'exec': { 'exec': {
repo.libs.hashable.hashable({ 'cpu_frequency': {
'commands': ["sudo /usr/local/share/telegraf/cpu_frequency"], 'commands': ["sudo /usr/local/share/telegraf/cpu_frequency"],
'name_override': "cpu_frequency", 'name_override': "cpu_frequency",
'data_format': "influx", 'data_format': "influx",
}), },
# repo.libs.hashable.hashable({ # repo.libs.hashable.hashable({
# 'commands': ["/bin/bash -c 'expr $(cat /sys/class/thermal/thermal_zone0/temp) / 1000'"], # 'commands': ["/bin/bash -c 'expr $(cat /sys/class/thermal/thermal_zone0/temp) / 1000'"],
# 'name_override': "cpu_temperature", # 'name_override': "cpu_temperature",
@ -34,5 +35,4 @@ defaults = {
}, },
}, },
}, },
},
} }

View file

@ -25,9 +25,9 @@ defaults = {
}, },
}, },
'telegraf': { 'telegraf': {
'config': {
'inputs': { 'inputs': {
'postfix': [{}], 'postfix': {
'default': {},
}, },
}, },
}, },

View file

@ -98,17 +98,17 @@ def zfs(metadata):
@metadata_reactor.provides( @metadata_reactor.provides(
'telegraf/config/inputs/postgresql', 'telegraf/inputs/postgresql/default',
) )
def telegraf(metadata): def telegraf(metadata):
return { return {
'telegraf': { 'telegraf': {
'config': {
'inputs': { 'inputs': {
'postgresql': [{ 'postgresql': {
'default': {
'address': f'postgres://root:{root_password}@localhost:5432/postgres', 'address': f'postgres://root:{root_password}@localhost:5432/postgres',
'databases': sorted(list(node.metadata.get('postgresql/databases').keys())), 'databases': sorted(list(node.metadata.get('postgresql/databases').keys())),
}], },
}, },
}, },
}, },

View file

@ -8,16 +8,14 @@ defaults = {
@metadata_reactor.provides( @metadata_reactor.provides(
'telegraf/config/agent', 'telegraf/agent',
) )
def telegraf(metadata): def telegraf(metadata):
return { return {
'telegraf': { 'telegraf': {
'config': {
'agent': { 'agent': {
'flush_interval': '30s', 'flush_interval': '30s',
'interval': '30s', 'interval': '1m',
},
}, },
}, },
} }

View file

@ -1,344 +1,344 @@
h = repo.libs.hashable.hashable # h = repo.libs.hashable.hashable
defaults = { # defaults = {
'apt': { # 'apt': {
'packages': { # 'packages': {
'snmp': {}, # 'snmp': {},
'snmp-mibs-downloader': {}, # 'snmp-mibs-downloader': {},
}, # },
}, # },
} # }
@metadata_reactor.provides( # @metadata_reactor.provides(
'telegraf/config/inputs/snmp', # 'telegraf/inputs/snmp',
) # )
def routeros_monitoring_telegraf_inputs(metadata): # def routeros_monitoring_telegraf_inputs(metadata):
return { # return {
"telegraf": { # "telegraf": {
"config": { # "config": {
"processors": { # "processors": {
"enum": [ # "enum": [
h({ # h({
"tagpass": { # "tagpass": {
"operating_system": ["routeros"], # "operating_system": ["routeros"],
}, # },
"mapping": [ # "mapping": [
h({ # h({
"tag": "agent_host", # "tag": "agent_host",
"dest": "host", # "dest": "host",
"default": "unknown", # "default": "unknown",
"value_mappings": { # "value_mappings": {
routeros_node.hostname: routeros_node.name # routeros_node.hostname: routeros_node.name
for routeros_node in repo.nodes_in_group("routeros") # for routeros_node in repo.nodes_in_group("routeros")
}, # },
}) # })
] # ]
}) # })
] # ]
}, # },
"inputs": { # "inputs": {
"snmp": { # "snmp": {
h({ # h({
"agents": [ # "agents": [
f"udp://{routeros_node.hostname}:161" # f"udp://{routeros_node.hostname}:161"
for routeros_node in repo.nodes_in_group("routeros") # for routeros_node in repo.nodes_in_group("routeros")
], # ],
"version": 2, # "version": 2,
"community": "public", # "community": "public",
"interval": "30s", # "interval": "30s",
"tags": { # "tags": {
"operating_system": "routeros", # "operating_system": "routeros",
}, # },
"table": [ # "table": [
# MikroTik Health (table) # # MikroTik Health (table)
{ # {
"name": "hw", # "name": "hw",
"oid": "MIKROTIK-MIB::mtxrGaugeTable", # "oid": "MIKROTIK-MIB::mtxrGaugeTable",
"field": [ # "field": [
{ # {
"name": "sensor", # "name": "sensor",
"oid": "MIKROTIK-MIB::mtxrGaugeName", # "oid": "MIKROTIK-MIB::mtxrGaugeName",
"is_tag": True, # "is_tag": True,
}, # },
{ # {
"name": "value", # "name": "value",
"oid": "MIKROTIK-MIB::mtxrGaugeValue", # "oid": "MIKROTIK-MIB::mtxrGaugeValue",
}, # },
{ # {
"name": "unit", # "name": "unit",
"oid": "MIKROTIK-MIB::mtxrGaugeUnit", # "oid": "MIKROTIK-MIB::mtxrGaugeUnit",
"is_tag": True, # "is_tag": True,
}, # },
], # ],
}, # },
# Interface statistics (standard IF-MIB) # # Interface statistics (standard IF-MIB)
{ # {
"name": "interface", # "name": "interface",
"oid": "IF-MIB::ifTable", # "oid": "IF-MIB::ifTable",
"field": [ # "field": [
# 6: ethernetCsmacd (physischer Ethernet-Port) # # 6: ethernetCsmacd (physischer Ethernet-Port)
# 24: softwareLoopback # # 24: softwareLoopback
# 53: propVirtual (oft VLANs bei MikroTik) # # 53: propVirtual (oft VLANs bei MikroTik)
# 131: tunnel # # 131: tunnel
# 135: l2vlan # # 135: l2vlan
# 161: ieee8023adLag (Bonding/LACP) # # 161: ieee8023adLag (Bonding/LACP)
# 209: bridge # # 209: bridge
{ # {
"name": "ifType", # "name": "ifType",
"oid": "IF-MIB::ifType", # "oid": "IF-MIB::ifType",
"is_tag": True, # "is_tag": True,
}, # },
# Labels (optional but recommended) # # Labels (optional but recommended)
{ # {
"name": "ifName", # "name": "ifName",
"oid": "IF-MIB::ifName", # "oid": "IF-MIB::ifName",
"is_tag": True, # "is_tag": True,
}, # },
{ # {
"name": "ifAlias", # "name": "ifAlias",
"oid": "IF-MIB::ifAlias", # "oid": "IF-MIB::ifAlias",
"is_tag": True, # "is_tag": True,
}, # },
# Bytes (64-bit) # # Bytes (64-bit)
{ # {
"name": "in_octets", # "name": "in_octets",
"oid": "IF-MIB::ifHCInOctets", # "oid": "IF-MIB::ifHCInOctets",
}, # },
{ # {
"name": "out_octets", # "name": "out_octets",
"oid": "IF-MIB::ifHCOutOctets", # "oid": "IF-MIB::ifHCOutOctets",
}, # },
# Packets (64-bit unicast) # # Packets (64-bit unicast)
{ # {
"name": "in_ucast_pkts", # "name": "in_ucast_pkts",
"oid": "IF-MIB::ifHCInUcastPkts", # "oid": "IF-MIB::ifHCInUcastPkts",
}, # },
{ # {
"name": "out_ucast_pkts", # "name": "out_ucast_pkts",
"oid": "IF-MIB::ifHCOutUcastPkts", # "oid": "IF-MIB::ifHCOutUcastPkts",
}, # },
{ # {
"name": "in_mcast_pkts", # "name": "in_mcast_pkts",
"oid": "IF-MIB::ifHCInMulticastPkts", # "oid": "IF-MIB::ifHCInMulticastPkts",
}, # },
{ # {
"name": "in_bcast_pkts", # "name": "in_bcast_pkts",
"oid": "IF-MIB::ifHCInBroadcastPkts", # "oid": "IF-MIB::ifHCInBroadcastPkts",
}, # },
{ # {
"name": "out_mcast_pkts", # "name": "out_mcast_pkts",
"oid": "IF-MIB::ifHCOutMulticastPkts", # "oid": "IF-MIB::ifHCOutMulticastPkts",
}, # },
{ # {
"name": "out_bcast_pkts", # "name": "out_bcast_pkts",
"oid": "IF-MIB::ifHCOutBroadcastPkts", # "oid": "IF-MIB::ifHCOutBroadcastPkts",
}, # },
# Drops / Errors # # Drops / Errors
{ # {
"name": "in_discards", # "name": "in_discards",
"oid": "IF-MIB::ifInDiscards", # "oid": "IF-MIB::ifInDiscards",
}, # },
{ # {
"name": "out_discards", # "name": "out_discards",
"oid": "IF-MIB::ifOutDiscards", # "oid": "IF-MIB::ifOutDiscards",
}, # },
{ # {
"name": "in_errors", # "name": "in_errors",
"oid": "IF-MIB::ifInErrors", # "oid": "IF-MIB::ifInErrors",
}, # },
{ # {
"name": "out_errors", # "name": "out_errors",
"oid": "IF-MIB::ifOutErrors", # "oid": "IF-MIB::ifOutErrors",
}, # },
], # ],
}, # },
# Interface statistics (MikroTik-specific mib) # # Interface statistics (MikroTik-specific mib)
{ # {
"name": "interface_errors", # "name": "interface_errors",
"oid": "MIKROTIK-MIB::mtxrInterfaceStatsTable", # "oid": "MIKROTIK-MIB::mtxrInterfaceStatsTable",
"field": [ # "field": [
# Join key / label (usually identical to IF-MIB ifName) # # Join key / label (usually identical to IF-MIB ifName)
{ # {
"name": "ifName", # "name": "ifName",
"oid": "MIKROTIK-MIB::mtxrInterfaceStatsName", # "oid": "MIKROTIK-MIB::mtxrInterfaceStatsName",
"is_tag": True, # "is_tag": True,
}, # },
# join IF-MIB for better labels # # join IF-MIB for better labels
{ # {
"name": "ifAlias", # "name": "ifAlias",
"oid": "IF-MIB::ifAlias", # "oid": "IF-MIB::ifAlias",
"is_tag": True, # "is_tag": True,
}, # },
# ========================= # # =========================
# Physical layer (L1/L2) # # Physical layer (L1/L2)
# ========================= # # =========================
# CRC/FCS errors → very often cabling, connectors, SFPs, signal quality (EMI) # # CRC/FCS errors → very often cabling, connectors, SFPs, signal quality (EMI)
{ # {
"name": "rx_fcs_errors", # "name": "rx_fcs_errors",
"oid": "MIKROTIK-MIB::mtxrInterfaceStatsRxFCSError", # "oid": "MIKROTIK-MIB::mtxrInterfaceStatsRxFCSError",
}, # },
# Alignment errors → typically duplex mismatch or PHY problems # # Alignment errors → typically duplex mismatch or PHY problems
{ # {
"name": "rx_align_errors", # "name": "rx_align_errors",
"oid": "MIKROTIK-MIB::mtxrInterfaceStatsRxAlignError", # "oid": "MIKROTIK-MIB::mtxrInterfaceStatsRxAlignError",
}, # },
# Code errors → PHY encoding errors (signal/SFP/PHY) # # Code errors → PHY encoding errors (signal/SFP/PHY)
{ # {
"name": "rx_code_errors", # "name": "rx_code_errors",
"oid": "MIKROTIK-MIB::mtxrInterfaceStatsRxCodeError", # "oid": "MIKROTIK-MIB::mtxrInterfaceStatsRxCodeError",
}, # },
# Carrier errors → carrier lost (copper issues, autoneg, PHY instability) # # Carrier errors → carrier lost (copper issues, autoneg, PHY instability)
{ # {
"name": "rx_carrier_errors", # "name": "rx_carrier_errors",
"oid": "MIKROTIK-MIB::mtxrInterfaceStatsRxCarrierError", # "oid": "MIKROTIK-MIB::mtxrInterfaceStatsRxCarrierError",
}, # },
# Jabber → extremely long invalid frames (faulty NIC/PHY, very severe) # # Jabber → extremely long invalid frames (faulty NIC/PHY, very severe)
{ # {
"name": "rx_jabber", # "name": "rx_jabber",
"oid": "MIKROTIK-MIB::mtxrInterfaceStatsRxJabber", # "oid": "MIKROTIK-MIB::mtxrInterfaceStatsRxJabber",
}, # },
# ================================== # # ==================================
# Length / framing anomalies (diagnostic) # # Length / framing anomalies (diagnostic)
# ================================== # # ==================================
# Frames shorter than minimum (noise, collisions, broken sender) # # Frames shorter than minimum (noise, collisions, broken sender)
{ # {
"name": "rx_too_short", # "name": "rx_too_short",
"oid": "MIKROTIK-MIB::mtxrInterfaceStatsRxTooShort", # "oid": "MIKROTIK-MIB::mtxrInterfaceStatsRxTooShort",
}, # },
# Frames longer than allowed (MTU mismatch, framing errors) # # Frames longer than allowed (MTU mismatch, framing errors)
{ # {
"name": "rx_too_long", # "name": "rx_too_long",
"oid": "MIKROTIK-MIB::mtxrInterfaceStatsRxTooLong", # "oid": "MIKROTIK-MIB::mtxrInterfaceStatsRxTooLong",
}, # },
# Fragments (often collision-related or duplex mismatch) # # Fragments (often collision-related or duplex mismatch)
{ # {
"name": "rx_fragment", # "name": "rx_fragment",
"oid": "MIKROTIK-MIB::mtxrInterfaceStatsRxFragment", # "oid": "MIKROTIK-MIB::mtxrInterfaceStatsRxFragment",
}, # },
# Generic length errors # # Generic length errors
{ # {
"name": "rx_length_errors", # "name": "rx_length_errors",
"oid": "MIKROTIK-MIB::mtxrInterfaceStatsRxLengthError", # "oid": "MIKROTIK-MIB::mtxrInterfaceStatsRxLengthError",
}, # },
# ================== # # ==================
# Drops (real packet loss) # # Drops (real packet loss)
# ================== # # ==================
# RX drops (queue/ASIC/policy/overload) → highly alert-worthy # # RX drops (queue/ASIC/policy/overload) → highly alert-worthy
{ # {
"name": "rx_drop", # "name": "rx_drop",
"oid": "MIKROTIK-MIB::mtxrInterfaceStatsRxDrop", # "oid": "MIKROTIK-MIB::mtxrInterfaceStatsRxDrop",
}, # },
# TX drops (buffer/queue exhaustion, scheduling, ASIC limits) # # TX drops (buffer/queue exhaustion, scheduling, ASIC limits)
{ # {
"name": "tx_drop", # "name": "tx_drop",
"oid": "MIKROTIK-MIB::mtxrInterfaceStatsTxDrop", # "oid": "MIKROTIK-MIB::mtxrInterfaceStatsTxDrop",
}, # },
# ========================================= # # =========================================
# Duplex / collision indicators # # Duplex / collision indicators
# (should be zero on full-duplex links) # # (should be zero on full-duplex links)
# ========================================= # # =========================================
# Total collisions (relevant only for half-duplex or misconfigurations) # # Total collisions (relevant only for half-duplex or misconfigurations)
{ # {
"name": "tx_collisions", # "name": "tx_collisions",
"oid": "MIKROTIK-MIB::mtxrInterfaceStatsTxCollision", # "oid": "MIKROTIK-MIB::mtxrInterfaceStatsTxCollision",
}, # },
# Late collisions → almost always duplex mismatch / bad autoneg # # Late collisions → almost always duplex mismatch / bad autoneg
{ # {
"name": "tx_late_collisions", # "name": "tx_late_collisions",
"oid": "MIKROTIK-MIB::mtxrInterfaceStatsTxLateCollision", # "oid": "MIKROTIK-MIB::mtxrInterfaceStatsTxLateCollision",
}, # },
# Aggregate collision counter (context) # # Aggregate collision counter (context)
{ # {
"name": "tx_total_collisions", # "name": "tx_total_collisions",
"oid": "MIKROTIK-MIB::mtxrInterfaceStatsTxTotalCollision", # "oid": "MIKROTIK-MIB::mtxrInterfaceStatsTxTotalCollision",
}, # },
# Excessive collisions → persistent duplex problems # # Excessive collisions → persistent duplex problems
{ # {
"name": "tx_excessive_collisions", # "name": "tx_excessive_collisions",
"oid": "MIKROTIK-MIB::mtxrInterfaceStatsTxExcessiveCollision", # "oid": "MIKROTIK-MIB::mtxrInterfaceStatsTxExcessiveCollision",
}, # },
# ================== # # ==================
# Flow control (diagnostic) # # Flow control (diagnostic)
# ================== # # ==================
# Pause frames received (peer throttling you) # # Pause frames received (peer throttling you)
{ # {
"name": "rx_pause", # "name": "rx_pause",
"oid": "MIKROTIK-MIB::mtxrInterfaceStatsRxPause", # "oid": "MIKROTIK-MIB::mtxrInterfaceStatsRxPause",
}, # },
# Pause frames sent (you throttling the peer) # # Pause frames sent (you throttling the peer)
{ # {
"name": "tx_pause", # "name": "tx_pause",
"oid": "MIKROTIK-MIB::mtxrInterfaceStatsTxPause", # "oid": "MIKROTIK-MIB::mtxrInterfaceStatsTxPause",
}, # },
# Pause frames actually honored # # Pause frames actually honored
{ # {
"name": "tx_pause_honored", # "name": "tx_pause_honored",
"oid": "MIKROTIK-MIB::mtxrInterfaceStatsTxPauseHonored", # "oid": "MIKROTIK-MIB::mtxrInterfaceStatsTxPauseHonored",
}, # },
# ========== # # ==========
# Stability # # Stability
# ========== # # ==========
# Link-down events (loose cables, bad SFPs, PoE power drops, reboots) # # Link-down events (loose cables, bad SFPs, PoE power drops, reboots)
{ # {
"name": "link_downs", # "name": "link_downs",
"oid": "MIKROTIK-MIB::mtxrInterfaceStatsLinkDowns", # "oid": "MIKROTIK-MIB::mtxrInterfaceStatsLinkDowns",
}, # },
], # ],
}, # },
# PoE # # PoE
{ # {
"name": "poe", # "name": "poe",
"oid": "MIKROTIK-MIB::mtxrPOETable", # "oid": "MIKROTIK-MIB::mtxrPOETable",
"field": [ # "field": [
{ # {
"name": "ifName", # "name": "ifName",
"oid": "IF-MIB::ifName", # "oid": "IF-MIB::ifName",
"is_tag": True, # "is_tag": True,
}, # },
{ # {
"name": "ifAlias", # "name": "ifAlias",
"oid": "IF-MIB::ifAlias", # "oid": "IF-MIB::ifAlias",
"is_tag": True, # "is_tag": True,
}, # },
{ # {
"name": "ifindex", # "name": "ifindex",
"oid": "MIKROTIK-MIB::mtxrPOEInterfaceIndex", # "oid": "MIKROTIK-MIB::mtxrPOEInterfaceIndex",
"is_tag": True, # "is_tag": True,
}, # },
{ # {
"name": "status", # "name": "status",
"oid": "MIKROTIK-MIB::mtxrPOEStatus", # "oid": "MIKROTIK-MIB::mtxrPOEStatus",
}, # },
{ # {
"name": "voltage", # "name": "voltage",
"oid": "MIKROTIK-MIB::mtxrPOEVoltage", # "oid": "MIKROTIK-MIB::mtxrPOEVoltage",
}, # },
{ # {
"name": "current", # "name": "current",
"oid": "MIKROTIK-MIB::mtxrPOECurrent", # "oid": "MIKROTIK-MIB::mtxrPOECurrent",
}, # },
{ # {
"name": "power", # "name": "power",
"oid": "MIKROTIK-MIB::mtxrPOEPower", # "oid": "MIKROTIK-MIB::mtxrPOEPower",
}, # },
], # ],
}, # },
], # ],
}) # })
}, # },
}, # },
}, # },
}, # },
} # }

View file

@ -11,24 +11,22 @@ defaults = {
}, },
'smartctl': {}, 'smartctl': {},
'telegraf': { 'telegraf': {
'config': {
'inputs': { 'inputs': {
'exec': { 'exec': {
h({ 'smartctl_power_mode': {
'commands': [ 'commands': [
f'sudo /usr/local/share/telegraf/smartctl_power_mode', f'sudo /usr/local/share/telegraf/smartctl_power_mode',
], ],
'data_format': 'influx', 'data_format': 'influx',
'interval': '20s', 'interval': '20s',
}), },
h({ 'smartctl_errors': {
'commands': [ 'commands': [
f'sudo /usr/local/share/telegraf/smartctl_errors', f'sudo /usr/local/share/telegraf/smartctl_errors',
], ],
'data_format': 'influx', 'data_format': 'influx',
'interval': '6h', 'interval': '6h',
}) }
},
}, },
}, },
}, },

View file

@ -15,7 +15,7 @@ defaults = {
@metadata_reactor.provides( @metadata_reactor.provides(
'telegraf/config/inputs/exec', 'telegraf/inputs/exec',
) )
def telegraf(metadata): def telegraf(metadata):
return { return {
@ -23,11 +23,11 @@ def telegraf(metadata):
'config': { 'config': {
'inputs': { 'inputs': {
'exec': { 'exec': {
repo.libs.hashable.hashable({ 'tasmota_charge': {
'commands': ["/usr/local/share/telegraf/tasmota_charge"], 'commands': ["/usr/local/share/telegraf/tasmota_charge"],
'name_override': "tasmota_charge", 'name_override': "tasmota_charge",
'data_format': "influx", 'data_format': "influx",
}), },
}, },
}, },
}, },

View file

@ -1,19 +1,46 @@
import tomlkit import tomlkit
import json
from bundlewrap.metadata import MetadataJSONEncoder
def inner_dict_to_list(dict_of_dicts):
"""
Example:
{
'cpu': {
'default': {'something': True},
'another': {'something': False},
},
}
becomes
{
'cpu': [
{'something': True},
{'something': False},
],
}
"""
return {
key: [value for _, value in sorted(dicts.items())]
for key, dicts in sorted(dict_of_dicts.items())
}
files = { files = {
'/etc/telegraf/telegraf.conf': { "/etc/telegraf/telegraf.conf": {
'content': tomlkit.dumps( 'owner': 'telegraf',
json.loads(json.dumps( 'group': 'telegraf',
node.metadata.get('telegraf/config'), 'mode': '0440',
cls=MetadataJSONEncoder, 'needs': [
)), "pkg_apt:telegraf",
sort_keys=True,
),
'triggers': [
'svc_systemd:telegraf.service:restart',
], ],
'content': tomlkit.dumps({
'agent': node.metadata.get('telegraf/agent'),
'inputs': inner_dict_to_list(node.metadata.get('telegraf/inputs')),
'processors': inner_dict_to_list(node.metadata.get('telegraf/processors')),
'outputs': inner_dict_to_list(node.metadata.get('telegraf/outputs')),
}),
'triggers': {
'svc_systemd:telegraf.service:restart',
},
}, },
'/usr/local/share/telegraf/procio': { '/usr/local/share/telegraf/procio': {
'content_type': 'download', 'content_type': 'download',
@ -27,9 +54,26 @@ files = {
}, },
} }
svc_systemd['telegraf.service'] = { actions = {
'telegraf-test-config': {
'command': "sudo -u telegraf bash -c 'telegraf config check --config /etc/telegraf/telegraf.conf --strict-env-handling'",
'triggered': True,
'needs': [ 'needs': [
'bundle:sudo',
'file:/etc/telegraf/telegraf.conf', 'file:/etc/telegraf/telegraf.conf',
'pkg_apt:telegraf', 'pkg_apt:telegraf',
], ],
},
}
svc_systemd = {
'telegraf.service': {
'needs': ['pkg_apt:telegraf'],
'preceded_by': {
'action:telegraf-test-config',
},
'needs': {
'action:telegraf-test-config',
},
},
} }

View file

@ -23,10 +23,9 @@ defaults = {
}, },
}, },
'telegraf': { 'telegraf': {
'config': {
'agent': { 'agent': {
'hostname': node.name, 'hostname': node.name,
'collection_jitter': '0s', 'collection_jitter': '15s',
'flush_interval': '15s', 'flush_interval': '15s',
'flush_jitter': '0s', 'flush_jitter': '0s',
'interval': '1m', 'interval': '1m',
@ -37,13 +36,16 @@ defaults = {
'skip_processors_after_aggregators': True, 'skip_processors_after_aggregators': True,
}, },
'inputs': { 'inputs': {
'cpu': {h({ 'cpu': {
'default': {
'collect_cpu_time': False, 'collect_cpu_time': False,
'percpu': True, 'percpu': True,
'report_active': False, 'report_active': False,
'totalcpu': True, 'totalcpu': True,
})}, },
'disk': {h({ },
'disk': {
'default': {
'ignore_fs': [ 'ignore_fs': [
'tmpfs', 'tmpfs',
'devtmpfs', 'devtmpfs',
@ -53,24 +55,41 @@ defaults = {
'aufs', 'aufs',
'squashfs', 'squashfs',
], ],
})}, }
'procstat': {h({ },
'procstat': {
'default': {
'interval': '60s', 'interval': '60s',
'pattern': '.', 'pattern': '.',
'fieldinclude': [ 'fieldinclude': [
'cpu_usage', 'cpu_usage',
'memory_rss', 'memory_rss',
], ],
})}, },
'diskio': {h({ },
'diskio': {
'default': {
'device_tags': ["ID_PART_ENTRY_NUMBER"], 'device_tags': ["ID_PART_ENTRY_NUMBER"],
})}, }
'kernel': {h({})}, },
'mem': {h({})}, 'kernel': {
'processes': {h({})}, 'default': {},
'swap': {h({})}, },
'system': {h({})}, 'mem': {
'net': {h({})}, 'default': {},
},
'processes': {
'default': {},
},
'swap': {
'default': {},
},
'system': {
'default': {},
},
'net': {
'default': {},
},
'exec': { 'exec': {
# h({ # h({
# 'commands': [ # 'commands': [
@ -79,16 +98,17 @@ defaults = {
# 'data_format': 'influx', # 'data_format': 'influx',
# 'interval': '20s', # 'interval': '20s',
# }), # }),
h({ 'pressure_stall': {
'commands': [ 'commands': [
f'/usr/local/share/telegraf/pressure_stall', f'/usr/local/share/telegraf/pressure_stall',
], ],
'data_format': 'influx', 'data_format': 'influx',
'interval': '10s', 'interval': '10s',
}),
}, },
}, },
}, },
'processors': {},
'outputs': {},
}, },
'grafana_rows': { 'grafana_rows': {
'cpu', 'cpu',
@ -106,21 +126,21 @@ defaults = {
@metadata_reactor.provides( @metadata_reactor.provides(
'telegraf/config/outputs/influxdb_v2', 'telegraf/outputs/influxdb_v2/default',
) )
def influxdb(metadata): def influxdb(metadata):
influxdb_metadata = repo.get_node(metadata.get('telegraf/influxdb_node')).metadata.get('influxdb') influxdb_metadata = repo.get_node(metadata.get('telegraf/influxdb_node')).metadata.get('influxdb')
return { return {
'telegraf': { 'telegraf': {
'config': {
'outputs': { 'outputs': {
'influxdb_v2': [{ 'influxdb_v2': {
'default': {
'urls': [f"http://{influxdb_metadata['hostname']}:{influxdb_metadata['port']}"], 'urls': [f"http://{influxdb_metadata['hostname']}:{influxdb_metadata['port']}"],
'token': str(influxdb_metadata['writeonly_token']), 'token': str(influxdb_metadata['writeonly_token']),
'organization': influxdb_metadata['org'], 'organization': influxdb_metadata['org'],
'bucket': influxdb_metadata['bucket'], 'bucket': influxdb_metadata['bucket'],
}] },
}, },
}, },
}, },

View file

@ -59,9 +59,9 @@ defaults = {
}, },
}, },
'telegraf': { 'telegraf': {
'config': {
'inputs': { 'inputs': {
'zfs': [{}], 'zfs': {
'default': {},
}, },
}, },
}, },