Skip to content

Commit

Permalink
[WIP] Set up sql-exporter to monitor db content
Browse files Browse the repository at this point in the history
  • Loading branch information
reosarevok committed Dec 18, 2024
1 parent 22f7bf7 commit c40a2c7
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 0 deletions.
15 changes: 15 additions & 0 deletions compose/monitoring.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,21 @@ services:
db:
condition: service_started
restart: unless-stopped
sql-exporter:
image: burningalchemist/sql_exporter
container_name: sql-exporter
expose:
- 9399
command: --config.file=/etc/sql-exporter/sql-exporter.yml
volumes:
- ./default/sql-exporter.yml:/etc/sql-exporter/sql-exporter.yml
depends_on:
prometheus:
condition: service_started
db:
condition: service_started
restart: unless-stopped


volumes:
grafana-storage: {}
3 changes: 3 additions & 0 deletions default/prometheus.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ scrape_configs:
- job_name: postgres
static_configs:
- targets: ['postgres-exporter:9187']
- job_name: 'sql_exporter'
static_configs:
- targets: ['sql-exporter:9399']
59 changes: 59 additions & 0 deletions default/sql-exporter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Global settings and defaults.
global:
# Subtracted from Prometheus' scrape_timeout to give us some headroom and prevent Prometheus from
# timing out first.
scrape_timeout_offset: 500ms
# Minimum interval between collector runs: by default (0s) collectors are executed on every scrape.
min_interval: 0s
# Maximum number of open connections to any one target. Metric queries will run concurrently on
# multiple connections.
max_connections: 3
# Maximum number of idle connections to any one target.
max_idle_connections: 3
# Maximum amount of time a connection may be reused to any one target. Infinite by default.
max_connection_lifetime: 10m

# The target to monitor and the list of collectors to execute on it.
target:
# Data source name always has a URI schema that matches the driver name. In some cases (e.g. MySQL)
# the schema gets dropped or replaced to match the driver expected DSN format.
data_source_name: 'postgres://musicbrainz:musicbrainz@db:5432/musicbrainz_db?sslmode=disable'

# Collectors (referenced by name) to execute on the target.
collectors: [entity_counts]

# A collector is a named set of related metrics that are collected together. It can be referenced by name, possibly
# along with other collectors.
#
# Collectors may be defined inline (under `collectors`) or loaded from `collector_files` (one collector per file).
collectors:
# A collector defining standard metrics for Microsoft SQL Server.
- collector_name: entity_counts

# Similar to global.min_interval, but applies to this collector only.
#min_interval: 0s

# A metric is a Prometheus metric with name, type, help text and (optional) additional labels, paired with exactly
# one query to populate the metric labels and values from.
#
# The result columns conceptually fall into two categories:
# * zero or more key columns: their values will be directly mapped to labels of the same name;
# * one or more value columns:
# * if exactly one value column, the column name is ignored and its value becomes the metric value
# * with multiple value columns, a `value_label` must be defined; the column name will populate this label and
# the column value will populate the metric value.
metrics:
# The metric name, type and help text, as exported to /metrics.
- metric_name: artist_count
type: gauge
help: 'Total number of rows in the artist table.'
# This query returns exactly one value per row, in the `count` column.
values: [count]
query: SELECT count(*) AS count FROM artist

- metric_name: label_count
type: gauge
help: 'Total number of rows in the label table.'
# This query returns exactly one value per row, in the `count` column.
values: [count]
query: SELECT count(*) AS count FROM label

0 comments on commit c40a2c7

Please sign in to comment.