From a201eea56083b0cf88ad4ff068a54565dc8cfeec Mon Sep 17 00:00:00 2001 From: Kazuhiro MUSASHI Date: Sat, 4 Mar 2023 15:09:05 +0900 Subject: [PATCH] Deploy `vector` config for `apt`. --- .../etc/systemd/system/vector-apt.service | 16 +++++++ cookbooks/vector/files/etc/vector/apt.toml | 48 +++++++++++++++++++ cookbooks/vector/setup.rb | 19 ++++++++ 3 files changed, 83 insertions(+) create mode 100644 cookbooks/vector/files/etc/systemd/system/vector-apt.service create mode 100644 cookbooks/vector/files/etc/vector/apt.toml diff --git a/cookbooks/vector/files/etc/systemd/system/vector-apt.service b/cookbooks/vector/files/etc/systemd/system/vector-apt.service new file mode 100644 index 0000000..e09c1de --- /dev/null +++ b/cookbooks/vector/files/etc/systemd/system/vector-apt.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/apt.toml +ExecReload=/bin/kill -HUP $MAINPID +Restart=always +StandardOutput=journal +StandardError=journal +SyslogIdentifier=vector + +[Install] +WantedBy=multi-user.target diff --git a/cookbooks/vector/files/etc/vector/apt.toml b/cookbooks/vector/files/etc/vector/apt.toml new file mode 100644 index 0000000..85a96a4 --- /dev/null +++ b/cookbooks/vector/files/etc/vector/apt.toml @@ -0,0 +1,48 @@ +data_dir = "/var/lib/vector/" + +[sources.apt] + type = "file" + include = [ "/var/log/apt/history.log" ] + ignore_older_secs = 600 + read_from = "beginning" + +[transforms.apt_transform] + type = "remap" + inputs = ["apt"] + source = ''' + .hostname = .host + del(.host) + ''' + +[sinks.apt_output] +type = "file" +inputs = [ "apt_transform" ] +compression = "none" +path = "/tmp/apt-%Y-%m-%d.log" + + [sinks.apt_output.encoding] + codec = "json" + + [sinks.apt_output.buffer] + max_size = 268435488 + type = "disk" + +[sinks.apt_loki] +type = "loki" +inputs = [ "apt_transform" ] +endpoint = "http://loki.service.consul:3100" +compression = "snappy" + + [sinks.apt_loki.labels] + level = "notice" + hostname = "{{ hostname }}" + job = "apt" + filename = "{{ file }}" + + [sinks.apt_loki.encoding] + codec = "json" + + [sinks.apt_loki.buffer] + max_size = 268435488 + type = "disk" + diff --git a/cookbooks/vector/setup.rb b/cookbooks/vector/setup.rb index af29c6b..54c4baa 100644 --- a/cookbooks/vector/setup.rb +++ b/cookbooks/vector/setup.rb @@ -7,6 +7,25 @@ end end +# Deploy config for `apt`: +remote_file '/etc/vector/apt.toml' do + owner 'root' + group 'root' + mode '0644' +end + +remote_file '/etc/systemd/system/vector-apt.service' do + owner 'root' + group 'root' + mode '0644' + + notifies :restart, 'service[vector-apt]' +end + +service 'vector-apt' do + action [:enable, :start] +end + # Stop vector default service: service 'vector' do action :disable