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/setup.rb b/cookbooks/docker/setup.rb index 93fbd24..56aa5a8 100644 --- a/cookbooks/docker/setup.rb +++ b/cookbooks/docker/setup.rb @@ -37,3 +37,18 @@ 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 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 %>"