Add `systemd` files for `snmp_exporter` and `vector-snmp_exporter`

This commit is contained in:
Kazuhiro MUSASHI 2023-02-05 22:00:56 +09:00
parent 3c27430e57
commit 2a78c5f1e6
3 changed files with 88 additions and 0 deletions

View File

@ -0,0 +1,17 @@
[Unit]
Description=Vector SNMP Exporter
Documentation=https://vector.dev
After=network-online.target
Requires=network-online.target
[Service]
ExecStart=/usr/bin/vector --config /etc/vector/snmp_exporter.toml
ExecReload=/bin/kill -HUP $MAINPID
Restart=always
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=vector
[Install]
WantedBy=multi-user.target

View File

@ -0,0 +1,54 @@
data_dir = "/var/lib/vector/"
[sources.snmp_exporter]
type = "file"
include = [ "/var/log/snmp_exporter.log" ]
ignore_older_secs = 600
read_from = "beginning"
[transforms.snmp_exporter_transform]
type = "remap"
inputs = ["snmp_exporter"]
source = '''
. |= parse_syslog!(.message)
. |= parse_key_value!(.message)
del(.message)
del(.host)
.message = .msg
del(.msg)
'''
[sinks.snmp_exporter_output]
type = "file"
inputs = [ "snmp_exporter_transform" ]
compression = "none"
path = "/tmp/snmp_exporter-%Y-%m-%d.log"
[sinks.snmp_exporter_output.encoding]
codec = "json"
[sinks.snmp_exporter_output.buffer]
max_size = 268435488
type = "disk"
[sinks.snmp_exporter_loki]
type = "loki"
inputs = [ "snmp_exporter_transform" ]
endpoint = "http://loki.service.consul:3100"
compression = "snappy"
[sinks.snmp_exporter_loki.labels]
level = "{{ level }}"
hostname = "{{ hostname }}"
job = "snmp_exporter"
filename = "/var/log/snmp_exporter.log"
[sinks.snmp_exporter_loki.encoding]
codec = "json"
[sinks.snmp_exporter_loki.buffer]
max_size = 268435488
type = "disk"

View File

@ -34,6 +34,23 @@ remote_file '/etc/logrotate.d/snmp_exporter' do
mode '644'
end
# Deploy `vector` config for `snmp_exporter`:
remote_file '/etc/vector/snmp_exporter.toml' do
owner 'root'
group 'root'
mode '644'
end
remote_file '/etc/systemd/system/vector-snmp_exporter.service' do
owner 'root'
group 'root'
mode '0644'
end
service 'vector-snmp_exporter' do
action [:enable, :start]
end
# Deploy `consul` config:
remote_file '/etc/consul.d/service-snmp_exporter.json' do
owner 'consul'