From 20a03c97a1380a4f8531d44c7dfda386bd92ddb9 Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Thu, 22 Oct 2020 00:15:40 +0100 Subject: [PATCH] Configure fastly exporter for prometheus --- cookbooks/prometheus/recipes/server.rb | 8 ++++++++ cookbooks/prometheus/resources/exporter.rb | 10 +++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/cookbooks/prometheus/recipes/server.rb b/cookbooks/prometheus/recipes/server.rb index e10e9e4ce..6a1219ca0 100644 --- a/cookbooks/prometheus/recipes/server.rb +++ b/cookbooks/prometheus/recipes/server.rb @@ -22,6 +22,14 @@ include_recipe "apt" include_recipe "networking" passwords = data_bag_item("prometheus", "passwords") +tokens = data_bag_item("prometheus", "tokens") + +prometheus_exporter "fastly" do + port 8080 + listen_switch "endpoint" + listen_type "url" + environment "FASTLY_API_TOKEN" => tokens["fastly"] +end package "prometheus" diff --git a/cookbooks/prometheus/resources/exporter.rb b/cookbooks/prometheus/resources/exporter.rb index 22e364f9f..82c2957c0 100644 --- a/cookbooks/prometheus/resources/exporter.rb +++ b/cookbooks/prometheus/resources/exporter.rb @@ -22,6 +22,7 @@ default_action :create property :exporter, :kind_of => String, :name_property => true property :port, :kind_of => Integer, :required => [:create] property :listen_switch, :kind_of => String, :default => "web.listen-address" +property :listen_type, :kind_of => String, :default => "address" property :user, :kind_of => String, :default => "root" property :options, :kind_of => [String, Array] property :environment, :kind_of => Hash, :default => {} @@ -82,7 +83,14 @@ action_class do end def executable_options - "--#{new_resource.listen_switch}=#{listen_address} #{Array(new_resource.options).join(' ')}" + "--#{new_resource.listen_switch}=#{listen_argument} #{Array(new_resource.options).join(' ')}" + end + + def listen_argument + case new_resource.listen_type + when "address" then listen_address + when "url" then "http://#{listen_address}/metrics" + end end def listen_address -- 2.43.2