# Monitoring Blocks Heimdall and Bor

#### Server

1 - Prerequisites

Curl

```
sudo apt install curl
```

NVM

```
curl https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash
source ~/.profile
```

Nodejs

```
nvm install node
```

PM2

```
npm install -g pm2
```

Git

```
sudo apt install git
```

2 - Download code

```
git clone git@github.com:Michel-Leidson/blocks-monitoring.git
```

3 - Enter in project directory

```
cd blocks-monitoring
```

4 - Install dependencies of project

```
npm install
```

5 - Running as a service in PM2

```
pm2 start server.js --name <choice-a-name-of-your-service>
pm2 save
pm2 startup
```

6 - Configure job in prometheus config

a - Add job in prometheus config file.

```
 - job_name: 'monitor_polygon_blocks'
    static_configs:
      - targets: ['localhost:9992']
```

b - Restart prometheus service

```
sudo systemctl restart prometheus
```

7 - Configuring reverse proxy nginx

a - Open your nginx configuration file

```
nano /etc/nginx/sites-enabled/default
```

b - Paste the content in the file

```
       location /blockshb/ {
                gzip_types *;
                proxy_pass         http://127.0.0.1:9992/;
                proxy_set_header   Host              $host;
                proxy_set_header   X-Real-IP         $remote_addr;
                proxy_set_header   X-Forwarded-For   $proxy_add_x_forwarded_for;
                proxy_set_header   X-Forwarded-Host   $host:443;
                proxy_set_header   X-Forwarded-Server $host;
                proxy_set_header   X-Forwarded-Port 443;
                proxy_set_header   X-Forwarded-Proto $scheme;
        }
```

c - Save the file

d - Restart Nginx service

```
sudo systemctl restart nginx
```

#### Client

1 - Prerequisites

Curl

```
sudo apt install curl
```

NVM

```
curl https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash
source ~/.profile
```

Nodejs

```
nvm install node
```

PM2

```
npm install -g pm2
```

Git

```
sudo apt install git
```

2 - Download the code

```
git clone git@github.com:Michel-Leidson/blocks-monitoring-polygon-client.git
```

3 - Enter the project directory

```
cd blocks-monitoring-polygon-client
```

4 - Install dependencies of project, and install dotenv with dev dependency flag

```
npm install
npm install dotenv --save-dev
```

5 - Configure .env file based on .env.example

a - Copy .env.example to .env file

```
cp .env.example .env

nano .env
```

b - Set your variabales

```
MATIC_VALIDATOR_ID=<node_name>
BACKEND_API=https://your-domain.com/blockshb
```

6 - Running as a service in PM2

```
pm2 start index.js --name <choice-a-name-of-your-service>
pm2 save
pm2 startup
```

### Create Heimdall and Bor Grafana Dashboard

1 - In "Dashboards" menu click in "Browse"

<figure><img src="https://577206089-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FilWUahKUPyBVUGJl2b1M%2Fuploads%2Fgit-blob-38b430dae22cb9f670d02d6be02bd6f1d2ad2f07%2Fimage%20(27).png?alt=media" alt=""><figcaption></figcaption></figure>

2 - Click in "New Dashboard" button

<figure><img src="https://577206089-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FilWUahKUPyBVUGJl2b1M%2Fuploads%2Fgit-blob-bd4820b67dee4e39057000d14367226301a1709f%2Fimage%20(28).png?alt=media" alt=""><figcaption></figcaption></figure>

3 - Click in "Add new panel" button

<figure><img src="https://577206089-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FilWUahKUPyBVUGJl2b1M%2Fuploads%2Fgit-blob-a96063da2f249dd0013374cc064cb7f626310180%2Fimage%20(29).png?alt=media" alt=""><figcaption></figcaption></figure>

4 - Define missed\_blocks\_type="heimdall" and define missed\_blocks\_matic\_id in query

<figure><img src="https://577206089-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FilWUahKUPyBVUGJl2b1M%2Fuploads%2Fgit-blob-3cf9478bfc6e4278281b922411bb5c3323738bdb%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

5 - Define title and description of panel and click in save button

<figure><img src="https://577206089-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FilWUahKUPyBVUGJl2b1M%2Fuploads%2Fgit-blob-99dc955c81e0665a871cc1e0bd40bf24c1f55298%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

6 - Define name of Dashboard select folder and click in "Save" button

<figure><img src="https://577206089-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FilWUahKUPyBVUGJl2b1M%2Fuploads%2Fgit-blob-91f67eea7703c6e830fe053836b87a475e45f333%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

7 - Duplicate heimdall panel and click in "Edit" button

<figure><img src="https://577206089-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FilWUahKUPyBVUGJl2b1M%2Fuploads%2Fgit-blob-f7274339688f9b1dc05d5e172d4cf4d9f90e0a17%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

8 - Define missed\_blocks\_type="bor" and define missed\_blocks\_matic\_id in query

<figure><img src="https://577206089-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FilWUahKUPyBVUGJl2b1M%2Fuploads%2Fgit-blob-2234a4ff6d9c2dfffd004a6e799c335f55d33aaf%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

9 - Define title and description of panel and click in save button

<figure><img src="https://577206089-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FilWUahKUPyBVUGJl2b1M%2Fuploads%2Fgit-blob-425f798ed9c211c6cebae03dfcdc5bec7eb7638d%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>
