From 60ca9176d9a40297b506caa57bb6f6c40ed3433f Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Wed, 8 Mar 2023 18:33:24 +0000 Subject: [PATCH] Run smokeping exporter on gateways --- cookbooks/prometheus/recipes/smokeping.rb | 43 +++++++++++++++++++ .../templates/default/smokeping.yml.erb | 16 +++++++ roles/gateway.rb | 3 +- 3 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 cookbooks/prometheus/recipes/smokeping.rb create mode 100644 cookbooks/prometheus/templates/default/smokeping.yml.erb diff --git a/cookbooks/prometheus/recipes/smokeping.rb b/cookbooks/prometheus/recipes/smokeping.rb new file mode 100644 index 000000000..975f8a5c2 --- /dev/null +++ b/cookbooks/prometheus/recipes/smokeping.rb @@ -0,0 +1,43 @@ +# +# Cookbook:: prometheus +# Recipe:: smokeping +# +# Copyright:: 2023, OpenStreetMap Foundation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +include_recipe "prometheus" + +ip4_hosts = [] +ip6_hosts = [] + +search(:node, "networking:interfaces") do |host| + next if host.name == node.name + + ip4_hosts << host[:fqdn] unless host.interfaces(:role => :external, :family => :inet).empty? + ip6_hosts << host[:fqdn] unless host.interfaces(:role => :external, :family => :inet6).empty? +end + +template "/etc/prometheus/exporters/smokeping.yml" do + source "smokeping.yml.erb" + owner "root" + group "root" + mode "644" + variables :ip4_hosts => ip4_hosts, :ip6_hosts => ip6_hosts +end + +prometheus_exporter "smokeping" do + port 9374 + options "--config.file=/etc/prometheus/exporters/smokeping.yml" +end diff --git a/cookbooks/prometheus/templates/default/smokeping.yml.erb b/cookbooks/prometheus/templates/default/smokeping.yml.erb new file mode 100644 index 000000000..46caf47b9 --- /dev/null +++ b/cookbooks/prometheus/templates/default/smokeping.yml.erb @@ -0,0 +1,16 @@ +--- +target: +- hosts: +<% @ip4_hosts.each do |host| -%> + - <%= host %> +<% end -%> + interval: 5s + network: ip4 + size: 24 +- hosts: +<% @ip6_hosts.each do |host| -%> + - <%= host %> +<% end -%> + interval: 5s + network: ip6 + size: 24 diff --git a/roles/gateway.rb b/roles/gateway.rb index b9007b86e..a78f04bcf 100644 --- a/roles/gateway.rb +++ b/roles/gateway.rb @@ -14,5 +14,6 @@ default_attributes( ) run_list( - "recipe[bind]" + "recipe[bind]", + "recipe[prometheus::smokeping]" ) -- 2.39.5