All Projects → justwatchcom → Sql_exporter

justwatchcom / Sql_exporter

Licence: mit
Flexible SQL Exporter for Prometheus

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to Sql exporter

Postgresql exporter
A Prometheus exporter for some postgresql metrics
Stars: ✭ 26 (-86.6%)
Mutual labels:  postgresql, prometheus, prometheus-exporter
Query Exporter
Export Prometheus metrics from SQL queries
Stars: ✭ 166 (-14.43%)
Mutual labels:  sql, prometheus, prometheus-exporter
Neo4j Etl
Data import from relational databases to Neo4j.
Stars: ✭ 165 (-14.95%)
Mutual labels:  sql, postgresql
Sqlcheck
Automatically identify anti-patterns in SQL queries
Stars: ✭ 2,062 (+962.89%)
Mutual labels:  sql, postgresql
Rom Sql
SQL support for rom-rb
Stars: ✭ 169 (-12.89%)
Mutual labels:  sql, postgresql
Yuniql
Free and open source schema versioning and database migration made natively with .NET Core.
Stars: ✭ 156 (-19.59%)
Mutual labels:  sql, postgresql
Sqorn
A Javascript library for building SQL queries
Stars: ✭ 1,871 (+864.43%)
Mutual labels:  sql, postgresql
Jaguar orm
Source-generated ORM with relations (one-to-one, one-to-many, many-to-many), preloading, cascading, polymorphic relations, etc
Stars: ✭ 188 (-3.09%)
Mutual labels:  sql, postgresql
Elephant Shed
PostgreSQL Management Appliance
Stars: ✭ 146 (-24.74%)
Mutual labels:  postgresql, prometheus
Sql Battleships
Play Battleships on PostgreSQL
Stars: ✭ 174 (-10.31%)
Mutual labels:  sql, postgresql
Prometheus Pve Exporter
Exposes information gathered from Proxmox VE cluster for use by the Prometheus monitoring system
Stars: ✭ 171 (-11.86%)
Mutual labels:  prometheus, prometheus-exporter
Nut
Advanced, Powerful and easy to use ORM for Qt
Stars: ✭ 181 (-6.7%)
Mutual labels:  sql, postgresql
Jmx exporter
A process for exposing JMX Beans via HTTP for Prometheus consumption
Stars: ✭ 2,134 (+1000%)
Mutual labels:  prometheus, prometheus-exporter
Pagespeed exporter
Prometheus pagespeed exporter
Stars: ✭ 149 (-23.2%)
Mutual labels:  prometheus, prometheus-exporter
Dgw
dgw generates Golang struct, and simple Table/Row Data Gateway functions from PostgreSQL table metadata
Stars: ✭ 161 (-17.01%)
Mutual labels:  sql, postgresql
Querybuilder
SQL query builder, written in c#, helps you build complex queries easily, supports SqlServer, MySql, PostgreSql, Oracle, Sqlite and Firebird
Stars: ✭ 2,111 (+988.14%)
Mutual labels:  sql, postgresql
Prometheus Es Exporter
Prometheus Elasticsearch Exporter
Stars: ✭ 184 (-5.15%)
Mutual labels:  prometheus, prometheus-exporter
Redis exporter
Prometheus Exporter for Redis Metrics. Supports Redis 2.x, 3.x, 4.x, 5.x and 6.x
Stars: ✭ 2,092 (+978.35%)
Mutual labels:  prometheus, prometheus-exporter
Sqlcell
SQLCell is a magic function for the Jupyter Notebook that executes raw, parallel, parameterized SQL queries with the ability to accept Python values as parameters and assign output data to Python variables while concurrently running Python code. And *much* more.
Stars: ✭ 145 (-25.26%)
Mutual labels:  sql, postgresql
Linq2db
Linq to database provider.
Stars: ✭ 2,211 (+1039.69%)
Mutual labels:  sql, postgresql

Prometheus SQL Exporter Build Status

Docker Pulls Go Report Card

This repository contains a service that runs user-defined SQL queries at flexible intervals and exports the resulting metrics via HTTP for Prometheus consumption.

Status

Actively used with PostgreSQL in production. We'd like to eventually support all databases for which stable Go database drivers are available. Contributions welcome.

What does it look like?

Grafana DB Dashboard

Getting Started

Create a config.yml and run the service:

go get github.com/justwatchcom/sql_exporter
cp config.yml.dist config.yml
./prom-sql-exporter

Running in Docker:

docker run \
  -v `pwd`/config.yml:/config/config.yml \
  -e CONFIG=/config/config.yml \
  -d \
  -p 9237:9237 \
  --name sql_exporter \
  justwatch/sql_exporter

Manual scrape_configs snippet:

scrape_configs:
- job_name: sql_exporter
  static_configs:
  - targets: ['localhost:9237']

Flags

Name Description
version Print version information
web.listen-address Address to listen on for web interface and telemetry
web.telemetry-path Path under which to expose metrics
config.file SQL Exporter configuration file name

Environment Variables

Name Description
CONFIG Location of Configuration File (yaml)

Usage

We recommend to deploy and run the SQL exporter in Kubernetes.

Kubernetes

See examples/kubernetes.

Grafana

See examples/grafana.

Prometheus

Example recording and alerting rules are available in examples/prometheus.

Configuration

When writing queries for this exporter please keep in mind that Prometheus data model assigns exactly one float to a metric, possibly further identified by a set of zero or more labels. These labels need to be of type string or text.

If your SQL dialect supports explicit type casts, you should always cast your label columns to text and the metric colums to float. The SQL exporter will try hard to support other types or drivers w/o support for explicit cast as well, but the results may not be what you expect.

Below is a documented configuration example showing all available options. For a more realistic example please have a look at examples/kubernetes/configmap.yml.

---
# jobs is a map of jobs, define any number but please keep the connection usage on the DBs in mind
jobs:
  # each job needs a unique name, it's used for logging and as an default label
- name: "example"
  # interval defined the pause between the runs of this job
  interval: '5m'
  # connections is an array of connection URLs
  # each query will be executed on each connection
  connections:
  - 'postgres://[email protected]/postgres?sslmode=disable'
  # startup_sql is an array of SQL statements
  # each statements is executed once after connecting
  startup_sql:
  - 'SET lock_timeout = 1000'
  - 'SET idle_in_transaction_session_timeout = 100'
  # queries is a map of Metric/Query mappings
  queries:
    # name is prefied with sql_ and used as the metric name
  - name: "running_queries"
    # help is a requirement of the Prometheus default registry, currently not
    # used by the Prometheus server. Important: Must be the same for all metrics
    # with the same name!
    help: "Number of running queries"
    # Labels is an array of columns which will be used as additional labels.
    # Must be the same for all metrics with the same name!
    # All labels columns should be of type text, varchar or string
    labels:
      - "datname"
      - "usename"
    # Values is an array of columns used as metric values. All values should be
    # of type float
    values:
      - "count"
    # Query is the SQL query that is run unalterted on the each of the connections
    # for this job
    query:  |
            SELECT datname::text, usename::text, COUNT(*)::float AS count
            FROM pg_stat_activity GROUP BY datname, usename;

Running as non-superuser on PostgreSQL

Some queries require superuser privileges on PostgreSQL. If you prefer not to run the exporter with superuser privileges, you can use some views/functions to get around this limitation.

CREATE USER postgres_exporter PASSWORD 'pw';
ALTER USER postgres_exporter SET SEARCH_PATH TO postgres_exporter,pg_catalog;

CREATE SCHEMA postgres_exporter AUTHORIZATION postgres_exporter;

CREATE FUNCTION postgres_exporter.f_select_pg_stat_activity()
RETURNS setof pg_catalog.pg_stat_activity
LANGUAGE sql
SECURITY DEFINER
AS $$
  SELECT * from pg_catalog.pg_stat_activity;
$$;

CREATE FUNCTION postgres_exporter.f_select_pg_stat_replication()
RETURNS setof pg_catalog.pg_stat_replication
LANGUAGE sql
SECURITY DEFINER
AS $$
  SELECT * from pg_catalog.pg_stat_replication;
$$;

CREATE VIEW postgres_exporter.pg_stat_replication
AS
  SELECT * FROM postgres_exporter.f_select_pg_stat_replication();

CREATE VIEW postgres_exporter.pg_stat_activity
AS
  SELECT * FROM postgres_exporter.f_select_pg_stat_activity();

GRANT SELECT ON postgres_exporter.pg_stat_replication TO postgres_exporter;
GRANT SELECT ON postgres_exporter.pg_stat_activity TO postgres_exporter;

Logging

You can change the loglevel by setting the LOGLEVEL variable in the exporters environment.

LOGLEVEL=info ./sql_exporter

Why this exporter exists

The other projects with similar goals did not meet our requirements on either maturity or flexibility. This exporter does not rely on any other service and runs in production for some time already.

License

MIT License

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].