Skip to content

Commit 749a519

Browse files
committed
Improve monitoring of primary database for api, tile and nominatim
1 parent 88f820a commit 749a519

File tree

5 files changed

+39
-30
lines changed

5 files changed

+39
-30
lines changed

cookbooks/db/attributes/default.rb

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
default[:db][:cluster] = "15/main"
22

33
default[:postgresql][:versions] |= ["15"]
4+
default[:postgresql][:monitor_database] = "openstreetmap"

cookbooks/nominatim/attributes/default.rb

+1
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,6 @@
3131
default[:nominatim][:redirects] = {}
3232

3333
default[:postgresql][:versions] |= [node[:nominatim][:dbcluster].split("/").first]
34+
default[:postgresql][:monitor_database] = "nominatim"
3435

3536
default[:accounts][:users][:nominatim][:status] = :role

cookbooks/postgresql/attributes/default.rb

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
default[:postgresql][:versions] = []
22
default[:postgresql][:clusters] = {}
3+
default[:postgresql][:monitor_database] = "postgres"
34
default[:postgresql][:settings][:defaults][:port] = "5432"
45
default[:postgresql][:settings][:defaults][:max_connections] = "100"
56
default[:postgresql][:settings][:defaults][:ssl] = "true"

cookbooks/postgresql/recipes/default.rb

+35-30
Original file line numberDiff line numberDiff line change
@@ -108,76 +108,81 @@
108108
template "ohai.rb.erb"
109109
end
110110

111+
template "/etc/prometheus/exporters/postgres_queries.yml" do
112+
source "postgres_queries.yml.erb"
113+
owner "root"
114+
group "root"
115+
mode "644"
116+
end
117+
111118
package "pgtop"
112119
package "libdbd-pg-perl"
113120

114121
clusters = node[:postgresql][:clusters] || []
115122

116123
clusters.each do |name, details|
117-
suffix = name.tr("/", ":")
124+
prometheus_suffix = name.tr("/", "-")
125+
prometheus_database = node[:postgresql][:monitor_database]
126+
127+
prometheus_exporter "postgres" do
128+
port 10000 + details[:port]
129+
service "postgres-#{prometheus_suffix}"
130+
labels "cluster" => name
131+
scrape_interval "1m"
132+
scrape_timeout "1m"
133+
user "postgres"
134+
options "--no-collector.process_idle --extend.query-path=/etc/prometheus/exporters/postgres_queries.yml"
135+
environment "DATA_SOURCE_NAME" => "postgres:///#{prometheus_database}?host=/run/postgresql&port=#{details[:port]}"
136+
restrict_address_families "AF_UNIX"
137+
remove_ipc false
138+
subscribes :restart, "template[/etc/prometheus/exporters/postgres_queries.yml]"
139+
end
118140

119-
munin_plugin "postgres_bgwriter_#{suffix}" do
141+
munin_suffix = name.tr("/", ":")
142+
143+
munin_plugin "postgres_bgwriter_#{munin_suffix}" do
120144
target "postgres_bgwriter"
121145
conf "munin.erb"
122146
conf_variables :port => details[:port]
123147
end
124148

125-
munin_plugin "postgres_checkpoints_#{suffix}" do
149+
munin_plugin "postgres_checkpoints_#{munin_suffix}" do
126150
target "postgres_checkpoints"
127151
conf "munin.erb"
128152
conf_variables :port => details[:port]
129153
end
130154

131-
munin_plugin "postgres_connections_db_#{suffix}" do
155+
munin_plugin "postgres_connections_db_#{munin_suffix}" do
132156
target "postgres_connections_db"
133157
conf "munin.erb"
134158
conf_variables :port => details[:port]
135159
end
136160

137-
munin_plugin "postgres_users_#{suffix}" do
161+
munin_plugin "postgres_users_#{munin_suffix}" do
138162
target "postgres_users"
139163
conf "munin.erb"
140164
conf_variables :port => details[:port]
141165
end
142166

143-
munin_plugin "postgres_xlog_#{suffix}" do
167+
munin_plugin "postgres_xlog_#{munin_suffix}" do
144168
target "postgres_xlog"
145169
conf "munin.erb"
146170
conf_variables :port => details[:port]
147171
end
148172

149173
next unless File.exist?("/var/lib/postgresql/#{details[:version]}/main/recovery.conf")
150174

151-
munin_plugin "postgres_replication_#{suffix}" do
175+
munin_plugin "postgres_replication_#{munin_suffix}" do
152176
target "postgres_replication"
153177
conf "munin.erb"
154178
conf_variables :port => details[:port]
155179
end
156180
end
157181

158-
uris = clusters.collect do |_, details|
159-
"postgres@:#{details[:port]}/postgres?host=/run/postgresql"
160-
end
161-
162-
template "/etc/prometheus/exporters/postgres_queries.yml" do
163-
source "postgres_queries.yml.erb"
164-
owner "root"
165-
group "root"
166-
mode "644"
182+
service "prometheus-postgres-exporter" do
183+
action [:stop, :disable]
167184
end
168185

169-
# lag / lag_seconds
170-
# process_idle missing state
171-
prometheus_exporter "postgres" do
172-
port 9187
173-
scrape_interval "1m"
174-
scrape_timeout "1m"
175-
user "postgres"
176-
options "--no-collector.process_idle --extend.query-path=/etc/prometheus/exporters/postgres_queries.yml"
177-
environment "DATA_SOURCE_URI" => uris.sort.uniq.first,
178-
"PG_EXPORTER_AUTO_DISCOVER_DATABASES" => "true",
179-
"PG_EXPORTER_EXCLUDE_DATABASES" => "postgres,template0,template1"
180-
restrict_address_families "AF_UNIX"
181-
remove_ipc false
182-
subscribes :restart, "template[/etc/prometheus/exporters/postgres_queries.yml]"
186+
systemd_service "prometheus-postgres-exporter" do
187+
action :delete
183188
end

cookbooks/tile/attributes/default.rb

+1
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@
1414
default[:tile][:styles] = {}
1515

1616
default[:postgresql][:versions] |= [node[:tile][:database][:cluster].split("/").first]
17+
default[:postgresql][:monitor_database] = "gis"
1718

1819
default[:accounts][:users][:tile][:status] = :role

0 commit comments

Comments
 (0)