Skip to content

Commit 68ac020

Browse files
committed
[+] add "Bootstrapping the Configuration Database" how-to
1 parent 17f07d5 commit 68ac020

File tree

3 files changed

+103
-12
lines changed

3 files changed

+103
-12
lines changed

docs/howto/config_db_bootstrap.md

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
---
2+
title: Bootstrapping the Configuration Database
3+
---
4+
5+
## Choosing a Database
6+
7+
pgwatch supports any database that supports the PostgreSQL wire protocol. This includes:
8+
9+
- PostgreSQL
10+
- TimescaleDB
11+
- CitusDB
12+
- CockroachDB
13+
- many more
14+
15+
We will use PostgreSQL in this guide. But the steps are similar for other databases. It's up to you to choose the database that best fits your needs and set it up accordingly.
16+
17+
## Creating the Database
18+
19+
First, we need to create a database for storing the configuration. We will use the `psql` command-line tool to create the database. You can also use a GUI tool like pgAdmin to create the database.
20+
21+
Let's assume we want to create a database named `pgwatch` on a completely fresh PostgreSQL installation.
22+
It is wise to use a special role for the configuration database, so we will create a role named `pgwatch` and assign it to the `pgwatch` database.
23+
24+
```terminal
25+
$ psql -U postgres -h localhost -p 5432 -d postgres
26+
psql (17.2)
27+
28+
postgres=# CREATE ROLE pgwatch WITH LOGIN PASSWORD 'pgwatchadmin';
29+
CREATE ROLE
30+
31+
postgres=# CREATE DATABASE pgwatch OWNER pgwatch;
32+
CREATE DATABASE
33+
```
34+
35+
That's it! We have created a database named `pgwatch` with the owner `pgwatch`. Now we can proceed to the next step.
36+
37+
## Init (optional)
38+
39+
pgwatch will automatically create the necessary tables and indexes in the database when it starts. But in case
40+
you want to create the schema as a separate step, you can use the `config init` command-line command. The only thing you
41+
need is to provide the connection string to the database.
42+
43+
```terminal
44+
pgwatch --sources=postgresql://pgwatch:pgwatchadmin@localhost/pgwatch config init
45+
```
46+
47+
Or you can use the `config init` command with the `--metrics` flag, since metrics and sources share the same database.
48+
49+
```terminal
50+
pgwatch --metrics=postgresql://pgwatch:pgwatchadmin@localhost/pgwatch config init
51+
```
52+
53+
## Usage
54+
55+
You can now configure pgwatch to use the `pgwatch` database as the configuration database for storing monitored sources,
56+
metric deinitions and presets.
57+
58+
```terminal
59+
$ pgwatch --sources=postgresql://pgwatch:pgwatchadmin@localhost/pgwatch --sink=postgresql://[email protected]/measurements
60+
...
61+
[INFO] [metrics:75] [presets:17] [sources:2] sources and metrics refreshed
62+
...
63+
```
64+
65+
!!! info
66+
Even though configuration database can hold both sources and metrics definitions,
67+
you are free to use any combination of configurations. For example, you can use a database
68+
for metrics and YAML file for sources, or vice versa.
69+
70+
That's it! You have successfully bootstrapped the configuration database for pgwatch.
71+
72+
If now you want to see the tables created by pgwatch in the configuration database, you can connect to the database
73+
using the `psql` command-line tool and list the tables.
74+
75+
```terminal
76+
$ psql postgresql://pgwatch:pgwatchadmin@localhost/pgwatch
77+
psql (17.2)
78+
79+
pgwatch=# \dt pgwatch.*
80+
List of relations
81+
Schema | Name | Type | Owner
82+
---------+-----------+-------+---------
83+
pgwatch | metric | table | pgwatch
84+
pgwatch | migration | table | pgwatch
85+
pgwatch | preset | table | pgwatch
86+
pgwatch | source | table | pgwatch
87+
(4 rows)
88+
```
89+
90+
You may examine these tables to understand how pgwatch stores metrics and presets definitions, as well as what sources and how to monitor in the database.

docs/howto/metrics_db_bootstrap.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: Bootstrapping the Metrics Measurements Database (Sink)
33
---
44

5-
# Choosing a Database
5+
## Choosing a Database
66

77
pgwatch supports multiple databases for storing metrics measurements. The following databases are supported:
88

@@ -14,14 +14,14 @@ pgwatch supports multiple databases for storing metrics measurements. The follow
1414

1515
We will use PostgreSQL in this guide. But the steps are similar for other databases. It's up to you to choose the database that best fits your needs and set it up accordingly.
1616

17-
# Creating the Database
17+
## Creating the Database
1818

1919
First, we need to create a database for storing the metrics measurements. We will use the `psql` command-line tool to create the database. You can also use a GUI tool like pgAdmin to create the database.
2020

21-
Let's assume we want to create a database named `measurements` on a completely fresh PostgreSQL installation.
21+
Let's assume we want to create a database named `measurements` on a completely fresh PostgreSQL installation.
2222
It is wise to use a special role for the metrics database, so we will create a role named `pgwatch` and assign it to the `measurements` database.
2323

24-
```
24+
```terminal
2525
$ psql -U postgres -h 10.0.0.42 -p 5432 -d postgres
2626
psql (17.2)
2727
@@ -34,24 +34,24 @@ CREATE DATABASE
3434

3535
That's it! We have created a database named `measurements` with the owner `pgwatch`. Now we can proceed to the next step.
3636

37-
# Usage
37+
## Usage
3838

3939
pgwatch will automatically create the necessary tables and indexes in the database when it starts. You don't need to create any tables or indexes manually.
4040

41-
You can now configure pgwatch to use the `measurements` database as the sink for storing metrics measurements.
41+
You can now configure pgwatch to use the `measurements` database as the sink for storing metrics measurements.
4242

43-
```bash
43+
```terminal
4444
$ pgwatch --sources=/etc/sources.yaml --sink=postgresql://[email protected]/measurements
4545
[INFO] [sink:postgresql://[email protected]/measurements] Initialising measurements database...
4646
[INFO] [sink:postgresql://[email protected]/measurements] Measurements sink activated
4747
...
4848
```
4949

50-
That's it! You have successfully bootstrapped the metrics measurements database for pgwatch. You can now start collecting metrics from your sources and storing them in the database.
50+
That's it! You have successfully bootstrapped the metrics measurements database for pgwatch. You can now start collecting metrics from your sources and storing them in the database.
5151

5252
If now you want to see the tables created by pgwatch in the `measurements` database, you can connect to the database using the `psql` command-line tool and list the tables.
5353

54-
```
54+
```terminal
5555
$ psql -U pgwatch -h 10.0.0.42 -p 5432 -d measurements
5656
psql (17.2)
5757
@@ -67,6 +67,6 @@ measurements=> \dn
6767
You can see that pgwatch has created the `admin` and `subpartitions` schemas in the `measurements` database. These schemas contain the tables and indexes used by pgwatch to store metrics measurements. You may examine these schemas to understand how pgwatch stores metrics measurements in the database.
6868

6969
!!! tip
70-
You can also add `--log-level=debug` command-line parameter to see every SQL query executed by pgwatch.
71-
This can be useful for debugging purposes. But remember that this will log a lot of information,
72-
so it is wise to use it with empty sources this time, meaning there are no database to monitor yet.
70+
You can also add `--log-level=debug` command-line parameter to see every SQL query executed by pgwatch.
71+
This can be useful for debugging purposes. But remember that this will log a lot of information,
72+
so it is wise to use it with empty sources this time, meaning there are no database to monitor yet.

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ nav:
6262
- How-To Guides:
6363
- Dashboarding and Alerting: howto/dashboarding_alerting.md
6464
- Using Managed Services: howto/using_managed_services.md
65+
- Bootstrapping the Configuration Database: howto/config_db_bootstrap.md
6566
- Bootstraping the Metrics Measurements Database (Sink): howto/metrics_db_bootstrap.md
6667
- Reference:
6768
- Advanced Features: reference/advanced_features.md

0 commit comments

Comments
 (0)