postgresql-monitoring mit prometheus und grafana€¦ · postgresql, monitoring, prometheus,...
TRANSCRIPT
PostgreSQL-Monitoring mit Prometheus und Grafana
Christoph Berg
Berlin, 13. April 2018
PostgreSQL, Monitoring, Prometheus,Grafana
I PostgreSQL: Datenbanksystem
I Monitoring:
I Uberwachung (Wie voll ist die Platte)I Performance-Analyse (Wie voll war die Platte die Nacht uber)
I Prometheus: Timeseries-Datenbank, Exporter zum Datensammeln
I Grafana: Dashboards fur Prometheus-Graphen
Christoph Berg credativ GmbH 1 / 20
Dashboard
Christoph Berg credativ GmbH 2 / 20
Workflow
Workflow
Christoph Berg credativ GmbH 3 / 20
Monitoring-Architektur
Figure:Christoph Berg credativ GmbH 4 / 20
PostgreSQL-Monitoring
# SELECT datname, xact_commit, xact_rollback
FROM pg_stat_database
WHERE datname !~ ’template(0|1)’
ORDER BY datname;
datname | xact_commit | xact_rollback
----------+-------------+---------------
foo | 8881 | 0
omdb | 29149 | 18926
postgres | 43780 | 1754
(3 Zeilen)
I aktuelle WerteI keine historischen Daten
Christoph Berg credativ GmbH 5 / 20
SQL Exporter
I Prometheus-Exporter fur SQL-Queries, Ausgabe JSON-artigI https://github.com/credativ/sql exporter
I http://localhost:9237/metrics
sql_pg_stat_database{col="xact_commit",
datname="omdb",
host=":5432",
sql_job="10/main",
user="postgres"} 29149
sql_pg_stat_database{col="xact_rollback",
datname="omdb",
host=":5432",
sql_job="10/main",
user="postgres"} 18926
Christoph Berg credativ GmbH 6 / 20
Prometheus
I Timeseries-Datenbank
I pollt Exporter, z.B. alle 30s
I Abfragesprache mit Statistik-Funktionen (sum, rate)
I Ausgabe JSON, Rendering im Browser
Christoph Berg credativ GmbH 7 / 20
Prometheus: Einfache Abfrage
I sql pg stat database{col=~’xact commit|xact rollback’,
datname=’omdb’,host=’:5432’}
Christoph Berg credativ GmbH 8 / 20
Prometheus: Graph
Figure:Christoph Berg credativ GmbH 9 / 20
Prometheus: Rate
I rate(sql pg stat database{col=˜‘xact commit|xact rollback’,datname=‘omdb’,host=‘:5432’}[1m])
I Rate pro Sekunde, gemittelt uber 1 min-Interval
Christoph Berg credativ GmbH 10 / 20
Prometheus: Rate-Graph
Figure:Christoph Berg credativ GmbH 11 / 20
Grafana: Panel
I Grafana zeigt Prometheus-Daten in Panels an
I umfangreich konfigurierbar
I Rendering im Browser
Christoph Berg credativ GmbH 12 / 20
Grafana: Dashboard
Christoph Berg credativ GmbH 13 / 20
Live Demo
Live Demo
Christoph Berg credativ GmbH 14 / 20
Elephant Shed
I elephant-shed.io
Christoph Berg credativ GmbH 15 / 20
OMDB
I www.omdb.org
I https://github.com/credativ/omdb-postgresql
Christoph Berg credativ GmbH 16 / 20
access.log
SELECT page, count(*), sum(runtime) AS runtime
FROM access_log GROUP BY 1;
page | count | runtime
-----------+-------+-------------------
language | 6 | 0.607174396514892
job | 18 | 1.88291954994202
category | 209 | 7.4515106678009
character | 163 | 8.79396939277649
movie | 8011 | 481.059208393097
country | 10 | 0.430700302124024
person | 12002 | 263.316899299622
date | 5095 | 85.0427992343903
(8 Zeilen)
Christoph Berg credativ GmbH 17 / 20
omdb.yml
I /etc/prometheus-sql-exporter/omdb.ymlI update-prometheus-sql-exporter-config.service (Elephant Shed 1.2)
- name: "omdb"
help: "Web hits in our application"
scope: database
database: omdb
labels:
- "page"
values:
- "count"
- "runtime"
query: >-
SELECT page, count(*), sum(runtime) AS runtime
FROM access_log GROUP BY 1;
Christoph Berg credativ GmbH 18 / 20
Prometheus
I rate(sql omdb{host=":5432",col="count"}[1m])
Christoph Berg credativ GmbH 19 / 20
Grafana
Christoph Berg credativ GmbH 20 / 20