Deploy `vector` config for `consul`.

This commit is contained in:
Kazuhiro MUSASHI 2023-03-04 15:21:56 +09:00
parent 75755b99f2
commit 401423d0da
3 changed files with 98 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/consul.toml
ExecReload=/bin/kill -HUP $MAINPID
Restart=always
StandardOutput=journal
StandardError=journal
SyslogIdentifier=vector
[Install]
WantedBy=multi-user.target

View File

@ -0,0 +1,62 @@
data_dir = "/var/lib/vector/"
[sources.consul]
type = "file"
include = [ "/var/log/consul/consul-*.log" ]
ignore_older_secs = 600
read_from = "beginning"
[transforms.consul_transform]
type = "remap"
inputs = ["consul"]
source = '''
dt, err = parse_regex(.message, r'^(?P<dt>\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}\+\d{4}) ')
. = merge(., dt)
.timestamp = .dt
del(.dt)
.message = replace!(.message, r'^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}\+\d{4} ', "")
.hostname = .host
del(.host)
lv, err = parse_regex(.message, r'\[(?P<level>[^\]]+)\]')
. = merge(., lv)
.message = replace(.message, r'\[(?P<level>[^\]]+)\] ', "")
.level = downcase!(.level)
'''
[sinks.consul_output]
type = "file"
inputs = [ "consul_transform" ]
compression = "none"
path = "/tmp/consul-%Y-%m-%d.log"
[sinks.consul_output.encoding]
codec = "json"
[sinks.consul_output.buffer]
max_size = 268435488
type = "disk"
[sinks.consul_loki]
type = "loki"
inputs = [ "consul_transform" ]
endpoint = "http://loki.service.consul:3100"
compression = "snappy"
[sinks.consul_loki.labels]
level = "{{ level }}"
hostname = "{{ hostname }}"
job = "consul"
filename = "{{ file }}"
[sinks.consul_loki.encoding]
codec = "json"
[sinks.consul_loki.buffer]
max_size = 268435488
type = "disk"

View File

@ -49,6 +49,26 @@ service 'vector-auth' do
action [:enable, :start]
end
# Deploy config for mointoring `/var/log/consul/consul-*.log`:
remote_file '/etc/vector/consul.toml' do
owner 'root'
group 'root'
mode '0644'
notifies :restart, 'service[vector-consul]'
end
remote_file '/etc/systemd/system/vector-consul.service' do
owner 'root'
group 'root'
mode '0644'
notifies :restart, 'service[vector-consul]'
end
service 'vector-consul' do
action [:enable, :start]
end
# Stop vector default service:
service 'vector' do