2 # Cookbook:: prometheus
5 # Copyright:: 2020, OpenStreetMap Foundation
7 # Licensed under the Apache License, Version 2.0 (the "License");
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
11 # https://www.apache.org/licenses/LICENSE-2.0
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
20 include_recipe "networking"
27 if node.internal_ipaddress
28 node.default[:prometheus][:mode] = "internal"
29 node.default[:prometheus][:address] = node.internal_ipaddress
30 elsif node[:networking][:wireguard][:enabled]
31 node.default[:prometheus][:mode] = "wireguard"
32 node.default[:prometheus][:address] = node[:networking][:wireguard][:address]
34 search(:node, "roles:prometheus") do |server|
35 node.default[:networking][:wireguard][:peers] << {
36 :public_key => server[:networking][:wireguard][:public_key],
37 :allowed_ips => server[:networking][:wireguard][:address],
38 :endpoint => "#{server.name}:51820"
42 node.default[:prometheus][:mode] = "external"
43 node.default[:prometheus][:address] = node.external_ipaddress(:family => :inet)
46 directory "/opt/prometheus" do
51 cache_dir = Chef::Config[:file_cache_path]
53 remote_file "#{cache_dir}/prometheus-exporters.tar.zst" do
54 source "https://github.com/openstreetmap/prometheus-exporters/releases/latest/download/prometheus-exporters-#{node[:kernel][:machine]}-only.tar.zst"
62 archive_file "/opt/prometheus-exporters" do
63 path "#{cache_dir}/prometheus-exporters.tar.zst"
64 destination "/opt/prometheus-exporters"
67 subscribes :extract, "remote_file[#{cache_dir}/prometheus-exporters.tar.zst]", :immediately
70 directory "/etc/prometheus/collectors" do
77 directory "/etc/prometheus/exporters" do
84 directory "/var/lib/prometheus/node-exporter" do
91 template "/var/lib/prometheus/node-exporter/chef.prom" do
92 source "chef.prom.erb"
100 node[:hardware][:hwmon].each do |chip, details|
101 next unless details[:ignore]
103 sensors = details[:ignore].join("|")
106 :source_labels => "chip,sensor",
107 :regex => "#{chip};(#{sensors})",
112 prometheus_exporter "node" do
117 restrict_address_families %w[AF_UNIX AF_NETLINK]
118 system_call_filter ["@system-service", "@clock"]
120 --collector.textfile.directory=/var/lib/prometheus/node-exporter
121 --collector.interrupts
122 --collector.processes
123 --collector.rapl.enable-zone-label
127 metric_relabel metric_relabel
130 unless node[:prometheus][:junos].empty?
131 targets = node[:prometheus][:junos].collect { |_, details| details[:address] }.sort.join(",")
133 prometheus_exporter "junos" do
136 --ssh.user=prometheus
137 --ssh.keyfile=/var/lib/prometheus/junos-exporter/id_rsa
138 --ssh.targets=#{targets}
143 --power.enabled=false
146 register_target false
150 unless node[:prometheus][:snmp].empty?
151 prometheus_exporter "snmp" do
153 options "--config.file=/opt/prometheus-exporters/exporters/snmp/snmp.yml"
154 register_target false
158 if node[:prometheus][:files].empty?
159 prometheus_exporter "filestat" do
163 file "/etc/prometheus/filestat.yml" do
167 template "/etc/prometheus/filestat.yml" do
168 source "filestat.yml.erb"
174 prometheus_exporter "filestat" do
176 options "--config.file=/etc/prometheus/filestat.yml"
177 subscribes :restart, "template[/etc/prometheus/filestat.yml]"