|
| 1 | +# Monitoring Shisui with InfluxDB and Grafana |
| 2 | + |
| 3 | +This tutorial will guide you through the process of installing [Shisui](https://github.com/optimism-java/shisui), which is a [Portal Network](https://ethportal.net/) client, and the auxiliary software [InfluxDb](https://www.influxdata.com/products/influxdb/) and [Grafana](https://grafana.com/). With this set up, it will be possible to run a dashboard to monitor the behavior of a network node running Shisui. |
| 4 | + |
| 5 | +All the steps described here are based on [Docker](https://www.docker.com/), except for Shisui, but you can also install the software directly on the operating system. Links to documentation describing different types of installation will be provided. |
| 6 | + |
| 7 | +## Setting up InfluxDB |
| 8 | + |
| 9 | +To run InfluxDB using Docker run the command below: |
| 10 | + |
| 11 | +```sh |
| 12 | +docker run \ |
| 13 | + --name influxdb \ |
| 14 | + --publish 8086:8086 \ |
| 15 | + --add-host host.docker.internal:host-gateway \ |
| 16 | + influxdb:1.11 |
| 17 | +``` |
| 18 | + |
| 19 | +If you're using a system that doesn't have Docker, or if you prefer to install InfluxDB directly on the operating system, check out the installation options available in [the documentation](https://docs.influxdata.com/influxdb/v2/install/). |
| 20 | + |
| 21 | +From another terminal, you can execute [InfluxDB CLI](https://docs.influxdata.com/influxdb/v2/tools/influx-cli/) to finalize the InfluxDB configuration. Create the user: |
| 22 | + |
| 23 | +```sh |
| 24 | +curl -XPOST "http://localhost:8086/query" --data-urlencode "q=CREATE USER admin WITH PASSWORD 'admin' WITH ALL PRIVILEGES" |
| 25 | +``` |
| 26 | +Note that when creating the user we chose the name “admin” and the password “admin”, you can change these values if you want a different administrator user. |
| 27 | + |
| 28 | +Then log in to the InfluxDB CLI: |
| 29 | + |
| 30 | +```sh |
| 31 | +influx -username 'admin' -password 'admin' |
| 32 | +``` |
| 33 | + |
| 34 | +Create a database and a user for Shisui metrics. |
| 35 | + |
| 36 | +```sh |
| 37 | +create database shisui |
| 38 | +create user shisui with password 'shisui' |
| 39 | +``` |
| 40 | + |
| 41 | +Verify created database and user: |
| 42 | + |
| 43 | +```sh |
| 44 | +show databases |
| 45 | +show users |
| 46 | +``` |
| 47 | + |
| 48 | +Leave InfluxDB CLI. |
| 49 | + |
| 50 | +```sh |
| 51 | +quit |
| 52 | +``` |
| 53 | + |
| 54 | +InfluxDB is running and configured to store metrics from Shisui. |
| 55 | + |
| 56 | +## Preparing Shisui |
| 57 | + |
| 58 | +The next step is to install and run Shisui with the parameters that allow the metrics to be exported to our InfluxDB instance. Shisui is software written in the [Go](https://go.dev/) language, so if you don't have a compiler installed, you'll need one. Follow the instructions on the official website to [install](https://go.dev/doc/install) the compiler on your machine. |
| 59 | + |
| 60 | +Download the latest version of Shisui: |
| 61 | +```sh |
| 62 | +git clone https://github.com/optimism-java/shisui.git |
| 63 | +``` |
| 64 | + |
| 65 | +Enter the `shisui` directory and install: |
| 66 | +```sh |
| 67 | +cd shisui |
| 68 | +make shisui |
| 69 | +``` |
| 70 | + |
| 71 | +After running the above commands, you should already be able to run Shisui with the command `./build/bin/shisui`, but we can move it to the system path (you'll need sudo permission): |
| 72 | +```sh |
| 73 | +sudo mv ./build/bin/shisui /usr/local/bin |
| 74 | +``` |
| 75 | + |
| 76 | +Then run Shisui with the command: |
| 77 | +```sh |
| 78 | +shisui --data.dir $HOME/.shisui --nat stun --networks "history,beacon,state" --metrics --metrics.influxdb --metrics.influxdb.endpoint "http://127.0.0.1:8086" --metrics.influxdb.username "shisui" --metrics.influxdb.password "shisui" --metrics.influxdb.database shisui |
| 79 | +``` |
| 80 | + |
| 81 | +The parameters used are: |
| 82 | +- data.dir - configures the directory in which the databases with network data and metadata will be stored. |
| 83 | +- nat - configures the stun server, used to pick up the external IP. If you're not behind a NAT you don't need this parameter, but if you don't know anything about it, use it. |
| 84 | +- networks - configures the Shisui node to run on the three subnets: history, beacon, and state. |
| 85 | +- metrics - enable metrics collection. |
| 86 | +- metrics.influxdb - enable the InfluxDB V1 database to be fed with the collected metrics. |
| 87 | +- metrics.influxdb.endpoint - InfluxDB address for sending metrics. |
| 88 | +- metrics.influxdb.username - username used by Shisui to feed data into InfluxDB. |
| 89 | +- metrics.influxdb.password - user password used by Shisui to feed data into InfluxDB. |
| 90 | +- metrics.influxdb.database - InfluxDB database used. |
| 91 | + |
| 92 | +You can verify that Shisui is successfully pushing data by listing metrics in the database using InfluxDB CLI: |
| 93 | +```sh |
| 94 | +influx -username 'admin' -password 'admin' |
| 95 | +use shisui |
| 96 | +show measurements |
| 97 | +``` |
| 98 | + |
| 99 | +Shisui also provides other configuration parameters and even the option to run with Docker, more information can be found in its [documentation](https://github.com/optimism-java/shisui?tab=readme-ov-file#shisui). |
| 100 | + |
| 101 | +## Setting up Grafana |
| 102 | + |
| 103 | +Execute Grafana using Docker with the command: |
| 104 | + |
| 105 | +```sh |
| 106 | +docker run \ |
| 107 | + --publish 3000:3000 \ |
| 108 | + --add-host host.docker.internal:host-gateway \ |
| 109 | + grafana/grafana:latest |
| 110 | +``` |
| 111 | + |
| 112 | +After the above command, Grafana should already be accessible, open any browser and access the address [`localhost:3000`](http://localhost:3000). When prompted for a username and password, use the default `admin` and `admin` respectively. |
| 113 | + |
| 114 | + |
| 115 | + |
| 116 | +You will be redirected to the Grafana home page. First, set up your datasource. Click on the configuration icon in the left bar and select "Data sources". |
| 117 | + |
| 118 | + |
| 119 | + |
| 120 | +There aren't any datasources created yet, click on “Add datasource” to define one. For this setup, select “InfluxDB” and proceed. Two sets of values need to be configured when creating an InfluxDB datasource. The first is the “HTTP” fields, configure the “URL” with the value `http://host.docker.internal:8086` as shown below: |
| 121 | + |
| 122 | + |
| 123 | + |
| 124 | +Then configure our created dabasse “shisui” with the username and password of our created user shisui: |
| 125 | + |
| 126 | + |
| 127 | + |
| 128 | +Click on the “Save and Test” button to check that the configuration was successful: |
| 129 | + |
| 130 | + |
| 131 | + |
| 132 | +Now let's create a dashboard that consumes the data from the datasource. Click on the configuration icon in the right bar and select “Dashboards”, then, on the top right-hand side of the screen, click on the “New” menu and choose the “import” option: |
| 133 | + |
| 134 | + |
| 135 | + |
| 136 | +Click on “Upload dashboard JSON file” and choose the file [provided](shisuiDashboard.json) and import it. |
| 137 | + |
| 138 | +The dashboard should not be working, this is due to a connection failure with the datasource, so let's configure it. In the top right corner, click on the “Dashboard settings” icon: |
| 139 | + |
| 140 | + |
| 141 | + |
| 142 | +In Settings, go to the tab “Variables” and click on “New variable”. When setting up our new variable, we need to change 3 places. The type needs to be “Data source” and the name “datasource”. In the “type” menu of the “Data source options” section, we choose our newly created influxDB datasource: |
| 143 | + |
| 144 | + |
| 145 | + |
| 146 | +Click on “Apply” and save the changes made to the Dashboard. By now you have your dashboard up and running: |
| 147 | + |
| 148 | + |
0 commit comments