GithubHelp home page GithubHelp logo

pandres95 / ibp-monitor Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ibp-network/ibp-monitor

0.0 0.0 0.0 51.56 MB

JavaScript 61.47% TypeScript 7.45% HTML 0.51% Vue 30.55% Dockerfile 0.01%

ibp-monitor's Introduction

IBP Monitor - network of members

Architecture / Components

  • BullMQ + Redis - in-memory and persistent storage
  • Datastore (Sequelize => MariaDB, PostgreSQL, MySQL etc)
  • P2P server
  • Workers - do the service health checks and other tasks
  • API - provides http services at /api
  • Frontend - serves the web application

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

  • 3000 - BullMQ admin, HTTP
  • 3306 - MariaDB, TCP
  • 6379 - Redis, TCP
  • 30000 - libp2p, gossip, TCP <= proxy this port TCP
  • 30001 - Frontend, HTTP <= proxy this port via SSL
  • 30002 - API, HTTP

Datastore

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

Notes:

  • SQLite is not supported by the IBP stack because the separate components need concurrent access to the database.
  • If you chose another database you need to create your own installation or Docker container, and amend the ./config/config.local.js with appropriate DB connection details.

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

  • requirements
    • Redis server
    • MariaDB / MySQL / PostgreSQL server
    • hosts file (optional)
  • edit the hosts file & config.local.js as needed

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:

  • ibp-redis
  • ibp-datastore
  • ibp-datastore-init
  • ibp-monitor-api
  • ibp-monitor-server
  • ibp-monitor-workers
  • ibp-monitor-frontend

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

  • Implememt scoring

  • Implement alerting

  • implement status / metrics - some basic metrics available at /api/metrics/{serviceId}.

  • implement prometheus (or similar) api - Done, each service has a link to the Prometheus data.

  • how to create your own peerId - Done, the server will create keys/peer-id.json at 1st startup.

  • Peers should sign status updates - This is configured in libp2p.pubsub.signMessages: true.

Kudos

ibp-monitor's People

Contributors

dcolley avatar pandres95 avatar senseless avatar kukabi avatar dependabot[bot] avatar paulormart avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.