Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 49 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Prometheus SQL Exporter [![Go](https://github.com/burningalchemist/sql_exporter/workflows/Go/badge.svg)](https://github.com/burningalchemist/sql_exporter/actions?query=workflow%3AGo) [![Go Report Card](https://goreportcard.com/badge/github.com/burningalchemist/sql_exporter)](https://goreportcard.com/report/github.com/burningalchemist/sql_exporter) [![Docker Pulls](https://img.shields.io/docker/pulls/burningalchemist/sql_exporter)](https://hub.docker.com/r/burningalchemist/sql_exporter) ![Downloads](https://img.shields.io/github/downloads/burningalchemist/sql_exporter/total)

This is a permanent fork of Database agnostic SQL exporter for [Prometheus](https://prometheus.io) created by [@free](https://github.com/free/sql_exporter).
This is a permanent fork of Database agnostic SQL exporter for [Prometheus](https://prometheus.io) created by
[@free](https://github.com/free/sql_exporter).

## Overview

Expand Down Expand Up @@ -59,7 +60,9 @@ By default we produce a binary with all the supported drivers with the following
make build
```

It's also possible to reduce the size of the binary by only including specific set of drivers like Postgres, MySQL and MSSQL. In this case we need to update `drivers.go`. To avoid manual manipulation there is a helper code generator available, so we can run the following commands:
It's also possible to reduce the size of the binary by only including specific set of drivers like Postgres, MySQL and
MSSQL. In this case we need to update `drivers.go`. To avoid manual manipulation there is a helper code generator
available, so we can run the following commands:

```shell
make drivers-minimal
Expand All @@ -70,7 +73,8 @@ The first command will regenerate `drivers.go` file with a minimal set of import

Running `make drivers-all` will regenerate driver set back to the current defaults.

Feel free to revisit and add more drivers as required. There's also the `custom` list that allows managing a separate list of drivers for special needs.
Feel free to revisit and add more drivers as required. There's also the `custom` list that allows managing a separate
list of drivers for special needs.

## Run as a Windows service

Expand Down Expand Up @@ -180,7 +184,7 @@ metrics:
GROUP BY Market
```

### Data Source Names
### Data Source Names (DSN)

To keep things simple and yet allow fully configurable database connections, SQL Exporter uses DSNs (like
`sqlserver://prom_user:[email protected]:1433`) to refer to database instances.
Expand All @@ -194,33 +198,42 @@ mysql://user:pass@localhost/dbname - for TCP connection
mysql:/var/run/mysqld/mysqld.sock - for Unix socket connection
```

If your DSN contains special characters in any part of your connection string (including passwords), you might need to apply
[URL encoding](https://en.wikipedia.org/wiki/URL_encoding#Reserved_characters) (percent-encoding) to them.
If your DSN contains special characters in any part of your connection string (including passwords), you might need to
apply [URL encoding](https://en.wikipedia.org/wiki/URL_encoding#Reserved_characters) (percent-encoding) to them.
For example, `p@$$w0rd#abc` then becomes `p%40%24%24w0rd%23abc`.

For additional details please refer to [xo/dburl](https://github.com/xo/dburl) documentation.

#### Using AWS Secrets Manager

If the database runs on AWS EC2 instance, this is a secure option to store the `Data source name` without having it in the configuration file.
To use this option:
- Create a [secret](https://docs.aws.amazon.com/secretsmanager/latest/userguide/manage_create-basic-secret.html) in key/value pairs format, specify Key `data_source_name` and then for Value enter the DSN value.
For the secret name, enter a name for your secret, and pass that name in the configuration file as a value for `aws_secret_name` item under `target`. Secret json example:
If the database runs on AWS EC2 instance, this is a secure option to store the DSN without having it in
the configuration file. To use this option:

```
- Create a [secret](https://docs.aws.amazon.com/secretsmanager/latest/userguide/manage_create-basic-secret.html) in
key/value pairs format, specify Key `data_source_name` and then for Value enter the DSN value.
For the secret name, enter a name for your secret, and pass that name in the configuration file as a value for
`aws_secret_name` item under `target`. Secret json example:

```json
{
"data_source_name": "sqlserver://prom_user:[email protected]:1433"
}
```

- Configuration file Example
```
- Configuration file example:

```yaml
...
target:
aws_secret_name: '<AWS_SECRET_NAME>'
...
```
- Allow read-only access from EC2 IAM role to the secret by attaching a [resource-based policy](https://docs.aws.amazon.com/secretsmanager/latest/userguide/auth-and-access_resource-based-policies.html) to the secret. Policy Example:
```

- Allow read-only access from EC2 IAM role to the secret by attaching a [resource-based
policy](https://docs.aws.amazon.com/secretsmanager/latest/userguide/auth-and-access_resource-based-policies.html) to
the secret. Policy example:

```json
{
"Version" : "2012-10-17",
"Statement" : [
Expand All @@ -234,6 +247,27 @@ target:
}
```

Currently, AWS Secret Manager integration is only available for a single target configuration.

### Multiple database connections

It is possible to run a single exporter instance against multiple database connections. In this case we need to
configure `jobs` list instead of the `target` section as in the following example:

```yaml
jobs:
- job_name: db_targets
collectors: [pricing_data_freshness, pricing_*]
static_configs:
- targets:
pg1: 'pg://[email protected]:25432/postgres?sslmode=disable'
pg2: 'pg://[email protected]:25432/testdb?sslmode=disable'
```

, where DSN strings are assigned to the arbitrary instance names (i.e. pg1 and pg2).

We can also define multiple jobs to run different collectors against different target sets.

### TLS and Basic Authentication

SQL Exporter supports TLS and Basic Authentication. This enables better control of the various HTTP endpoints.
Expand Down