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

Add metrics server to Anchor #10

Merged
merged 16 commits into from
Oct 31, 2024
2 changes: 2 additions & 0 deletions book/src/SUMMARY.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# Summary

* [Introduction](./intro.md)
* [Metrics](./metrics.md)
* [FAQs](./faq.md)
* [Development Environment](./setup.md)
* [Contributing](./contributing.md)
* [Protocol Developers](./developers.md)

52 changes: 52 additions & 0 deletions book/src/metrics.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Metrics

Anchor comes pre-built with a suite of metrics for developers or users to monitor the health
and performance of their node.

They must be enabled at runtime using the `--metrics` CLI flag.

## Usage

In order to run a metrics server, `docker` is required to be installed.

Once docker is installed, a metrics server can be run locally via the following steps:

1. Start an anchor node with `$ anchor --metrics`
- The `--metrics` flag is required for metrics.
1. Move into the metrics directory `$ cd metrics`.
1. Bring the environment up with `$ docker-compose up --build -d`.
1. Ensure that Prometheus can access your Anchor node by ensuring it is in
the `UP` state at [http://localhost:9090/targets](http://localhost:9090/targets).
1. Browse to [http://localhost:3000](http://localhost:3000)
- Username: `admin`
- Password: `changeme`
1. Import some dashboards from the `metrics/dashboards` directory in this repo:
- In the Grafana UI, go to `Dashboards` -> `Manage` -> `Import` -> `Upload .json file`.
- The `Summary.json` dashboard is a good place to start.

## Dashboards

A suite of dashboards can be found in `metrics/dashboard` directory. The Anchor team will
frequently update these dashboards as new metrics are introduced.

We welcome Pull Requests for any users wishing to add their dashboards to this repository for
others to share.

## Scrape Targets

Prometheus periodically reads the `metrics/scrape-targets/scrape-targets.json` file. This
file tells Prometheus which endpoints to collect data from. The current file is setup to read
from Anchor on its default metrics port. You can add additional endpoints if you want to collect
metrics from other servers.

An example is Lighthouse. You can collect metrics from Anchor and Lighthouse simultaneously if
they are both running. We have an example file `scrape-targets-lighthouse.json` which allows this.
You can replace the `scrape-targets.json` file with the contents of
`scrape-targets-lighthouse.json` if you wish to collect metrics from Anchor and Lighthouse
simultaneously.

## Hosting Publicly

By default Prometheus and Grafana will only bind to localhost (127.0.0.1), in
order to protect you from accidentally exposing them to the public internet. If
you would like to change this you must edit the `http_addr` in `metrics/grafana/grafana.ini`.
40 changes: 40 additions & 0 deletions metrics/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Anchor Metrics

[![metrics.png](https://i.postimg.cc/Jh7rxtgp/metrics.png)](https://postimg.cc/4YMRN4Xc)

Here we provides a `docker-compose` environment which scrapes metrics from Anchor
nodes using Prometheus and presents them in a browser-based Grafana GUI.

For in-depth details on running metrics, please see the [anchor
book](https://anchor-book.sigmaprime.io).

## Basic Usage

1. Start an anchor node with `$ anchor --metrics`
- The `--metrics` flag is required for metrics.
1. Move in to the `metrics` directory `$ cd metrics`.
1. Bring the environment up with `$ docker-compose up --build`.
1. Ensure that Prometheus can access your Anchor node by ensuring it is in
the `UP` state at [http://localhost:9090/targets](http://localhost:9090/targets).
1. Browse to [http://localhost:3000](http://localhost:3000)
- Username: `admin`
- Password: `changeme`
1. Import some dashboards from the `dashboards` directory in this repo:
- In the Grafana UI, go to `Dashboards` -> `Manage` -> `Import` -> `Upload .json file`.
- The `Summary.json` dashboard is a good place to start.

## Hosting Publicly

By default Prometheus and Grafana will only bind to localhost (127.0.0.1), in
order to protect you from accidentally exposing them to the public internet. If
you would like to change this you must edit the `http_addr` in `grafana.ini`.

## Maintenance and Contributing

The Anchor team has a hosted version of this stack where we do the
majority of the monitoring. The dashboards in this repo are not guaranteed to
be kept updated as we add/modify metrics to Anchor. If you're having
problems, please reach out and we can update the dashboards here.

Feel free to create your own dashboards, export them and submit them here as
PRs.
Empty file.
28 changes: 28 additions & 0 deletions metrics/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#
# Metrics services -- provides a web GUI to monitor Lighthouse nodes.
#
version: "3.3"

services:
prometheus:
build:
context: prometheus
volumes:
- prometheus-data:/prometheus
- type: bind
source: ./scrape-targets
target: /prometheus/targets
restart: always
network_mode: host
grafana:
build:
context: grafana
volumes:
- grafana-data:/var/lib/grafana
restart: always
network_mode: host

volumes:
grafana-data:
prometheus-data:
targets:
4 changes: 4 additions & 0 deletions metrics/grafana/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM grafana/grafana

COPY provisioning/ /etc/grafana/provisioning
COPY grafana.ini /etc/grafana/grafana.ini
Loading
Loading