]> git.openstreetmap.org Git - chef.git/commitdiff
Run smokeping exporter on gateways
authorTom Hughes <tom@compton.nu>
Wed, 8 Mar 2023 18:33:24 +0000 (18:33 +0000)
committerTom Hughes <tom@compton.nu>
Wed, 8 Mar 2023 18:33:45 +0000 (18:33 +0000)
cookbooks/prometheus/recipes/smokeping.rb [new file with mode: 0644]
cookbooks/prometheus/templates/default/smokeping.yml.erb [new file with mode: 0644]
roles/gateway.rb

diff --git a/cookbooks/prometheus/recipes/smokeping.rb b/cookbooks/prometheus/recipes/smokeping.rb
new file mode 100644 (file)
index 0000000..975f8a5
--- /dev/null
@@ -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 (file)
index 0000000..46caf47
--- /dev/null
@@ -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
index b9007b86ece3163425243dcf5c324e6b4d810659..a78f04bcf849bd056ecf9a4ae09a863161133c4a 100644 (file)
@@ -14,5 +14,6 @@ default_attributes(
 )
 
 run_list(
-  "recipe[bind]"
+  "recipe[bind]",
+  "recipe[prometheus::smokeping]"
 )