Deploy `vector` config for `apt`.

This commit is contained in:
Kazuhiro MUSASHI 2023-03-04 15:09:05 +09:00
parent e9a1480351
commit a201eea560
3 changed files with 83 additions and 0 deletions

View File

@ -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

View File

@ -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"

View File

@ -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