Commit f3f04697 authored by Ben Wilson's avatar Ben Wilson Committed by GitHub

Docker-compose metric collection (#763)

* Docker-compose metric collection
* Added prometheus and dashboard-sync services
Co-authored-by: default avatarGeorgios Konstantopoulos <me@gakonst.com>
parent 467e2757
up: down
DOCKER_BUILDKIT=1 \
docker-compose \
-f docker-compose.yml \
up --build --detach
.PHONY: up
down:
docker-compose \
-f docker-compose.yml \
down
.PHONY: down
ps:
docker-compose \
-f docker-compose.yml \
ps
.PHONY: ps
up-metrics: down-metrics
DOCKER_BUILDKIT=1 \
docker-compose \
-f docker-compose.yml \
-f docker-compose-metrics.yml \
up --build --detach
.PHONY: up-metrics
down-metrics:
docker-compose \
-f docker-compose.yml \
-f docker-compose-metrics.yml \
down
.PHONY: down-metrics
ps-metrics:
docker-compose \
-f docker-compose.yml \
-f docker-compose-metrics.yml \
ps
.PHONY: ps
\ No newline at end of file
# docker-compose
The docker-compose project runs a local optimism stack.
## prerequisites
- docker
- docker-compose
- make
## Starting and stopping the project
The base `docker-compose.yml` file will start the required components for a full stack.
Supplementing the base configuration is an additional metric enabling file, `docker-compose-metrics.yml`. Adding this configuration to the stack will enable metric emission for l2geth and start grafana (for metrics visualisation) and influxdb (for metric collection) instances.
The base stack can be started and stopped with a command like this (there is no need to specify the default docker-compose.yml)
```
docker-compose \
up --build --detach
```
To start the stack with monitoring enabled, just add the metric composition file.
```
docker-compose \
-f docker-compose.yml \
-f docker-compose-metrics.yml \
up --build --detach
```
A Makefile has been provided for convience. The following targets are available.
- make up
- make down
- make up-metrics
- make down-metrics
## Authentication
Influxdb has authentication disabled.
Grafana requires a login. The defaults are:
```
user: admin
password: optimism
```
## Data persistance
Grafana data is not currently saved. Any modifications or additions will be lost on container restart.
InfluxDB is persisting data to a Docker volume.
**Stopping the project removing the containers will not clear this volume**
To remove the influxdb and grafana data, run a commands like
```
docker volume rm ops_influxdb_data
docker volume rm ops_grafana_data
```
## Accessing Grafana dashboards
After starting up the project Grafana should be listening on http://localhost:3000.
Access this link and authenticate as `admin` (see #Authentication)
From the Dashboard list, select "Geth dashboard".
version: "3"
services:
l2geth:
command: ["--metrics", "--metrics.influxdb", "--metrics.influxdb.endpoint", "http://influxdb:8086", "--metrics.influxdb.database", "l2geth"]
grafana:
image: grafana/grafana:7.5.5
env_file:
- ./envs/metrics.env
ports:
- ${GRAFANA_HTTP_PORT:-3000}:3000
volumes:
- ./docker/grafana/provisioning/:/etc/grafana/provisioning/:ro
- grafana_data:/var/lib/grafana/
- grafana_dashboards:/grafana-dashboards:ro
influxdb:
image: quay.io/influxdb/influxdb:1.6
env_file:
- ./envs/metrics.env
volumes:
- influxdb_data:/var/lib/influxdb
prometheus:
image: prom/prometheus
env_file:
- ./envs/metrics.env
volumes:
- ./docker/prometheus:/etc/prometheus
- prometheus_data:/prometheus
dashboard-sync:
image: python:3
env_file:
- ./envs/metrics.env
command:
- python
- /scripts/dashboard-sync.py
volumes:
- ./docker/scripts/:/scripts
- grafana_dashboards:/grafana-dashboards
volumes:
influxdb_data:
grafana_data:
grafana_dashboards:
prometheus_data:
\ No newline at end of file
......@@ -18,7 +18,7 @@ services:
dockerfile: Dockerfile
ports:
# expose the service to the host for integration testing
- ${L1_CHAIN_PORT:-9545}:8545
- ${L1CHAIN_HTTP_PORT:-9545}:8545
deployer:
depends_on:
......
apiVersion: 1
providers:
- name: dashboards
type: file
updateIntervalSeconds: 30
options:
path: /grafana-dashboards
foldersFromFilesStructure: true
\ No newline at end of file
apiVersion: 1
datasources:
- name: InfluxDB
type: influxdb
access: proxy
orgId: 1
database: l2geth
url: http://influxdb:8086
version: 1
editable: false
apiVersion: 1
datasources:
- name: Prometheus
type: prometheus
access: proxy
orgId: 1
url: http://prometheus:9090
version: 1
editable: false
\ No newline at end of file
# my global config
global:
scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
# scrape_timeout is set to the global default (10s).
# Alertmanager configuration
alerting:
alertmanagers:
- static_configs:
- targets:
# - alertmanager:9093
# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
# - "first_rules.yml"
# - "second_rules.yml"
# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
- job_name: 'data-transport-layer'
static_configs:
- targets: ['dtl:7878']
import os
import urllib.request
dashboard_list=[
{
'name': 'Single Geth',
'filename': 'single_geth.json',
'url': 'https://gist.githubusercontent.com/karalabe/1e26f9ea5c842fb118584edadc454e18/raw/6754e6d5c59328e19ad3a8a29a8e7e41fd46e202/geth.json'
}
]
dashboard_path="/grafana-dashboards"
GF_SECURITY_ADMIN_PASSWORD = os.environ.get('GF_SECURITY_ADMIN_PASSWORD')
if GF_SECURITY_ADMIN_PASSWORD is None:
print('GF_SECURITY_ADMIN_PASSWORD env value is missing, exiting.')
sys.exit(1)
if (not os.path.exists(dashboard_path)) or (not os.path.isdir(dashboard_path)) or (not os.access(dashboard_path, os.W_OK)):
print('Dashboard path %s is not writable, exiting'.format(dashboard_path))
sys.exit(1)
for dashboard in dashboard_list:
with urllib.request.urlopen(dashboard['url']) as f:
response = f.read()
decoded_html = response.decode('utf-8')
data = decoded_html.replace('${DS_INFLUXDB}', 'InfluxDB')
d_file = open(os.path.join(dashboard_path, dashboard['filename']),'w')
d_file.write(data)
d_file.close()
GF_SECURITY_ADMIN_PASSWORD=optimism
INFLUXDB_HTTP_AUTH_ENABLED=false
INFLUXDB_DB=l2geth
......@@ -38,4 +38,4 @@ curl \
--retry-delay 1 \
$ROLLUP_CLIENT_HTTP
exec geth --verbosity="$VERBOSITY"
exec geth --verbosity="$VERBOSITY" "$@"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment