From f7eae0c857f480542d82cc68de8596968a46bc84 Mon Sep 17 00:00:00 2001 From: Kazuhiro MUSASHI Date: Tue, 7 Feb 2023 23:39:10 +0900 Subject: [PATCH] Deploy `systemd` config for `filestat_exporter`. --- .../system/vector-filestat_exporter.service | 16 ++++++ .../files/etc/vector/filestat_exporter.toml | 55 +++++++++++++++++++ .../filestat_exporter_setup.rb | 19 +++++++ 3 files changed, 90 insertions(+) create mode 100644 cookbooks/prometheus-exporters/files/etc/systemd/system/vector-filestat_exporter.service create mode 100644 cookbooks/prometheus-exporters/files/etc/vector/filestat_exporter.toml diff --git a/cookbooks/prometheus-exporters/files/etc/systemd/system/vector-filestat_exporter.service b/cookbooks/prometheus-exporters/files/etc/systemd/system/vector-filestat_exporter.service new file mode 100644 index 0000000..5cc135d --- /dev/null +++ b/cookbooks/prometheus-exporters/files/etc/systemd/system/vector-filestat_exporter.service @@ -0,0 +1,16 @@ +[Unit] +Description=Vector +Documentation=https://vector.dev +After=network-online.target +Requires=network-online.target + +[Service] +ExecStart=/usr/bin/vector --config /etc/vector/filestat_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-exporters/files/etc/vector/filestat_exporter.toml b/cookbooks/prometheus-exporters/files/etc/vector/filestat_exporter.toml new file mode 100644 index 0000000..42f47d8 --- /dev/null +++ b/cookbooks/prometheus-exporters/files/etc/vector/filestat_exporter.toml @@ -0,0 +1,55 @@ +data_dir = "/var/lib/vector/" + +[sources.filestat_exporter] + type = "file" + include = [ "/var/log/filestat_exporter.log" ] + ignore_older_secs = 600 + read_from = "beginning" + +[transforms.filestat_exporter_transform] + type = "remap" + inputs = ["filestat_exporter"] + source = ''' + . |= parse_syslog!(.message) + + . |= parse_key_value!(.message) + + del(.message) + del(.host) + + .message = .msg + del(.msg) + ''' + +[sinks.filestat_exporter_output] +type = "file" +inputs = [ "filestat_exporter_transform" ] +compression = "none" +path = "/tmp/filestat_exporter-%Y-%m-%d.log" + + [sinks.filestat_exporter_output.encoding] + codec = "json" + + [sinks.filestat_exporter_output.buffer] + max_size = 268435488 + type = "disk" + +[sinks.filestat_exporter_loki] +type = "loki" +inputs = [ "filestat_exporter_transform" ] +endpoint = "http://loki.service.consul:3100" +compression = "snappy" + + [sinks.filestat_exporter_loki.labels] + level = "{{ level }}" + hostname = "{{ hostname }}" + job = "filestat_exporter" + filename = "/var/log/filestat_exporter.log" + + [sinks.filestat_exporter_loki.encoding] + codec = "json" + + [sinks.filestat_exporter_loki.buffer] + max_size = 268435488 + type = "disk" + diff --git a/cookbooks/prometheus-exporters/filestat_exporter_setup.rb b/cookbooks/prometheus-exporters/filestat_exporter_setup.rb index 7f8bf1c..780dfaa 100644 --- a/cookbooks/prometheus-exporters/filestat_exporter_setup.rb +++ b/cookbooks/prometheus-exporters/filestat_exporter_setup.rb @@ -38,6 +38,25 @@ remote_file '/etc/logrotate.d/filestat_exporter' do mode '644' end +# Deploy `vector` config: +remote_file '/etc/vector/filestat_exporter.toml' do + owner 'root' + group 'root' + mode '0644' + + notifies :restart, 'service[vector-filestat_exporter]' +end + +remote_file '/etc/systemd/system/vector-filestat_exporter.service' do + owner 'root' + group 'root' + mode '0644' +end + +service 'vector-filestat_exporter' do + action [:enable, :start] +end + # Deploy `consul` config for `filestat_exporter`: remote_file '/etc/consul.d/service-filestat_exporter.json' do owner 'consul'