Skip to content

Commit

Permalink
Use docker compose to setup metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
Ktl-XV committed Jan 9, 2025
1 parent f518cc2 commit 4df4e0e
Show file tree
Hide file tree
Showing 11 changed files with 88 additions and 54 deletions.
50 changes: 22 additions & 28 deletions book/src/users/monitoring.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,29 @@ htop
```

## Metrics
[Metrics setup with docker](#metrics-setup-with-docker) (Recomended)

[Metrics setup no docker](#metrics-setup-no-docker)

[Metrics setup with docker](#metrics-setup-with-docker)
## Metrics setup with docker
1. [Install Docker](https://docs.docker.com/engine/install/).

2. From the `metrics` directory run:
```sh
docker compose up
```

3. Start your Trin process exposing metrics:
```sh
cargo run -p trin -- --enable-metrics-with-url 0.0.0.0:9100 --web3-http-address http://0.0.0.0:8545 --web3-transport http
```
- The addresses must be bound to 0.0.0.0, because 127.0.0.1 only allows internal requests to
complete, and requests from docker instances are considered external.
- The `--enable-metrics-with-url` parameter is the address that Trin exports metrics to, and should be equal to the port to which your Prometheus server is targeting at the bottom of `prometheus/prometheus.yml`
- The `--web-transport http` will allow Grafana to request routing table information from Trin via JSON-RPC over HTTP

4. Navigate to http://localhost:3000/d/trin-metrics/trin-metrics. Use `admin`/`admin` to login.


## Metrics setup no docker
Prometheus maintains a database of metrics (trin & system). Grafana converts metrics into graphs. Node exporter provides system information.
Expand Down Expand Up @@ -230,13 +250,7 @@ http_addr = localhost # After

Copy the provisioning files. From trin root directory:
```sh
sudo cp -R etc/grafana/provisioning /etc/grafana/provisioning
```
Modify prometheus datasource to use localhost
```ini
url: http://host.docker.internal:9090 # Before
url: http://127.0.0.1:9090 # After
```
sudo cp -R metrics/grafana/provisioning /etc/grafana/provisioning
Start grafana
```sh
Expand Down Expand Up @@ -291,26 +305,6 @@ ssh -N -L 3000:127.0.0.1:3000 username@mycomputer
Then navigate to [http://127.0.0.1:3000](http://127.0.0.1:3000)` in a browser and login
with username: admin, password: admin. Then navigate to the trin-app-metrics dashboard.

## Metrics setup with docker
1. Install Docker.
2. Run Prometheus, note that you MUST manually set the absolute path to your copy of Trin's `etc/prometheus/`:
```sh
docker run -p 9090:9090 -v /**absolute/path/to/trin/etc/prometheus**:/etc/prometheus --add-host=host.docker.internal:host-gateway prom/prometheus
```
3. Run Grafana:
```sh
docker run -p 3000:3000 -v /**absolute/path/to/trin/etc/grafana/provisioning**:/etc/grafana/provisioning --add-host=host.docker.internal:host-gateway grafana/grafana:latest
```
4. Start your Trin process with:
```sh
cargo run -p trin -- --enable-metrics-with-url 0.0.0.0:9100 --web3-http-address http://0.0.0.0:8545 --web3-transport http
```
- The addresses must be bound to 0.0.0.0, because 127.0.0.1 only allows internal requests to
complete, and requests from docker instances are considered external.
- The `--enable-metrics-with-url` parameter is the address that Trin exports metrics to, and should be equal to the port to which your Prometheus server is targeting at the bottom of `prometheus/prometheus.yml`
- The `--web-transport http` will allow Grafana to request routing table information from Trin via JSON-RPC over HTTP
5. Navigate to http://localhost:3000/d/trin-metrics/trin-metrics. Use `admin`/`admin` to login.

## Gotchas

- There is a limit on concurrent connections given by the threadpool. At last
Expand Down
8 changes: 0 additions & 8 deletions etc/README.md

This file was deleted.

6 changes: 0 additions & 6 deletions etc/grafana/provisioning/dashboards/trin.yaml

This file was deleted.

10 changes: 0 additions & 10 deletions etc/grafana/provisioning/datasources/prometheus.yaml

This file was deleted.

25 changes: 25 additions & 0 deletions metrics/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Trin Metrics

You can run this docker compose file it will run
- prometheus
- grafana
- setup the metrics dashboard

Metrics are useful for telling how Trin is performing.

The default username and password is `admin`.

### How to run
```sh
docker compose up
```

### View the dashboard at
http://localhost:3000/d/trin-metrics/trin-metrics

***WARNING***: don't forget to run `Trin` with metric exporting on!

**Example**
```bash
cargo run -p trin -- --enable-metrics-with-url 0.0.0.0:9100 --web3-http-address http://0.0.0.0:8545 --web3-transport http
```
20 changes: 20 additions & 0 deletions metrics/compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
services:
prometheus:
image: prom/prometheus
container_name: prometheus
command:
- '--config.file=/etc/prometheus/prometheus.yml'
network_mode: "host"
restart: unless-stopped
volumes:
- ./prometheus:/etc/prometheus
- prom_data_trin:/prometheus
grafana:
image: grafana/grafana
container_name: grafana
network_mode: "host"
restart: unless-stopped
volumes:
- ./grafana/provisioning/:/etc/grafana/provisioning
volumes:
prom_data_trin:
7 changes: 7 additions & 0 deletions metrics/grafana/provisioning/dashboards/trin.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: 1

providers:
- name: 'Trin'
type: file
options:
path: /etc/grafana/provisioning/dashboards/trin
11 changes: 11 additions & 0 deletions metrics/grafana/provisioning/datasources/prometheus.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: 1

datasources:
- name: Prometheus
type: prometheus
uid: trinprom
url: http://localhost:9090
orgId: 1
access: proxy
isDefault: true

Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ alerting:
static_configs:
- targets: []
scrape_configs:
- job_name: prometheus
- job_name: trin
honor_timestamps: true
scrape_interval: 15s
scrape_timeout: 10s
metrics_path: /metrics
scheme: http
follow_redirects: true
enable_http2: true
fallback_scrape_protocol: PrometheusText0.0.4
static_configs:
- targets:
- host.docker.internal:9100
- localhost:9100

0 comments on commit 4df4e0e

Please sign in to comment.