From 5e7a0c07b0b33abab23fc23e7e3789436d18f0e0 Mon Sep 17 00:00:00 2001 From: Greg Karekinian Date: Sun, 5 Jul 2026 18:16:18 +0200 Subject: [PATCH] Move web port to an attribute --- site-cookbooks/kosmos_prometheus/attributes/default.rb | 4 +++- site-cookbooks/kosmos_prometheus/recipes/server.rb | 6 ++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/site-cookbooks/kosmos_prometheus/attributes/default.rb b/site-cookbooks/kosmos_prometheus/attributes/default.rb index 3189a86..8bd2964 100644 --- a/site-cookbooks/kosmos_prometheus/attributes/default.rb +++ b/site-cookbooks/kosmos_prometheus/attributes/default.rb @@ -1,6 +1,8 @@ node.default["kosmos_prometheus"]["version"] = "3.13.0" node.default["kosmos_prometheus"]["checksum"] = "744d93324cc024d82089921737bd797474d7f1e5dbbfd1c6b387bad258538cb9" +node.default["kosmos_prometheus"]["web"]["port"] = "9090" + node.default["kosmos_prometheus"]["alertmanager"]["version"] = "0.33.0" node.default["kosmos_prometheus"]["alertmanager"]["checksum"] = "8ce11c42e8a6dfbbf93a59c0b193cb1329210b36d0c7ef3df7b745608675a1d1" @@ -21,7 +23,7 @@ node.default["kosmos_prometheus"]["alerting"] = { } node.default["kosmos_prometheus"]["jobs"] = { - "prometheus" => { "targets" => [{ "target" => "localhost:9090", "instance" => "localhost" }] }, + "prometheus" => { "targets" => [{ "target" => "localhost:#{node["kosmos_prometheus"]["web"]["port"]}", "instance" => "localhost" }] }, } node.default["kosmos_prometheus"]["rule_files"] = [] diff --git a/site-cookbooks/kosmos_prometheus/recipes/server.rb b/site-cookbooks/kosmos_prometheus/recipes/server.rb index 345bd94..22f6a73 100644 --- a/site-cookbooks/kosmos_prometheus/recipes/server.rb +++ b/site-cookbooks/kosmos_prometheus/recipes/server.rb @@ -10,6 +10,8 @@ checksum = node["kosmos_prometheus"]["checksum"] tarball = "#{Chef::Config[:file_cache_path]}/prometheus-#{version}.linux-amd64.tar.gz" binary_url = "https://github.com/prometheus/prometheus/releases/download/v#{version}/prometheus-#{version}.linux-amd64.tar.gz" +web_port = node["kosmos_prometheus"]["web"]["port"] + group "prometheus" user "prometheus" do @@ -110,7 +112,7 @@ systemd_unit "prometheus.service" do Type: "simple", User: "prometheus", Group: "prometheus", - ExecStart: "/usr/local/bin/prometheus --config.file=/etc/prometheus/prometheus.yml --storage.tsdb.path=/var/lib/prometheus --storage.tsdb.retention.time=15d --web.listen-address=:9090 --web.enable-lifecycle", + ExecStart: "/usr/local/bin/prometheus --config.file=/etc/prometheus/prometheus.yml --storage.tsdb.path=/var/lib/prometheus --storage.tsdb.retention.time=15d --web.listen-address=:#{web_port} --web.enable-lifecycle", ExecReload: "/bin/kill -HUP $MAINPID", Restart: "on-failure", RestartSec: "5", @@ -128,7 +130,7 @@ service "prometheus" do end firewall_rule "prometheus web" do - port 9090 + port web_port source "10.1.1.0/24" protocol :tcp command :allow