From 5a32a4bcec44eaf44a903931934c32e73c189d5f Mon Sep 17 00:00:00 2001 From: Kazuhiro MUSASHI Date: Sun, 25 Oct 2020 00:16:11 +0900 Subject: [PATCH] Deploy `promtail` config for `snmp_exporter`. --- cookbooks/prometheus/snmp_exporter_setup.rb | 11 +++++ .../templates/etc/promtail/snmp_exporter.yaml | 40 +++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 cookbooks/prometheus/templates/etc/promtail/snmp_exporter.yaml diff --git a/cookbooks/prometheus/snmp_exporter_setup.rb b/cookbooks/prometheus/snmp_exporter_setup.rb index 8b39c01..b35f865 100644 --- a/cookbooks/prometheus/snmp_exporter_setup.rb +++ b/cookbooks/prometheus/snmp_exporter_setup.rb @@ -25,3 +25,14 @@ end service 'supervisor' do action :nothing end + +# Deploy /etc/hosts file: +template '/etc/promtail/snmp_exporter.yaml' do + owner 'root' + group 'root' + mode '644' + + variables(HOSTNAME: node[:hostname], LOKIENDPOINT: node['promtail']['lokiendpoint']) + + notifies :restart, 'service[promtail-prometheus]' +end diff --git a/cookbooks/prometheus/templates/etc/promtail/snmp_exporter.yaml b/cookbooks/prometheus/templates/etc/promtail/snmp_exporter.yaml new file mode 100644 index 0000000..6009a02 --- /dev/null +++ b/cookbooks/prometheus/templates/etc/promtail/snmp_exporter.yaml @@ -0,0 +1,40 @@ +server: + disable: true + +positions: + filename: /var/opt/promtail/promtail_snmp_exporter_position.yaml + +clients: + - url: http://<%= @LOKIENDPOINT %>/loki/api/v1/push + +scrape_configs: + - job_name: snmp_exporter + static_configs: + - targets: + - localhost + labels: + job: snmp_exporter + hostname: <%= @HOSTNAME %> + __path__: /var/log/supervisor/snmp_exporter.log + + pipeline_stages: + - match: + selector: '{job="snmp_exporter"}' + stages: + - regex: + expression: '^level=(?P[^ ]+) ts=(?P\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z) (?P.+)$' + + - timestamp: + source: timestamp + format: 2006-01-02T15:04:05.000Z + location: Etc/GMT + + - template: + source: level + template: '{{ regexReplaceAllLiteral "warn" .Value "warning" }}' + + - labels: + level: + + - output: + source: message