Skip to content

Commit

Permalink
Merge pull request #578 from dark-vex/postgresql-exporter
Browse files Browse the repository at this point in the history
Merge pull request #577 from dark-vex/dark-vex-patch-1
  • Loading branch information
dark-vex authored May 26, 2024
2 parents e0c3f9e + f93de25 commit 50a6ca6
Show file tree
Hide file tree
Showing 2 changed files with 178 additions and 0 deletions.
145 changes: 145 additions & 0 deletions clusters/kubenuc/apps/postgresql/manifests/custom-quey.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
---
apiVersion: v1
kind: ConfigMap
metadata:
name: postgresql-exporter-server-queries
namespace: databases
labels:
app.kubernetes.io/name: postgresql-exporter-server-queries
app: postgresql-exporter-server-queries
data:
queries.yaml: |
pg_replication:
query: "SELECT EXTRACT(EPOCH FROM (now() - pg_last_xact_replay_timestamp())) as lag"
master: true
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()"
master: true
metrics:
- start_time_seconds:
usage: "GAUGE"
description: "Time at which postmaster started"
pg_stat_user_tables:
query: "SELECT current_database() datname, 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, COALESCE(last_vacuum, '1970-01-01Z'), COALESCE(last_vacuum, '1970-01-01Z') as last_vacuum, COALESCE(last_autovacuum, '1970-01-01Z') as last_autovacuum, COALESCE(last_analyze, '1970-01-01Z') as last_analyze, COALESCE(last_autoanalyze, '1970-01-01Z') as last_autoanalyze, vacuum_count, autovacuum_count, analyze_count, autoanalyze_count FROM pg_stat_user_tables"
metrics:
- datname:
usage: "LABEL"
description: "Name of current database"
- 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_statio_user_tables:
query: "SELECT current_database() datname, schemaname, relname, heap_blks_read, heap_blks_hit, idx_blks_read, idx_blks_hit, toast_blks_read, toast_blks_hit, tidx_blks_read, tidx_blks_hit FROM pg_statio_user_tables"
metrics:
- datname:
usage: "LABEL"
description: "Name of current database"
- schemaname:
usage: "LABEL"
description: "Name of the schema that this table is in"
- relname:
usage: "LABEL"
description: "Name of this table"
- heap_blks_read:
usage: "COUNTER"
description: "Number of disk blocks read from this table"
- heap_blks_hit:
usage: "COUNTER"
description: "Number of buffer hits in this table"
- idx_blks_read:
usage: "COUNTER"
description: "Number of disk blocks read from all indexes on this table"
- idx_blks_hit:
usage: "COUNTER"
description: "Number of buffer hits in all indexes on this table"
- toast_blks_read:
usage: "COUNTER"
description: "Number of disk blocks read from this table's TOAST table (if any)"
- toast_blks_hit:
usage: "COUNTER"
description: "Number of buffer hits in this table's TOAST table (if any)"
- tidx_blks_read:
usage: "COUNTER"
description: "Number of disk blocks read from this table's TOAST table indexes (if any)"
- tidx_blks_hit:
usage: "COUNTER"
description: "Number of buffer hits in this table's TOAST table indexes (if any)"
pg_database:
query: "SELECT pg_database.datname, pg_database_size(pg_database.datname) as size_bytes FROM pg_database"
master: true
cache_seconds: 30
metrics:
- datname:
usage: "LABEL"
description: "Name of the database"
- size_bytes:
usage: "GAUGE"
description: "Disk space used by the database"
33 changes: 33 additions & 0 deletions clusters/kubenuc/apps/postgresql/manifests/db.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,23 @@ metadata:
name: postgresql-nuc-cluster
namespace: databases
spec:
additionalVolumes:
- mountPath: /tmp/queries.yaml
name: customqueries
subPath: queries.yaml
targetContainers:
- exporter
volumeSource:
configMap:
name: postgresql-exporter-server-queries
teamId: "ddlns"
volume:
size: 10Gi
storageClass: "longhorn"
numberOfInstances: 3
podAnnotations:
prometheus.io/port: "9187"
prometheus.io/scrape: "true"
postgresql:
version: "15"
parameters:
Expand All @@ -20,3 +32,24 @@ spec:
requests:
cpu: "1"
memory: 1Gi
sidecars:
- env:
- name: DATA_SOURCE_URI
value: localhost:5432/postgres?sslmode=disable
- name: DATA_SOURCE_USER
value: "postgres"
- name: PG_EXPORTER_EXTEND_QUERY_PATH
value: /tmp/queries.yaml
image: quay.io/sysdig/postgresql-exporter:v0.11.6
name: exporter
ports:
- containerPort: 9187
name: exporter
protocol: TCP
resources:
limits:
cpu: 250m
memory: 256M
requests:
cpu: 100m
memory: 200M

0 comments on commit 50a6ca6

Please sign in to comment.