ibp-network / ibp-monitor

15 stars 10 forks source link

IBP Monitor - network of members

Architecture / Components

Getting Started

Clone the repository:

git clone https://github.com/ibp-network/ibp-monitor.git
cd ibp-monitor

Configuration

Under the docker folder, Rename .env.sample file to .env, and edit P2P_PUBLIC_HOST and/or P2P_PUBLIC_IP variables. These are going to be used to announce your monitor node's public address, so that it can connect with the other monitor nodes on the network. You may leave both commented out, or include any or both.

mv .env.sample .env
nano .env
# edit values as necessary

Rest of the default configuration is in config/config.js. Make a copy of the file, and edit the necessary items:

cp config.js config.local.js

Any item changed in config/config.local.js will override the default value in config/config.js

For details of the config items, please refer CONFIG.md

Default Ports

Datastore

The database abstraction layer is powered by Sequelize. The default datastore is MariaDB, supported DBs are:

Notes:

Initialise the datastore

After you make the necessary edits in config/config.local.js for your choice of database, you can use the following commands to install the necessary dependencies and run the migrations:

cd data
node migrate.js

If you instead choose to run the IBP stack using Docker Compose, the ibp-datastore-init job defined in docker/docker-compose.yml will initialise the database using Sequelize migration definitions under data/migrations, which use the data model definitions under data/models.

Manual / Development

Hosts file (for development)

Inside Docker, the components can access each other by hostnames. When developing locally, you need to edit config/config.local.js file to define the ports, or set /etc/hosts as follows:

127.0.0.1 ibp-redis
127.0.0.1 ibp-datastore
127.0.0.1 ibp-monitor-api

If you don't have Redis or MariaDB installed, you can start these individually & manually via Docker. See below for more info.

Starting each component manually

Clone the repository and install the dependencies:

git clone https://github.com/ibp-network/ibp-monitor.git
cd ibp-monitor
npm install

Each component requires a separate shell window.

  1. Redis & MariaDB

    See Docker section if you don't have these running locally, or, amend the config to point to your local services.

  2. API

    node api.js
  3. P2P Server

    node server.js
  4. Front End (static)

    See Docker, this will launch on http://localhost:30001.

    cd frontend
    npm install
    npm run build # target files will populate ./static
  5. Front End (developer mode)

    In developer mode the frontend will proxy /api to the API service. See ./vue- spa/vite.config.js if you need to amend this. Note, in production mode the /api location is proxied by nginx to the ibp-monitor-api service.

    cd frontend
    npm install
    npm run serve
  6. BullMQ See http://localhost:3000/admin/queues

    node workers.js

PM2

As above, each node.js component can run separately in PM2. (Requires MariaDB and Redis)

pm2 start --name ibp-monitor-api api.js
pm2 start --name ibp-monitor-p2p server.js
pm2 start --name ibp-monitor-workders workers.js

Serving the frontend apache/nginx

The frontend is located in the ./frontend/static folder. See development above for building the folder contents.

Point Apache or nginx to serve this folder, with the following config (nginx example):

server {
  listen 80;
  server_name ibp-monitor.metaspan.io;
  location /api {
    # to preserve the url encoding, don't put the /api on the end
    proxy_pass http://ibp-monitor-api:30002;
  }
  location / {
    root /usr/share/nginx/html;
    index index.html index.htm;
    try_files $uri $uri/ /index.html;
  }
  error_page 500 502 503 504 /50x.html;
  location = /50x.html {
  root /usr/share/nginx/html;
}

Docker

Docker files and docker-compose.yml are in the ./docker folder. Service names:

Edit the .env file

Under the docker folder, Rename .env.sample file to .env, and edit P2P_PUBLIC_HOST and/or P2P_PUBLIC_IP variables. These are going to be used to announce your monitor node's public address, so that it can connect with the other monitor nodes on the network. You may leave both commented out, or include any or both.

mv .env.sample .env
nano .env
# edit values as necessary

Start all services

cd docker # you need to be in the docker directory!
docker compose up

Use ctrl-c to stop services.

Use -d flag with compose (docker compose up -d) for detach to let the services run in background.

Start individual services

cd docker # you need to be in the docker directory!
docker compose up <service name> # optional `-d` flag

Getting started

(Tested on Node v16)

git clone https://github.com/ibp-network/ibp-monitor.git
cd  ibp-monitor
npm install
cd config
# edit config.local.js to suit your needs
cp config.js config.local.js
# initialise the datastore
cd data
node migrate.js
cd ..
# run the server
node server.js
# run the workers
node workers.js
# run the API
node api.js
# run the frontend
cd frontend
npm install
npm run dev

optional

pm2 save  # to persist your jobs
pm2 list  # see the running jobs
pm2 logs  ibp-monitor

TODO

Kudos