2 # Cookbook:: prometheus
5 # Copyright:: 2023, 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 "prometheus"
24 %w[ipv4 ipv6].each do |protocol|
25 json_file = "#{Chef::Config[:file_cache_path]}/#{protocol}.json"
27 remote_file json_file do
28 source "https://dns.openstreetmap.org/#{protocol}.json"
33 hosts[protocol] = if File.exist?(json_file)
34 JSON.parse(IO.read(json_file)).filter_map do |name, address|
35 name unless name.split(".").first == node[:hostname] ||
36 name.end_with?(".oob") ||
37 address.start_with?("10.")
44 template "/etc/prometheus/exporters/smokeping.yml" do
45 source "smokeping.yml.erb"
49 variables :ip4_hosts => hosts["ipv4"], :ip6_hosts => hosts["ipv6"]
52 prometheus_exporter "smokeping" do
54 environment "GOMAXPROCS" => "1"
55 options "--config.file=/etc/prometheus/exporters/smokeping.yml"
56 capability_bounding_set "CAP_NET_RAW"
57 ambient_capabilities "CAP_NET_RAW"
59 subscribes :restart, "template[/etc/prometheus/exporters/smokeping.yml]"