Docker Monitoring Bundle

Requirement

🐳  docker
🐙  docker-compose
🐱  git
🐶  nginx
🐭  certbot

🐳 Docker

Docker Installation

Ubuntu

$ sudo apt-get update

$ sudo apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    gnupg \
    lsb-release

$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

$ echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
  $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

$ sudo apt-get update
$ sudo apt-get install docker-ce docker-ce-cli containerd.io

🐙 Docker compose

Docker-compose Installation

Ubuntu

$ sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
$ sudo chmod +x /usr/local/bin/docker-compose

🐱 Git

Using git for download my repository otherwise you can use another way...

Git Installation

Ubuntu

$ sudo apt-get update; sudo apt-get install git

🐶 Nginx

Using Nginx for pretend as web server and give Certbot to check.

Nginx Installation

Ubuntu

$ sudo apt update
$ sudo apt install nginx
$ sudo systemctl status nginx

🐭 Certbot

Using Certbot for generate SSL keys for using HTTPS.

Certbot Installation

Ubuntu

$ sudo snap install core; sudo snap refresh core
$ sudo snap install --classic certbot
$ sudo ln -s /snap/bin/certbot /usr/bin/certbot
$ sudo certbot certonly --nginx

🚀 Then... location of certificates in /etc/letsencrypt/live/DOMAIN.NAME/


⚠️ !! IF YOU WANT TO UNINSTALL NGINX

$ sudo systemctl stop nginx

$ sudo systemctl status nginx

$ sudo apt-get purge nginx nginx-common

👽 Docker-monitoring-bundle

git clone: https://github.com/Winz-Mawin7/docker-monitoring-bundle

cd docker-monitoring-bundle

Kong & Konga 🦍

Kong is an API Gateway and have many plugins...

Konga is an open-source for Kong GUI.

$ sudo sh -c 'cd Kong && docker-compose up
  • You can change ENV variables

    • KONG_PG_DATABASE
    • KONG_PG_USER
    • KONG_PG_PASSWORD

    Default is "kong"

🧎🏻‍♂️ Wait until Kong start...

  • Config by Konga GUI: PORT 1337, http://localhost:1337

    • Add Services
    • Add Routes
    • Add Certificate
  • Config by REST API

Add Services

$ curl -i -X POST http://localhost:8001/services/ \
--data 'name=service_name' \
--data 'url=http://example.domain:8088'

Add Routes

$ curl -i -X POST http://localhost:8001/services/service_name/routes/ \
--data 'name=route_name' \
--data 'paths[]=/'

Add Certificate by curl to API

$ curl -i -m 60 -X POST http://localhost:8001/certificates  \
-F "cert=$(sudo cat /etc/letsencrypt/live/DOMAIN.NAME/cert.pem)" \
-F "key=$(sudo cat /etc/letsencrypt/live/DOMAIN.NAME/privkey.pem)" \
-F "snis[1]=DOMAIN.NAME"

  1. Monitoring 📈

Prometheus & Exporter & Grafana

Prometheus is an open-source time series database for monitoring system using promQL.

Exporter is an export metrics for giving prometheus scrape.

Grafana is an open-source for monitoring dashboard can add various data sources.

Using below command to copy cert and key for grafana because grafana not have permission for access /etc/letsencrypt/live folder

$ sudo cat /etc/letsencrypt/live/DOMAIN.NAME/cert.pem >> ~/docker-monitoring-bundle/Monitoring/certs/cert.pem

$ sudo cat /etc/letsencrypt/live/DOMAIN.NAME/privkey.pem >> ~/docker-monitoring-bundle/Monitoring/certs/privkey.pem

$ sudo sh -c 'cd Monitoring && docker-compose up'

  1. Services 🐯

In this repository I used my services in Docker hub for FCM messaging API you should

change docker-compose.yml in Services folder to match your services do you want.

$ sudo sh -c 'cd Services && docker-compose up'

Finally

  • Grafana

    • Add Data Source
    • Import JSON file from folder Monitoring/Dashboard.json
  • If you Setup Successfully

sudo sh -c 'cd Kong && docker-compose up -d'

sudo sh -c 'cd Monitoring && docker-compose up -d'

sudo sh -c 'cd Services && docker-compose up -d'
  • If you want to down docker-compose
sudo sh -c 'cd Kong && docker-compose down'

sudo sh -c 'cd Monitoring && docker-compose down'

sudo sh -c 'cd Services && docker-compose down'

PORTS (Open World)

  • 3000 : Grafana
  • 5432 : Postgresql
  • 8000 : Kong HTTP
  • 8088: Node-FCM
  • 8443 : Kong HTTPS
  • 9090 : Prometheus
  • 9100 : Node_Exporter

PORTS (Not Open World)

  • 8001 : Kong Admin API