postgresql-monitoring mit prometheus und grafana€¦ · postgresql, monitoring, prometheus,...

21
PostgreSQL-Monitoring mit Prometheus und Grafana Christoph Berg Berlin, 13. April 2018

Upload: others

Post on 15-Jun-2020

62 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: PostgreSQL-Monitoring mit Prometheus und Grafana€¦ · PostgreSQL, Monitoring, Prometheus, Grafana I PostgreSQL: Datenbanksystem I Monitoring: I Uberwachung ( Wie voll ist die Platte)

PostgreSQL-Monitoring mit Prometheus und Grafana

Christoph Berg

Berlin, 13. April 2018

Page 2: PostgreSQL-Monitoring mit Prometheus und Grafana€¦ · PostgreSQL, Monitoring, Prometheus, Grafana I PostgreSQL: Datenbanksystem I Monitoring: I Uberwachung ( Wie voll ist die Platte)

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

Page 3: PostgreSQL-Monitoring mit Prometheus und Grafana€¦ · PostgreSQL, Monitoring, Prometheus, Grafana I PostgreSQL: Datenbanksystem I Monitoring: I Uberwachung ( Wie voll ist die Platte)

Dashboard

Christoph Berg credativ GmbH 2 / 20

Page 4: PostgreSQL-Monitoring mit Prometheus und Grafana€¦ · PostgreSQL, Monitoring, Prometheus, Grafana I PostgreSQL: Datenbanksystem I Monitoring: I Uberwachung ( Wie voll ist die Platte)

Workflow

Workflow

Christoph Berg credativ GmbH 3 / 20

Page 5: PostgreSQL-Monitoring mit Prometheus und Grafana€¦ · PostgreSQL, Monitoring, Prometheus, Grafana I PostgreSQL: Datenbanksystem I Monitoring: I Uberwachung ( Wie voll ist die Platte)

Monitoring-Architektur

Figure:Christoph Berg credativ GmbH 4 / 20

Page 6: PostgreSQL-Monitoring mit Prometheus und Grafana€¦ · PostgreSQL, Monitoring, Prometheus, Grafana I PostgreSQL: Datenbanksystem I Monitoring: I Uberwachung ( Wie voll ist die Platte)

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

Page 7: PostgreSQL-Monitoring mit Prometheus und Grafana€¦ · PostgreSQL, Monitoring, Prometheus, Grafana I PostgreSQL: Datenbanksystem I Monitoring: I Uberwachung ( Wie voll ist die Platte)

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

Page 8: PostgreSQL-Monitoring mit Prometheus und Grafana€¦ · PostgreSQL, Monitoring, Prometheus, Grafana I PostgreSQL: Datenbanksystem I Monitoring: I Uberwachung ( Wie voll ist die Platte)

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

Page 9: PostgreSQL-Monitoring mit Prometheus und Grafana€¦ · PostgreSQL, Monitoring, Prometheus, Grafana I PostgreSQL: Datenbanksystem I Monitoring: I Uberwachung ( Wie voll ist die Platte)

Prometheus: Einfache Abfrage

I sql pg stat database{col=~’xact commit|xact rollback’,

datname=’omdb’,host=’:5432’}

Christoph Berg credativ GmbH 8 / 20

Page 10: PostgreSQL-Monitoring mit Prometheus und Grafana€¦ · PostgreSQL, Monitoring, Prometheus, Grafana I PostgreSQL: Datenbanksystem I Monitoring: I Uberwachung ( Wie voll ist die Platte)

Prometheus: Graph

Figure:Christoph Berg credativ GmbH 9 / 20

Page 11: PostgreSQL-Monitoring mit Prometheus und Grafana€¦ · PostgreSQL, Monitoring, Prometheus, Grafana I PostgreSQL: Datenbanksystem I Monitoring: I Uberwachung ( Wie voll ist die Platte)

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

Page 12: PostgreSQL-Monitoring mit Prometheus und Grafana€¦ · PostgreSQL, Monitoring, Prometheus, Grafana I PostgreSQL: Datenbanksystem I Monitoring: I Uberwachung ( Wie voll ist die Platte)

Prometheus: Rate-Graph

Figure:Christoph Berg credativ GmbH 11 / 20

Page 13: PostgreSQL-Monitoring mit Prometheus und Grafana€¦ · PostgreSQL, Monitoring, Prometheus, Grafana I PostgreSQL: Datenbanksystem I Monitoring: I Uberwachung ( Wie voll ist die Platte)

Grafana: Panel

I Grafana zeigt Prometheus-Daten in Panels an

I umfangreich konfigurierbar

I Rendering im Browser

Christoph Berg credativ GmbH 12 / 20

Page 14: PostgreSQL-Monitoring mit Prometheus und Grafana€¦ · PostgreSQL, Monitoring, Prometheus, Grafana I PostgreSQL: Datenbanksystem I Monitoring: I Uberwachung ( Wie voll ist die Platte)

Grafana: Dashboard

Christoph Berg credativ GmbH 13 / 20

Page 15: PostgreSQL-Monitoring mit Prometheus und Grafana€¦ · PostgreSQL, Monitoring, Prometheus, Grafana I PostgreSQL: Datenbanksystem I Monitoring: I Uberwachung ( Wie voll ist die Platte)

Live Demo

Live Demo

Christoph Berg credativ GmbH 14 / 20

Page 16: PostgreSQL-Monitoring mit Prometheus und Grafana€¦ · PostgreSQL, Monitoring, Prometheus, Grafana I PostgreSQL: Datenbanksystem I Monitoring: I Uberwachung ( Wie voll ist die Platte)

Elephant Shed

I elephant-shed.io

Christoph Berg credativ GmbH 15 / 20

Page 17: PostgreSQL-Monitoring mit Prometheus und Grafana€¦ · PostgreSQL, Monitoring, Prometheus, Grafana I PostgreSQL: Datenbanksystem I Monitoring: I Uberwachung ( Wie voll ist die Platte)

OMDB

I www.omdb.org

I https://github.com/credativ/omdb-postgresql

Christoph Berg credativ GmbH 16 / 20

Page 18: PostgreSQL-Monitoring mit Prometheus und Grafana€¦ · PostgreSQL, Monitoring, Prometheus, Grafana I PostgreSQL: Datenbanksystem I Monitoring: I Uberwachung ( Wie voll ist die Platte)

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

Page 19: PostgreSQL-Monitoring mit Prometheus und Grafana€¦ · PostgreSQL, Monitoring, Prometheus, Grafana I PostgreSQL: Datenbanksystem I Monitoring: I Uberwachung ( Wie voll ist die Platte)

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

Page 20: PostgreSQL-Monitoring mit Prometheus und Grafana€¦ · PostgreSQL, Monitoring, Prometheus, Grafana I PostgreSQL: Datenbanksystem I Monitoring: I Uberwachung ( Wie voll ist die Platte)

Prometheus

I rate(sql omdb{host=":5432",col="count"}[1m])

Christoph Berg credativ GmbH 19 / 20

Page 21: PostgreSQL-Monitoring mit Prometheus und Grafana€¦ · PostgreSQL, Monitoring, Prometheus, Grafana I PostgreSQL: Datenbanksystem I Monitoring: I Uberwachung ( Wie voll ist die Platte)

Grafana

Christoph Berg credativ GmbH 20 / 20