# DEX Metrics

Komodo DeFi Framework 2.0 collects data metrics that allow interested users to view the history of events of an Komodo DeFi Framework session. For example, metrics recorded by the Komodo DeFi Framework include incoming and outgoing traffic.

The metrics can be:

  • Recorded to a log file at a specified frequency
  • Requested using Komodo DeFi Framework in JSON format
  • Visualized using Prometheus and Grafana

# Setting Up the Log Recording

By default, the collected metrics are recorded to a log file every five minutes.

A custom time interval can be set during the initiation of the Komodo DeFi Framework 2.0 software.

For example, to set the interval to two minutes, initiate Komodo DeFi Framework with the additional argument \"metrics\":120, as follows.

TIP

Note that in the examples below, the you will need to change the text to reflect your own password and passphrase.

Example:

stdbuf -oL ./mm2 "{\"gui\":\"Docs_Walkthru\",\"netid\":7777, \"userhome\":\"/${HOME#"/"}\", \"passphrase\":\"YOUR_PASSPHRASE_HERE\", \"rpc_password\":\"YOUR_PASSWORD_HERE\", \"metrics\":120}" &

To prohibit the recording of metrics to the log file, set the metrics argument to 0.

Example:

stdbuf -oL ./mm2 "{\"gui\":\"Docs_Walkthru\",\"netid\":7777, \"userhome\":\"/${HOME#"/"}\", \"passphrase\":\"YOUR_PASSPHRASE_HERE\", \"rpc_password\":\"YOUR_PASSWORD_HERE\", \"metrics\":0}" &

# API Calling

Execute the following command to request a metrics snapshot.

curl --url "http://127.0.0.1:7783" --data "{\"method\":\"metrics\"}"

The response should be similar to the following.

{
  "metrics": [
    {
      "type": "gauge",
      "key": "p2p.received_messages.period_in_secs",
      "labels": {},
      "value": 60.0
    },
    {
      "type": "gauge",
      "key": "p2p.connected_relays.len",
      "labels": {},
      "value": 4.0
    },
    {
      "type": "gauge",
      "key": "orderbook.len",
      "labels": {},
      "value": 0.0
    },
    {
      "type": "gauge",
      "key": "p2p.relay_mesh.len",
      "labels": {},
      "value": 2.0
    },
    {
      "type": "gauge",
      "key": "p2p.received_messages.count",
      "labels": {},
      "value": 0.0
    },
    {
      "type": "gauge",
      "key": "p2p.connected_peers.count",
      "labels": {},
      "value": 4.0
    },
    {
      "type": "gauge",
      "key": "orderbook.memory_db",
      "labels": {},
      "value": 297800386624.0
    }
  ]
}

# Prometheus Integration

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

Prometheus scrapes metrics using an HTTP pull model.

To provide Prometheus with the ability to scrape the metrics at localhost:9001, initiate Komodo DeFi Framework with the following additional argument:

\"prometheusport\":9001

You may optionally specify the username and password for Prometheus to enforce basic authorization security. For this effect, add one more argument as follows:

\"prometheus_credentials\":\"PROM_USERNAME:PROM_PASSWORD\"

Note that this additional argument is NOT necessary.

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

Note that the username and password should be separated by :.

Example:

stdbuf -oL ./mm2 "{\"gui\":\"Docs_Walkthru\",\"netid\":7777, \"userhome\":\"/${HOME#"/"}\", \"passphrase\":\"YOUR_PASSPHRASE_HERE\", \"rpc_password\":\"YOUR_PASSWORD_HERE\", \"prometheusport\":9001, \"prometheus_credentials\":\"PROM_USERNAME:PROM_PASSWORD\"}" &

# Configuring Prometheus to monitor the Komodo DeFi Framework

The following basic Prometheus configuration file, named prometheus.yml, can simplify the process of connecting Prometheus to the Komodo DeFi Framework.

global:
  scrape_interval: 10s
scrape_configs:
  - job_name: "KomoDeFi"
    basic_auth:
      username: "PROM_USERNAME"
      password: "PROM_PASSWORD"
    static_configs:
      - targets: ["0.0.0.0:9001"]
        labels:
          group: "komodefi"

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. (opens new window)

# Starting Prometheus and Grafana

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

# Using the graphing interface

# Prometheus

Once the docker containers are up and running, navigate to http://localhost:9090/graph (opens new window) 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.

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

# Grafana

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. (opens new window)

To use Grafana, navigate to http://localhost:3000 (opens new window) 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 (opens new window).

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

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.

Next, navigate to http://localhost:3000/dashboards (opens new window) and click on the New Dashboard button

Next, click on Add a new panel

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

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 (opens new window).

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

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.

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