|
108 | 108 | template "ohai.rb.erb"
|
109 | 109 | end
|
110 | 110 |
|
| 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 | + |
111 | 118 | package "pgtop"
|
112 | 119 | package "libdbd-pg-perl"
|
113 | 120 |
|
114 | 121 | clusters = node[:postgresql][:clusters] || []
|
115 | 122 |
|
116 | 123 | 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 |
118 | 140 |
|
119 |
| - munin_plugin "postgres_bgwriter_#{suffix}" do |
| 141 | + munin_suffix = name.tr("/", ":") |
| 142 | + |
| 143 | + munin_plugin "postgres_bgwriter_#{munin_suffix}" do |
120 | 144 | target "postgres_bgwriter"
|
121 | 145 | conf "munin.erb"
|
122 | 146 | conf_variables :port => details[:port]
|
123 | 147 | end
|
124 | 148 |
|
125 |
| - munin_plugin "postgres_checkpoints_#{suffix}" do |
| 149 | + munin_plugin "postgres_checkpoints_#{munin_suffix}" do |
126 | 150 | target "postgres_checkpoints"
|
127 | 151 | conf "munin.erb"
|
128 | 152 | conf_variables :port => details[:port]
|
129 | 153 | end
|
130 | 154 |
|
131 |
| - munin_plugin "postgres_connections_db_#{suffix}" do |
| 155 | + munin_plugin "postgres_connections_db_#{munin_suffix}" do |
132 | 156 | target "postgres_connections_db"
|
133 | 157 | conf "munin.erb"
|
134 | 158 | conf_variables :port => details[:port]
|
135 | 159 | end
|
136 | 160 |
|
137 |
| - munin_plugin "postgres_users_#{suffix}" do |
| 161 | + munin_plugin "postgres_users_#{munin_suffix}" do |
138 | 162 | target "postgres_users"
|
139 | 163 | conf "munin.erb"
|
140 | 164 | conf_variables :port => details[:port]
|
141 | 165 | end
|
142 | 166 |
|
143 |
| - munin_plugin "postgres_xlog_#{suffix}" do |
| 167 | + munin_plugin "postgres_xlog_#{munin_suffix}" do |
144 | 168 | target "postgres_xlog"
|
145 | 169 | conf "munin.erb"
|
146 | 170 | conf_variables :port => details[:port]
|
147 | 171 | end
|
148 | 172 |
|
149 | 173 | next unless File.exist?("/var/lib/postgresql/#{details[:version]}/main/recovery.conf")
|
150 | 174 |
|
151 |
| - munin_plugin "postgres_replication_#{suffix}" do |
| 175 | + munin_plugin "postgres_replication_#{munin_suffix}" do |
152 | 176 | target "postgres_replication"
|
153 | 177 | conf "munin.erb"
|
154 | 178 | conf_variables :port => details[:port]
|
155 | 179 | end
|
156 | 180 | end
|
157 | 181 |
|
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] |
167 | 184 | end
|
168 | 185 |
|
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 |
183 | 188 | end
|
0 commit comments