Alert slack with alert manager in Docker environment

What to do in this article

I'm using docker-compose to launch the Prometheus and alertmanager containers and see the alerts I received in Slack.

Screen Shot 2020-12-24 at 8.11.31.png

environment

In the docker environment, create a container that runs the following applications.

Environment

In this article, we will use docker-compose to build Prometheus and alertmanager. First, create the file structure as follows.

docker-compose.yaml
prometheus
-- prometheus.yaml
-- alert_rules.yaml
alertmanager
-- alertmanager.yaml

Next, build the docker network with docker network create --subnet = 172.19.0.0/19 prom_net. After building the configuration file and docker nework, build the docker environment with the following docker-compose.yaml.

docker-compose.yaml


version: '2.2'
# define services
services:
  prometheus:
    image: prom/prometheus
    container_name: prometheus
    volumes: 
       - ./prometheus:/etc/prometheus
    command: "--config.file=/etc/prometheus/prometheus.yaml --storage.tsdb.retention.time=10m"
    ports: 
      - 9090:9090      
    restart: "no"
  alertmanager:
    image: prom/alertmanager
    container_name: alertmanager
    volumes:
      - ./alertmanager:/etc/alertmanager
    command: "--config.file=/etc/alertmanager/alertmanager.yaml"
    ports:
      - 9093:9093
    restart: "no"

# define network
networks:  
  default:
    external:
      name: prom_net

Prometheus settings

The configuration file of Prometheus is as follows. For slack_api_url:'<Your channel on Slack>', enter the webhook URL of any Slack you created.

prometheus.yaml


global:
  slack_api_url: '< Your channel on Slack >'

route:
  receiver: slack
  routes:
  - match:
      receiver: 'slack'


receivers:
  - name: slack
    slack_configs:
    - channel: '< Channel Name >'
      text: '< Optional Text>'

Next, Prometheus is set to send alerts about Mertric. We have selected appropriate Metrics for the conditions for sending alerts, so please choose your favorite Metrics.

alert_rule.yaml


groups:
- name: prometheus_build
  rules:
  - alert: test
    expr: prometheus_build_info == 1
    for: 10s
    labels:
      severity: notice
    annotations:
      text: testsing alert

test

Finally, launch each application's container and see the alerts sent by Prometheus and Slack. By the way, the following is the command to start / stop the container configured with docker-compose. docker-compose up docker-compose down

Prometheus Below, you can see from the image that the alert is being sent under the conditions set in alert_rule.yaml. Screen Shot 2020-12-24 at 7.47.22.png

Slack You can see that the alert displayed by Prometheus can be received by Channle of Slack. Screen Shot 2020-12-24 at 7.40.55.png

Impressions

I used Prometheus and alertmanager to check if I could receive alerts in Slack. In the future, I would like to send an alert to Elasticsearch and configure it so that Kibana can check the log. In this article, I used Slack's Channel to see if I could send alerts.

Recommended Posts

Alert slack with alert manager in Docker environment
Edit Mysql with commands in Docker environment
Self-hosting with Docker of AuteMuteUs in Windows environment
Pytorch execution environment with Docker
[Note] Build a Python3 environment with Docker in EC2
[Docker] Rails 5.2 environment construction with docker
Build docker environment with WSL
React environment construction with Docker
Database environment construction with Docker in Spring boot (IntellJ)
Create a Vue3 environment with Docker!
Node.js environment construction with Docker Compose
Build Couchbase local environment with Docker
Build a Node.js environment with Docker
Environment construction with Docker for beginners
Build PlantUML environment with VSCode + Docker
Try running cloudera manager with docker
Build environment with vue.js + rails + docker
Build Rails environment with Docker Compose
Create SolrCloud verification environment with Docker
Install laravel/Dusk in docker environment (laravel6)
Create Laravel environment with Docker (docker-compose)
[Environment construction with Docker] Rails 6 & MySQL 8
Build docker + laravel environment with laradock
Check MySQL logs in Docker environment
A story stuck with log output in Docker + Play framework environment
GPU environment construction with Docker [October 2020 version]
[Docker] Use environment variables in Nginx conf
Rails environment construction with Docker (personal apocalypse)
Building Rails 6 and PostgreSQL environment with Docker
Laravel development environment construction with Docker (Mac)
Build a PureScript development environment with Docker
Create Rails 6 + MySQL environment with Docker compose
Use docker in proxy environment on ubuntu 20.04.1
Scraping with puppeteer in Nuxt on Docker.
Environment construction with Docker (Ubuntu20.04) + Laravel + nginx
Create a MySQL environment with Docker from 0-> 1
Create Spring Boot-gradle-mysql development environment with Docker
[Docker] Create Node.js + express + webpack environment with Docker
Laravel + MySQL + phpMyadmin environment construction with Docker
Build a Wordpress development environment with Docker
Show Better Errors in Rails + Docker environment
[Docker] Build Jupyter Lab execution environment with Docker
Build an environment with Docker on AWS
Lightweight PHP 7.4 development environment created with Docker
Build TensorFlow operation check environment with Docker
Dealing with composer installation errors in Docker
How to build Rails 6 environment with Docker
How to execute with commands of normal development language in Docker development environment
I tried to build a Firebase application development environment with Docker in 2020
Install Zabbix 5.0 with Docker → Set up Slack notification in case of failure
Spring Boot environment construction with Docker (January 2021 version)
Use JDBC Manager with the settings in jdbc.dicon.
[Memo] Create a CentOS 8 environment easily with Docker
Make SpringBoot1.5 + Gradle4.4 + Java8 + Docker environment compatible with Java11
Just install Laravel8 on docker in PHP8 environment
Build a Laravel / Docker environment with VSCode devcontainer
(Basic authentication) environment variables in rails and Docker
Environment construction command memo with Docker on AWS
Build a WordPress development environment quickly with Docker
Rails6 [API mode] + MySQL5.7 environment construction with Docker
Docker in LXD