I'm using docker-compose to launch the Prometheus and alertmanager containers and see the alerts I received in Slack.
In the docker environment, create a container that runs the following applications.
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
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
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
.
Slack You can see that the alert displayed by Prometheus can be received by Channle of Slack.
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