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.
 
  21 include_recipe "networking"
 
  24 if node.internal_ipaddress
 
  25   node.default[:prometheus][:mode] = "internal"
 
  26   node.default[:prometheus][:address] = node.internal_ipaddress
 
  27 elsif node[:networking][:wireguard][:enabled]
 
  28   node.default[:prometheus][:mode] = "wireguard"
 
  29   node.default[:prometheus][:address] = node[:networking][:wireguard][:address]
 
  31   search(:node, "roles:prometheus") do |server|
 
  32     node.default[:networking][:wireguard][:peers] << {
 
  33       :public_key => server[:networking][:wireguard][:public_key],
 
  34       :allowed_ips => server[:networking][:wireguard][:address],
 
  35       :endpoint => "#{server.name}:51820"
 
  39   node.default[:prometheus][:mode] = "external"
 
  40   node.default[:prometheus][:address] = node.external_ipaddress(:family => :inet)
 
  43 directory "/opt/prometheus" do
 
  48 git "/opt/prometheus-exporters" do
 
  50   repository "https://github.com/openstreetmap/prometheus-exporters.git"
 
  57 directory "/etc/prometheus/collectors" do
 
  64 directory "/etc/prometheus/exporters" do
 
  71 directory "/var/lib/prometheus/node-exporter" do
 
  78 template "/var/lib/prometheus/node-exporter/chef.prom" do
 
  79   source "chef.prom.erb"
 
  87 node[:hardware][:hwmon].each do |chip, details|
 
  88   next unless details[:ignore]
 
  90   sensors = details[:ignore].join("|")
 
  93     :source_labels => "chip,sensor",
 
  94     :regex => "#{chip};(#{sensors})",
 
  99 prometheus_exporter "node" do
 
 104   restrict_address_families %w[AF_UNIX AF_NETLINK]
 
 105   system_call_filter ["@system-service", "@clock"]
 
 107     --collector.textfile.directory=/var/lib/prometheus/node-exporter
 
 108     --collector.interrupts
 
 109     --collector.processes
 
 110     --collector.rapl.enable-zone-label
 
 114   metric_relabel metric_relabel
 
 117 unless node[:prometheus][:junos].empty?
 
 118   targets = node[:prometheus][:junos].collect { |_, details| details[:address] }.sort.join(",")
 
 120   prometheus_exporter "junos" do
 
 123       --ssh.user=prometheus
 
 124       --ssh.keyfile=/var/lib/prometheus/junos-exporter/id_rsa
 
 125       --ssh.targets=#{targets}
 
 130       --power.enabled=false
 
 133     register_target false
 
 137 unless node[:prometheus][:snmp].empty?
 
 138   prometheus_exporter "snmp" do
 
 140     options "--config.file=/opt/prometheus-exporters/exporters/snmp/snmp.yml"
 
 141     register_target false
 
 145 if node[:prometheus][:files].empty?
 
 146   prometheus_exporter "filestat" do
 
 150   file "/etc/prometheus/filestat.yml" do
 
 154   template "/etc/prometheus/filestat.yml" do
 
 155     source "filestat.yml.erb"
 
 161   prometheus_exporter "filestat" do
 
 163     options "--config.file=/etc/prometheus/filestat.yml"
 
 164     subscribes :restart, "template[/etc/prometheus/filestat.yml]"