Skip to content
Snippets Groups Projects
Commit ef3c4d60 authored by Marin Jankovski's avatar Marin Jankovski
Browse files

Merge branch 'database-monitor' into 'master'

Add Postgres exporter queries configuration file

See merge request !1545
parents ff685868 580dfe97
No related branches found
No related tags found
2 merge requests!1637Merge 9.3 RC2,!1545Add Postgres exporter queries configuration file
Loading
Loading
@@ -1330,7 +1330,7 @@ external_url 'GENERATED_EXTERNAL_URL'
################################################################################
 
# redis_exporter['enable'] = true
# redis_exporter['log_directory'] = "/var/log/gitlab/redis-exporter"
# redis_exporter['log_directory'] = '/var/log/gitlab/redis-exporter'
# redis_exporter['flags'] = {
# 'redis.addr' => "unix://#{node['gitlab']['gitlab-rails']['redis_socket']}",
# }
Loading
Loading
@@ -1344,7 +1344,8 @@ external_url 'GENERATED_EXTERNAL_URL'
################################################################################
 
# postgres_exporter['enable'] = true
# postgres_exporter['log_directory'] = "/var/log/gitlab/postgres-exporter"
# postgres_exporter['home'] = '/var/opt/gitlab/postgres-exporter'
# postgres_exporter['log_directory'] = '/var/log/gitlab/postgres-exporter'
# postgres_exporter['flags'] = {}
# postgres_exporter['listen_address'] = 'localhost:9187'
 
Loading
Loading
Loading
Loading
@@ -917,6 +917,7 @@ default['gitlab']['redis-exporter']['listen_address'] = 'localhost:9121'
# Postgres exporter
###
default['gitlab']['postgres-exporter']['enable'] = true
default['gitlab']['postgres-exporter']['home'] = '/var/opt/gitlab/postgres-exporter'
default['gitlab']['postgres-exporter']['log_directory'] = "/var/log/gitlab/postgres-exporter"
default['gitlab']['postgres-exporter']['listen_address'] = 'localhost:9187'
default['gitlab']['postgres-exporter']['env'] = {
Loading
Loading
Loading
Loading
@@ -108,9 +108,11 @@ module Prometheus
default_config = Gitlab['node']['gitlab']['postgres-exporter'].to_hash
user_config = Gitlab['postgres_exporter']
 
home_directory = user_config['home'] || default_config['home']
listen_address = user_config['listen_address'] || default_config['listen_address']
default_config['flags'] = {
'web.listen-address' => listen_address,
'extend.query-path' => File.join(home_directory, 'queries.yaml'),
}
 
default_config['flags'].merge!(user_config['flags']) if user_config.key?('flags')
Loading
Loading
Loading
Loading
@@ -19,6 +19,7 @@ account_helper = AccountHelper.new(node)
postgresql_user = account_helper.postgresql_user
postgres_exporter_log_dir = node['gitlab']['postgres-exporter']['log_directory']
postgres_exporter_static_etc_dir = "/opt/gitlab/etc/postgres-exporter"
postgres_exporter_dir = node['gitlab']['postgres-exporter']['home']
 
directory postgres_exporter_log_dir do
owner postgresql_user
Loading
Loading
@@ -26,6 +27,12 @@ directory postgres_exporter_log_dir do
recursive true
end
 
directory postgres_exporter_dir do
owner postgresql_user
mode '0700'
recursive true
end
env_dir File.join(postgres_exporter_static_etc_dir, 'env') do
variables node['gitlab']['postgres-exporter']['env']
restarts ["service[postgres-exporter]"]
Loading
Loading
@@ -40,6 +47,12 @@ runit_service 'postgres-exporter' do
log_options node['gitlab']['logging'].to_hash.merge(node['gitlab']['registry'].to_hash)
end
 
template File.join(postgres_exporter_dir, 'queries.yaml') do
source 'postgres-queries.yaml'
owner postgresql_user
mode '0644'
end
if node['gitlab']['bootstrap']['enable']
execute "/opt/gitlab/bin/gitlab-ctl start postgres-exporter" do
retries 20
Loading
Loading
pg_replication:
query: "SELECT EXTRACT(EPOCH FROM (now() - pg_last_xact_replay_timestamp()))::INT as lag"
metrics:
- lag:
usage: "GAUGE"
description: "Replication lag behind master in seconds"
pg_postmaster:
query: "SELECT pg_postmaster_start_time as start_time_seconds from pg_postmaster_start_time()"
metrics:
- start_time_seconds:
usage: "GAUGE"
description: "Time at which postmaster started"
pg_settings_shared_buffers:
query: "SELECT 8192*setting::bigint as bytes from pg_settings where name = 'shared_buffers'"
metrics:
- bytes:
usage: "GAUGE"
description: "Size of shared_buffers"
pg_settings_checkpoint:
query: "select (select setting::int from pg_settings where name = 'checkpoint_segments') as segments, (select setting::int from pg_settings where name = 'checkpoint_timeout') as timeout_seconds, (select setting::float from pg_settings where name = 'checkpoint_completion_target') as completion_target"
metrics:
- segments:
usage: "GAUGE"
description: "Number of checkpoint segments"
- timeout_seconds:
usage: "GAUGE"
description: "Checkpoint timeout in seconds"
- completion_target:
usage: "GAUGE"
description: "Checkpoint completion target, ranging from 0 to 1"
pg_stat_user_tables:
query: "SELECT schemaname, relname, seq_scan, seq_tup_read, idx_scan, idx_tup_fetch, n_tup_ins, n_tup_upd, n_tup_del, n_tup_hot_upd, n_live_tup, n_dead_tup, n_mod_since_analyze, last_vacuum, last_autovacuum, last_analyze, last_autoanalyze, vacuum_count, autovacuum_count, analyze_count, autoanalyze_count FROM pg_stat_user_tables"
metrics:
- schemaname:
usage: "LABEL"
description: "Name of the schema that this table is in"
- relname:
usage: "LABEL"
description: "Name of this table"
- seq_scan:
usage: "COUNTER"
description: "Number of sequential scans initiated on this table"
- seq_tup_read:
usage: "COUNTER"
description: "Number of live rows fetched by sequential scans"
- idx_scan:
usage: "COUNTER"
description: "Number of index scans initiated on this table"
- idx_tup_fetch:
usage: "COUNTER"
description: "Number of live rows fetched by index scans"
- n_tup_ins:
usage: "COUNTER"
description: "Number of rows inserted"
- n_tup_upd:
usage: "COUNTER"
description: "Number of rows updated"
- n_tup_del:
usage: "COUNTER"
description: "Number of rows deleted"
- n_tup_hot_upd:
usage: "COUNTER"
description: "Number of rows HOT updated (i.e., with no separate index update required)"
- n_live_tup:
usage: "GAUGE"
description: "Estimated number of live rows"
- n_dead_tup:
usage: "GAUGE"
description: "Estimated number of dead rows"
- n_mod_since_analyze:
usage: "GAUGE"
description: "Estimated number of rows changed since last analyze"
- last_vacuum:
usage: "GAUGE"
description: "Last time at which this table was manually vacuumed (not counting VACUUM FULL)"
- last_autovacuum:
usage: "GAUGE"
description: "Last time at which this table was vacuumed by the autovacuum daemon"
- last_analyze:
usage: "GAUGE"
description: "Last time at which this table was manually analyzed"
- last_autoanalyze:
usage: "GAUGE"
description: "Last time at which this table was analyzed by the autovacuum daemon"
- vacuum_count:
usage: "COUNTER"
description: "Number of times this table has been manually vacuumed (not counting VACUUM FULL)"
- autovacuum_count:
usage: "COUNTER"
description: "Number of times this table has been vacuumed by the autovacuum daemon"
- analyze_count:
usage: "COUNTER"
description: "Number of times this table has been manually analyzed"
- autoanalyze_count:
usage: "COUNTER"
description: "Number of times this table has been analyzed by the autovacuum daemon"
pg_stat_statements:
query: |
SELECT
pg_authid.rolname as user,
pg_database.datname as database,
pg_stat_statements.queryid,
left(pg_stat_statements.query,250) as query,
pg_stat_statements.calls,
pg_stat_statements.total_time as time_milliseconds,
pg_stat_statements.rows,
pg_stat_statements.shared_blks_hit,
pg_stat_statements.shared_blks_read,
pg_stat_statements.shared_blks_dirtied,
pg_stat_statements.shared_blks_written,
pg_stat_statements.temp_blks_read,
pg_stat_statements.temp_blks_written
FROM pg_stat_statements
JOIN pg_authid
ON pg_authid.oid = pg_stat_statements.userid
JOIN pg_database
ON pg_database.oid = pg_stat_statements.dbid
metrics:
- user:
usage: "LABEL"
description: "The user who executed the statement"
- dbid:
usage: "LABEL"
description: "The database in which the statement was executed"
- queryid:
usage: "LABEL"
description: "Internal hash code, computed from the statement's parse tree"
- query:
usage: "LABEL"
description: "Text of a representative statement (first 250 characters)"
- calls:
usage: "COUNTER"
description: "Number of times executed"
- time_milliseconds:
usage: "COUNTER"
description: "Total time spent in the statement, in milliseconds"
- rows:
usage: "COUNTER"
description: "Total number of rows retrieved or affected by the statement"
- shared_blks_hit:
usage: "COUNTER"
description: "Total number of shared block cache hits by the statement"
- shared_blks_read:
usage: "COUNTER"
description: "Total number of shared blocks read by the statement"
- shared_blks_dirtied:
usage: "COUNTER"
description: "Total number of shared blocks dirtied by the statement"
- shared_blks_written:
usage: "COUNTER"
description: "Total number of shared blocks written by the statement"
- temp_blks_read:
usage: "COUNTER"
description: "Total number of temp blocks read by the statement"
- temp_blks_written:
usage: "COUNTER"
description: "Total number of temp blocks written by the statement"
Loading
Loading
@@ -50,6 +50,11 @@ describe 'gitlab::postgres-exporter' do
.with_content(/exec svlogd -tt \/var\/log\/gitlab\/postgres-exporter/)
end
 
it 'creates the queries.yaml file' do
expect(chef_run).to render_file('/var/opt/gitlab/postgres-exporter/queries.yaml')
.with_content(/pg_replication:/)
end
it 'creates default set of directories' do
expect(chef_run).to create_directory('/var/log/gitlab/postgres-exporter').with(
owner: 'gitlab-psql',
Loading
Loading
@@ -60,7 +65,10 @@ describe 'gitlab::postgres-exporter' do
 
it 'sets default flags' do
expect(chef_run).to render_file('/opt/gitlab/sv/postgres-exporter/run')
.with_content(/web.listen-address=localhost:9187/)
.with_content { |content|
expect(content).to match(/web.listen-address=localhost:9187/)
expect(content).to match(/extend.query-path=\/var\/opt\/gitlab\/postgres-exporter\/queries.yaml/)
}
end
end
 
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment