elastic / beats

:tropical_fish: Beats - Lightweight shippers for Elasticsearch & Logstash
https://www.elastic.co/products/beats
Other
12.06k stars 4.89k forks source link

Metricbeat PostgreSQL module - add database size metrics #35479

Open leweafan opened 1 year ago

leweafan commented 1 year ago

Describe the enhancement:

Currently I can not get from postgresql module database size and use SQL module and the following request

postgres=# SELECT pg_database.datname, pg_database_size(pg_database.datname) as size FROM pg_database;

  datname   |     size
----------------+--------------
 postgres   |      7248408
 template0  |      7127556
 db1        |      8403480
 db2        |      7240216
 template1  |      7135748
 db3        |    452999704
 db4        |     29874712
 db5        |     18577944
 db6        |   1395186200
 db7        |   4455660056
 db8        | 194548423192
 db9        | 138852497944
(12 lignes)

Describe a specific use case for the enhancement or feature:

Database size is important metric and should be added to postgresql module.

leweafan commented 1 year ago

You can get database size using sql module:

- module: sql
  metricsets:
    - query
  period: 300s
  hosts: ["postgres://username:password@127.0.0.1:5432/postgres?sslmode=disable"]
  driver: "postgres"
  sql_query: "SELECT pg_database.datname as pg_database_name, pg_database_size(pg_database.datname) as pg_database_size FROM pg_database;"
  sql_response_format: table

Two fields will be created:

You should add mapping for these fields to your template.

botelastic[bot] commented 3 weeks ago

Hi! We just realized that we haven't looked into this issue in a while. We're sorry!

We're labeling this issue as Stale to make it hit our filters and make sure we get back to it as soon as possible. In the meantime, it'd be extremely helpful if you could take a look at it as well and confirm its relevance. A simple comment with a nice emoji will be enough :+1. Thank you for your contribution!