diff --git a/cookbooks/docker/attributes.rb b/cookbooks/docker/attributes.rb new file mode 100644 index 0000000..094fc19 --- /dev/null +++ b/cookbooks/docker/attributes.rb @@ -0,0 +1,8 @@ +# ------------------------------------------- +# Specifying the default settings: +# ------------------------------------------- +node.reverse_merge!({ + 'docker' => { + 'loki' => '192.168.10.101' + } +}) diff --git a/cookbooks/docker/default.rb b/cookbooks/docker/default.rb index a1a8dc3..2f8afef 100644 --- a/cookbooks/docker/default.rb +++ b/cookbooks/docker/default.rb @@ -1,3 +1,5 @@ +include_recipe './attributes.rb' + include_recipe './install.rb' include_recipe './setup.rb' diff --git a/cookbooks/docker/files/etc/systemd/system/vector-docker.service b/cookbooks/docker/files/etc/systemd/system/vector-docker.service new file mode 100644 index 0000000..6994e1d --- /dev/null +++ b/cookbooks/docker/files/etc/systemd/system/vector-docker.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/docker.toml +ExecReload=/bin/kill -HUP $MAINPID +Restart=always +StandardOutput=syslog +StandardError=syslog +SyslogIdentifier=vector + +[Install] +WantedBy=multi-user.target diff --git a/cookbooks/docker/setup.rb b/cookbooks/docker/setup.rb index 93fbd24..7745fb8 100644 --- a/cookbooks/docker/setup.rb +++ b/cookbooks/docker/setup.rb @@ -37,3 +37,32 @@ remote_file '/etc/cron.d/docker-housekeep' do group 'root' mode '644' end + +# Deploy config file for `vector`: +template '/etc/vector/docker.toml' do + owner 'root' + group 'root' + mode '644' + + variables(LOKI: node['docker']['loki'], + HOSTNAME: node[:hostname] + ) + + source 'templates/etc/vector/docker.toml.erb' + + notifies :restart, 'service[vector-docker]' +end + +# Deploy `systemd` configuration for `prometheus`: +remote_file '/etc/systemd/system/vector-docker.service' do + owner 'root' + group 'root' + mode '644' + + notifies :restart, 'service[vector-docker]' +end + +# Service setting: +service 'vector-docker' do + action [ :enable, :restart ] +end diff --git a/cookbooks/docker/templates/etc/vector/docker.toml.erb b/cookbooks/docker/templates/etc/vector/docker.toml.erb new file mode 100644 index 0000000..5b7d60a --- /dev/null +++ b/cookbooks/docker/templates/etc/vector/docker.toml.erb @@ -0,0 +1,22 @@ +data_dir = "/var/lib/vector" + +[sources.docker] + type = "docker" + +[transforms.docker-transform] + type = "remove_fields" + inputs = ["docker"] + fields = ["container_created_at", "container_id", "container_name"] + +[sinks.docker-logs] + type = "loki" + inputs = ["docker-transform"] + endpoint = "http://<%= @LOKI %>:3100" + healthcheck = true + remove_timestamp = true + + encoding.codec = "text" + + labels.level = "info" + labels.job = "docker" + labels.hostname = "<%= @HOSTNAME %>" diff --git a/cookbooks/vector/default.rb b/cookbooks/vector/default.rb index b7d07c1..f0eb864 100644 --- a/cookbooks/vector/default.rb +++ b/cookbooks/vector/default.rb @@ -3,4 +3,5 @@ include_recipe './attributes.rb' # Install loki here: include_recipe './install.rb' +include_recipe './setup.rb' diff --git a/cookbooks/vector/setup.rb b/cookbooks/vector/setup.rb new file mode 100644 index 0000000..ea2e32f --- /dev/null +++ b/cookbooks/vector/setup.rb @@ -0,0 +1,8 @@ +# Create `/var/log/vector`: +%w( /var/log/vector ).each do |d| + directory d do + owner 'root' + group 'root' + mode '0755' + end +end diff --git a/cookbooks/vector/syslog_setup.rb b/cookbooks/vector/syslog_setup.rb index 1da1eec..58c3185 100644 --- a/cookbooks/vector/syslog_setup.rb +++ b/cookbooks/vector/syslog_setup.rb @@ -1,12 +1,3 @@ -# Create `/var/log/vector`: -%w( /var/log/vector ).each do |d| - directory d do - owner 'root' - group 'root' - mode '0755' - end -end - # Deploy `vector` configuration for `syslog`: remote_file '/etc/vector/syslog.toml' do owner 'root'