latest contributor to this doc

Last Edit: @gcharang ,

AtomicDEX Metrics

The AtomicDEX-API collects data metrics that allow interested users to view a history of events of an AtomicDEX API session, such as incoming and outgoing traffic.

The metrics can be:

  • Recorded to a log file at a specified frequency
  • Requested using AtomicDEX API in JSON format
  • Visualized using Prometheus and Grafana

By default, collected metrics are recorded to a log file every five minutes, but this value can be defined with the metrics parameter in a user's MM2.json file.

"metrics\": 0,

To disable the collection of metrics, set the metrics parameter to 0.

Execute the following command to request a metrics snapshot.

POST
metrics
{
  "method": "metrics",
  "userpass": "testpsw"
}

AtomicDEX API 2.0 supports integration with Prometheus. This software allows users to setup automated scraping of metrics at regular intervals and enables sophisticated queries on the stored timeseries data. It also allows users to configure an elegant dashboard using built-in graphs, or to export data for graphical processing using Grafana.

Prometheus scrapes metrics using an HTTP pull model. To provide Prometheus with the ability to scrape the metrics at localhost:9001, you need to add the prometheusport parameter to your MM2.json file:

"prometheusport": 9001

You can also define your username and password for Prometheus to enforce basic authorization security with the prometheus_credentials in your MM2.json file. Note that this additional argument is NOT necessary.

"prometheus_credentials": "PROM_USERNAME:PROM_PASSWORD"

Replace PROM_USERNAME and PROM_PASSWORD with your actual Prometheus username and password. Make sure your username and password are separated by :.

The following basic Prometheus configuration file, named prometheus.yml, can simplify the process of connecting Prometheus to the AtomicDEX API.

global:
  scrape_interval: 10s

scrape_configs:
  - job_name: "AtomicDEX_API"

    basic_auth:
      username: "PROM_USERNAME"
      password: "PROM_PASSWORD"

    static_configs:
      - targets: ["0.0.0.0:9001"]
        labels:
          group: "atomicdex"

Replace PROM_USERNAME and PROM_PASSWORD with your actual Prometheus username and password.

To learn more about creating a Prometheus configuration file, read this documentation.

A simple way to initiate Prometheus and Grafana is to have the standard Prometheus and Grafana docker containers run together using docker-compose.

Name the following compose file as docker-compose.yml.

version: "3.1"
volumes:
  prometheus:
  grafana:
services:
  grafana:
    image: grafana/grafana:latest
    depends_on:
      - prometheus
    ports:
      - "3000:3000"
    network_mode: "host"
    volumes:
      - grafana:/var/lib/grafana
    restart: always
  prometheus:
    image: prom/prometheus:latest
    ports:
      - "9090:9090"
    network_mode: "host"
    volumes:
      - ./prometheus.yml:/etc/prometheus/prometheus.yml
      - prometheus:/prometheus
    restart: always

Use the following command to start both containers.

docker-compose up

Once the docker containers are up and running, navigate to http://localhost:9090/graph and use the Graph tab to use Prometheus's built-in graph expressions.

To visualize one of the available metrics, open the metric explorer (next to the execute button), select a metric and then click execute.

Prometheus

More graphs can be added to the same page using the "Add Panel" button available.

Grafana can access data scraped by Prometheus and it can analyze, transform and display it in a variety of ways. For more information see the Prometheus guide.

To use Grafana, navigate to http://localhost:3000 and log in using the default credentials: admin / admin. When offered to set a new password, do so and secure it in an encrypted password manager like KeePassXC.

Next we need to add Prometheus as a data source. Click on the cog icon in the sidebar to open the configuration panel.

Grafana

Click the "Add data source" button, and select Prometheus from the menu. Set the URL to http://localhost:9090, leave other fields as default, and click the "Test and save" button at the bottom of the form.

Grafana

Next, navigate to http://localhost:3000/dashboards and click on the New Dashboard button

Grafana

Next, click on Add a new panel

Grafana

In the next screen, select Prometheus as the provider from the drop down menu in the Query tab.

Grafana

Click the Metrics menu and select one of the available options. These should be the same ones available directly in the Graphs tab of Prometheus: http://localhost:9090/graph.

Grafana

Optionally, you can tweak the query options (shown in the image below).

Grafana

Once complete, click on Run queries to see the data displayed on the graph. If you like, you can also customise the graph, by adding a title, changing the colors, or using a different graph type. Click Apply in the top right corner once complete.

Grafana

Add any additional panels as desired, and save them to your dashboard.

Grafana