diff --git a/cookbooks/prometheus/files/etc/systemd/system/vector-snmp_exporter.service b/cookbooks/prometheus/files/etc/systemd/system/vector-snmp_exporter.service new file mode 100644 index 0000000..cb33a7d --- /dev/null +++ b/cookbooks/prometheus/files/etc/systemd/system/vector-snmp_exporter.service @@ -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 + diff --git a/cookbooks/prometheus/files/etc/vector/snmp_exporter.toml b/cookbooks/prometheus/files/etc/vector/snmp_exporter.toml new file mode 100644 index 0000000..35db8d1 --- /dev/null +++ b/cookbooks/prometheus/files/etc/vector/snmp_exporter.toml @@ -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" diff --git a/cookbooks/prometheus/snmp_exporter_setup.rb b/cookbooks/prometheus/snmp_exporter_setup.rb index 038a362..11bb23e 100644 --- a/cookbooks/prometheus/snmp_exporter_setup.rb +++ b/cookbooks/prometheus/snmp_exporter_setup.rb @@ -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'