Skip to content

Commit 607a51e

Browse files
docs: revisit README.md (burningalchemist#545)
1 parent c547cd8 commit 607a51e

File tree

1 file changed

+120
-52
lines changed

1 file changed

+120
-52
lines changed

README.md

Lines changed: 120 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -74,29 +74,6 @@ Running `make drivers-all` will regenerate driver set back to the current defaul
7474
Feel free to revisit and add more drivers as required. There's also the `custom` list that allows managing a separate
7575
list of drivers for special needs.
7676

77-
## Run as a Windows service
78-
79-
If you run SQL Exporter from Windows, it might come in handy to register it as a service to avoid interactive sessions.
80-
It is **important** to define `--config.file` parameter to load the configuration file. The other settings can be added
81-
as well. The registration itself is performed with Powershell or CMD (make sure you run it as Administrator):
82-
83-
Powershell:
84-
85-
```powershell
86-
New-Service -name "SqlExporterSvc" `
87-
-BinaryPathName "%SQL_EXPORTER_PATH%\sql_exporter.exe --config.file %SQL_EXPORTER_PATH%\sql_exporter.yml" `
88-
-StartupType Automatic `
89-
-DisplayName "Prometheus SQL Exporter"
90-
```
91-
92-
CMD:
93-
94-
```shell
95-
sc.exe create SqlExporterSvc binPath= "%SQL_EXPORTER_PATH%\sql_exporter.exe --config.file %SQL_EXPORTER_PATH%\sql_exporter.yml" start= auto
96-
```
97-
98-
`%SQL_EXPORTER_PATH%` is a path to the SQL Exporter binary executable. This document assumes that configuration files
99-
are in the same location.
10077

10178
## Configuration
10279

@@ -215,7 +192,94 @@ For example, `p@$$w0rd#abc` then becomes `p%40%24%24w0rd%23abc`.
215192

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

218-
#### Using AWS Secrets Manager
195+
196+
## Miscellaneous
197+
198+
<details>
199+
<summary>Multiple database connections</summary>
200+
201+
It is possible to run a single exporter instance against multiple database connections. In this case we need to
202+
configure `jobs` list instead of the `target` section as in the following example:
203+
204+
```yaml
205+
jobs:
206+
- job_name: db_targets
207+
collectors: [pricing_data_freshness, pricing_*]
208+
enable_ping: true # Optional, true by default. Set to `false` in case you connect to pgbouncer or a data warehouse
209+
static_configs:
210+
- targets:
211+
pg1: 'pg://db1@127.0.0.1:25432/postgres?sslmode=disable'
212+
pg2: 'postgresql://username:password@pg-host.example.com:5432/dbname?sslmode=disable'
213+
labels: # Optional, arbitrary key/value pair for all targets
214+
cluster: cluster1
215+
```
216+
217+
, where DSN strings are assigned to the arbitrary instance names (i.e. pg1 and pg2).
218+
219+
We can also define multiple jobs to run different collectors against different target sets.
220+
221+
Since v0.14, sql_exporter can be passed an optional list of job names to filter out metrics. The `jobs[]` query
222+
parameter may be used multiple times. In Prometheus configuration we can use this syntax under the [scrape
223+
config](https://prometheus.io/docs/prometheus/latest/configuration/configuration/#%3Cscrape_config%3E):
224+
225+
```yaml
226+
params:
227+
jobs[]:
228+
- db_targets1
229+
- db_targets2
230+
```
231+
232+
This might be useful for scraping targets with different intervals or any other advanced use cases, when calling all
233+
jobs at once is undesired.
234+
235+
</details>
236+
237+
<details>
238+
<summary>Scraping PgBouncer, ProxySQL, Clickhouse or Snowflake</summary>
239+
240+
Given that PgBouncer is a connection pooler, it doesn't support all the commands that a regular SQL database does, so
241+
we need to make some adjustments to the configuration:
242+
243+
- add `enable_ping: false` to the metric/job configuration as PgBouncer doesn't support the ping command;
244+
- add `no_prepared_statement: true` to the metric/job configuration as PgBouncer doesn't support the extended query protocol;
245+
246+
Note: For libpq(postgres) we only need to add `no_prepared_statement: true` parameter. For pgx driver, we also need to
247+
add `default_query_exec_mode=simple_protocol` parameter to the DSN (for v5).
248+
249+
Below is an example of a metric configuration for PgBouncer:
250+
```yaml
251+
metrics:
252+
- metric_name: max_connections
253+
no_prepared_statement: true
254+
type: gauge
255+
values: [max_connections]
256+
key_labels:
257+
- name
258+
- database
259+
- force_user
260+
- pool_mode
261+
- disabled
262+
- paused
263+
- current_connections
264+
- reserve_pool
265+
- min_pool_size
266+
- pool_size
267+
- port
268+
query: |
269+
SHOW DATABASES;
270+
271+
```
272+
273+
Same goes for ProxySQL and Clickhouse, where we need to add `no_prepared_statement: true` to the metric/job
274+
configuration, as these databases doesn't support prepared statements.
275+
276+
In case, you connect to a data warehouse (e.g. Snowflake) you don't want to keep online all the time (due to the extra
277+
cost), you might want to disable `ping` by setting `enable_ping: false`.
278+
</details>
279+
280+
281+
<details>
282+
<summary>Using AWS Secrets Manager</summary>
219283

220284
If the database runs on AWS EC2 instance, this is a secure option to store the DSN without having it in
221285
the configuration file. To use this option:
@@ -260,50 +324,54 @@ the secret. Policy example:
260324

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

263-
### Multiple database connections
327+
</details>
264328

265-
It is possible to run a single exporter instance against multiple database connections. In this case we need to
266-
configure `jobs` list instead of the `target` section as in the following example:
329+
<details>
330+
<summary>Run as a Windows service</summary>
267331

268-
```yaml
269-
jobs:
270-
- job_name: db_targets
271-
collectors: [pricing_data_freshness, pricing_*]
272-
enable_ping: true # Optional, true by default. Set to `false` in case you connect to pgbouncer or a data warehouse
273-
static_configs:
274-
- targets:
275-
pg1: 'pg://db1@127.0.0.1:25432/postgres?sslmode=disable'
276-
pg2: 'postgresql://username:password@pg-host.example.com:5432/dbname?sslmode=disable'
277-
labels: # Optional, arbitrary key/value pair for all targets
278-
cluster: cluster1
279-
```
332+
If you run SQL Exporter from Windows, it might come in handy to register it as a service to avoid interactive sessions.
333+
It is **important** to define `--config.file` parameter to load the configuration file. The other settings can be added
334+
as well. The registration itself is performed with Powershell or CMD (make sure you run it as Administrator):
280335

281-
, where DSN strings are assigned to the arbitrary instance names (i.e. pg1 and pg2).
336+
Powershell:
282337

283-
We can also define multiple jobs to run different collectors against different target sets.
338+
```powershell
339+
New-Service -name "SqlExporterSvc" `
340+
-BinaryPathName "%SQL_EXPORTER_PATH%\sql_exporter.exe --config.file %SQL_EXPORTER_PATH%\sql_exporter.yml" `
341+
-StartupType Automatic `
342+
-DisplayName "Prometheus SQL Exporter"
343+
```
284344

285-
Since v0.14, sql_exporter can be passed an optional list of job names to filter out metrics. The `jobs[]` query
286-
parameter may be used multiple times. In Prometheus configuration we can use this syntax under the [scrape
287-
config](https://prometheus.io/docs/prometheus/latest/configuration/configuration/#%3Cscrape_config%3E):
345+
CMD:
288346

289-
```yaml
290-
params:
291-
jobs[]:
292-
- db_targets1
293-
- db_targets2
347+
```shell
348+
sc.exe create SqlExporterSvc binPath= "%SQL_EXPORTER_PATH%\sql_exporter.exe --config.file %SQL_EXPORTER_PATH%\sql_exporter.yml" start= auto
294349
```
295350

296-
This might be useful for scraping targets with different intervals or any other advanced use cases, when calling all
297-
jobs at once is undesired.
351+
`%SQL_EXPORTER_PATH%` is a path to the SQL Exporter binary executable. This document assumes that configuration files
352+
are in the same location.
353+
354+
In case you need a more sophisticated setup (e.g. with logging, environment variables, etc), you might want to use [NSSM](https://nssm.cc/) or
355+
[WinSW](https://github.com/winsw/winsw). Please consult their documentation for more details.
298356

299-
### TLS and Basic Authentication
357+
</details>
358+
359+
<details>
360+
<summary>TLS and Basic Authentication</summary>
300361

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

303364
To use TLS and/or Basic Authentication, you need to pass a configuration file using the `--web.config.file` parameter.
304365
The format of the file is described in the
305366
[exporter-toolkit](https://github.com/prometheus/exporter-toolkit/blob/master/docs/web-configuration.md) repository.
306367

368+
</details>
369+
370+
If you have an issue using sql_exporter, please check [Discussions](https://github.com/burningalchemist/sql_exporter/discussions) or
371+
closed [Issues](https://github.com/burningalchemist/sql_exporter/issues?q=is%3Aissue+is%3Aclosed) first. Chances are
372+
someone else has already encountered the same problem and there is a solution. If not, feel free to create a new
373+
discussion.
374+
307375
## Why It Exists
308376

309377
SQL Exporter started off as an exporter for Microsoft SQL Server, for which no reliable exporters exist. But what is

0 commit comments

Comments
 (0)