forked from pgexporter/pgexporter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[pgexporter#96] Instructions for use with Grafana
- Loading branch information
Showing
3 changed files
with
127 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
# Grafana Dashboard | ||
|
||
This tutorial will show you how to encapsulate Prometheus standard API and use them to monitor state of pgexporter with the help of Grafana dashboard. | ||
|
||
## Preface | ||
|
||
This tutorial assumes that you have an installation of PostgreSQL 10+ and pgexporter. | ||
|
||
See [Install pgexporter](https://github.com/pgexporter/pgexporter/blob/main/doc/tutorial/01_install.md) | ||
for more detail. | ||
|
||
## Prometheus Configuration | ||
|
||
### Installation | ||
First of all, you should install Prometheus in your pgmoneta server. Download one of the binaries from the [Prometheus Downloads](https://prometheus.io/download/), say `prometheus-2.45.0.linux-amd64.tar.gz` (may be different for you, but the following instructions are based off of this). | ||
|
||
Unzip the tarball: | ||
```sh | ||
$ tar -xzvf prometheus-2.45.0.linux-amd64.tar.gz | ||
``` | ||
|
||
(OPTIONAL) Putting the binaries in a location included in `PATH` so that it's convenient to use `$ prometheus` (choosing `/usr/local/bin` for this): | ||
```sh | ||
$ sudo mv prometheus-2.45.0.linux-amd64/prometheus /usr/local/bin | ||
$ sudo mv prometheus-2.45.0.linux-amd64/promtool /usr/local/bin | ||
``` | ||
|
||
Verify: | ||
```sh | ||
$ prometheus --version | ||
prometheus, version 2.45.0 (branch: HEAD, revision: 8ef767e396bf8445f009f945b0162fd71827f445) | ||
build user: root@920118f645b7 | ||
build date: 20230623-15:09:49 | ||
go version: go1.20.5 | ||
platform: linux/amd64 | ||
tags: netgo,builtinassets,stringlabels | ||
``` | ||
|
||
### Configuration | ||
After you successfully installed Prometheus, you should replace `prometheus.yml` with the content below to configure how to query your pgmoneta metrics (assuming `pgexporter` runs on port `5002` on `localhost`): | ||
```yml | ||
scrape_configs: | ||
- job_name: 'pgexporter' | ||
metrics_path: '/metrics' | ||
static_configs: | ||
- targets: ['localhost:5002'] | ||
``` | ||
|
||
Run Prometheus using: | ||
```sh | ||
$ prometheus | ||
``` | ||
(assuming there is a valid `./prometheus.yaml`). | ||
|
||
|
||
Then the Prometheus service will query your pgmoneta metrics every 15 seconds and package them as time-series data. You can query your pgmoneta metrics and watch their changes as time passed in Prometheus web page (default port is `9090`). | ||
|
||
![image](https://github.com/resyfer/pgexporter/assets/74897008/1e8402c8-2b73-4758-ab82-f61e4bfa809d) | ||
|
||
## Grafana Dashboard | ||
|
||
Although Prometheus provides capacity of querying and monitoring metrics, we can not customize graphs for each metric and provide a unified view. As a result, we use Grafana to help us manage all graphs together. | ||
|
||
### Installation | ||
First of all, we should install Grafana in the computer you need to monitor pgmoneta metrics. Installation instructions for your preferred operating system is provided in the official [Grafana Installation page](https://grafana.com/docs/grafana/latest/setup-grafana/installation/): | ||
|
||
For example, on Fedora it is: | ||
```sh | ||
$ wget -q -O gpg.key https://rpm.grafana.com/gpg.key | ||
$ sudo rpm --import gpg.key | ||
``` | ||
|
||
Create and edit file `grafana.repo`: | ||
```sh | ||
$ sudo nano /etc/yum.repos.d/grafana.repo | ||
``` | ||
Contents of the file: | ||
``` | ||
[grafana] | ||
name=grafana | ||
baseurl=https://rpm.grafana.com | ||
repo_gpgcheck=1 | ||
enabled=1 | ||
gpgcheck=1 | ||
gpgkey=https://rpm.grafana.com/gpg.key | ||
sslverify=1 | ||
sslcacert=/etc/pki/tls/certs/ca-bundle.crt | ||
``` | ||
Save and Exit. | ||
|
||
```sh | ||
$ sudo dnf install grafana | ||
``` | ||
|
||
Start the daemon: | ||
```sh | ||
$ sudo systemctl start grafana-server | ||
$ sudo systemctl status grafana-server | ||
``` | ||
Verify the status is "active (running)". | ||
|
||
### Configuration | ||
You can now browse Grafana web page with default port `3000`, default user `admin` and default password `admin`. | ||
![image](https://github.com/resyfer/pgexporter/assets/74897008/711f17be-ef57-49bb-bc48-55de0ab9cd20) | ||
Set the new password. | ||
![image](https://github.com/resyfer/pgexporter/assets/74897008/72b20a7e-7b46-43c9-8479-f82823e51352) | ||
|
||
|
||
Then you can create Prometheus data source of pgmoneta. Click Menu -> Connections -> Data Sources -> "Add data source" -> Prometheus. | ||
|
||
![image](https://github.com/resyfer/pgexporter/assets/74897008/cd0d7933-39cb-4446-9abf-61e13e1147df) | ||
![image](https://github.com/resyfer/pgexporter/assets/74897008/1d2fdc13-37f7-4b89-8cbb-3cf998d11ae8) | ||
![image](https://github.com/resyfer/pgexporter/assets/74897008/ec4ccd71-61fc-4c02-8211-7b169b30841e) | ||
|
||
Then configure the data source and then "Save & test": | ||
|
||
![image](https://github.com/resyfer/pgexporter/assets/74897008/5b0c065d-ebb0-4ca7-9e01-1f1e8373c552) | ||
|
||
Then you can explore dashboards with queries in "Expore" (Home -> Explore): | ||
![image](https://github.com/resyfer/pgexporter/assets/74897008/4fbc9981-762f-4ec1-9146-ac708f92a1c2) | ||
|
||
Then "Run Query": | ||
![image](https://github.com/resyfer/pgexporter/assets/74897008/83e54bac-55e3-4c4b-a169-7e7ef6935bbd) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters