Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[*] improve Prometheus sink and Docker setup docs #578

Merged
merged 3 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
18 changes: 9 additions & 9 deletions docs/reference/advanced_features.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,15 @@ that:

pgwatch was originally designed with direct metrics storage in mind,
but later also support for externally controlled
[Prometheus](https://prometheus.io/) scraping was added. Note that
currently though the storage modes are exclusive, i.e. when you enable
the Prometheus endpoint (default port 9187) there will be no direct
metrics storage.

To enable the scraping endpoint set `--datastore=prometheus` and
optionally also `--prometheus-port`, `--prometheus-namespace`,
`--prometheus-listen-addr`. Additionally, note that you still need to
specify some metrics config as usually - only metrics with interval
[Prometheus](https://prometheus.io/) scraping was added.

To enable the scraping endpoint, add this commandline parameter:
`--sink=prometheus://<host>:<port>/<namespace>`.
If you omit host (Ex: `--sink=prometheus://:8080`), server listens on all
interfaces and supplied port. If you omit namespace, default is `pgwatch`.

Additionally, note that you still need to
specify some metrics config as usual - only metrics with interval
values bigger than zero will be populated on scraping.

Currently, a few built-in metrics that require some state to be stored
Expand Down
3 changes: 1 addition & 2 deletions docs/tutorial/custom_installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,7 @@ DB".
located at */etc/pgwatch/config/instances.yaml* or online
[here](https://github.com/cybertec-postgresql/pgwatch/blob/master/pgwatch/config/instances.yaml).
Note that you can also use env. variables inside the YAML templates!
3. Bootstrap the metrics storage DB (not needed if using Prometheus
mode).
3. Bootstrap the metrics storage DB (not needed if using only Prometheus sink).
4. Prepare the "to-be-monitored" databases for monitoring by creating
a dedicated login role name as a
[minimum](preparing_databases.md).
Expand Down
38 changes: 36 additions & 2 deletions docs/tutorial/docker_installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ title: Installing using Docker
The simplest real-life pgwatch setup should look something like that:

1. Decide which metrics storage engine you want to use -
*cybertec/pgwatch* uses PostgreSQL. For Prometheus mode (exposing a
port for remote scraping) one should use the slimmer
*cybertec/pgwatch* uses PostgreSQL. When only Prometheus sink is used (exposing a
port for remote scraping), one should use the slimmer
*cybertec/pgwatch-daemon* image which doesn't have any built in
databases.

Expand Down Expand Up @@ -190,3 +190,37 @@ collector could be organized. For another example how various components
(as Docker images here) can work together, see a *Docker Compose*
example with loosely coupled components
[here](https://github.com/cybertec-postgresql/pgwatch/blob/master/docker-compose.yml).

## Example of advanced setup using YAML files and dual sinks:

pgwatch service in file `docker/docker-compose.yml` can look like this:
```yaml
pgwatch:
image: cybertecpostgresql/pgwatch:latest
command:
- "--web-disable=true"
- "--sources=/sources.yaml"
- "--sink=postgresql://pgwatch@postgres:5432/pgwatch_metrics"
- "--sink=prometheus://:8080"
volumes:
- "./sources.yaml:/sources.yaml"
ports:
- "8080:8080"
depends_on:
postgres:
condition: service_healthy
```

Source file `sources.yaml` in the same directory:
```yaml
- name: demo
conn_str: postgresql://pgwatch:pgwatchadmin@postgres/pgwatch'
preset_metrics: exhaustive
is_enabled: true
group: default
```

Running this setup you get pgwatch that uses sources from YAML file and
outputs measurements to postgres DB and exposes them for Prometheus
to scrape on port 8080 instead of WebUI (which is disabled by `--web-disable`).
Metrics definition are built-in, you can examine definition in [`internal/metrics/metrics.yaml`](https://github.com/cybertec-postgresql/pgwatch/blob/master/internal/metrics/metrics.yaml).
ondar marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 1 addition & 1 deletion internal/sinks/cmdopts.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import "time"

// CmdOpts specifies the storage configuration to store metrics measurements
type CmdOpts struct {
Sinks []string `long:"sink" mapstructure:"sink" description:"URI where metrics will be stored" env:"PW_SINK"`
Sinks []string `long:"sink" mapstructure:"sink" description:"URI where metrics will be stored, can be used multiple times" env:"PW_SINK"`
BatchingDelay time.Duration `long:"batching-delay" mapstructure:"batching-delay" description:"Max milliseconds to wait for a batched metrics flush. [Default: 250ms]" default:"250ms" env:"PW_BATCHING_MAX_DELAY"`
Retention int `long:"retention" mapstructure:"retention" description:"If set, metrics older than that will be deleted" default:"14" env:"PW_RETENTION"`
RealDbnameField string `long:"real-dbname-field" mapstructure:"real-dbname-field" description:"Tag key for real database name" env:"PW_REAL_DBNAME_FIELD" default:"real_dbname"`
Expand Down
Loading