├── README.md ├── alertmanager └── alertmanager.yml ├── docker-compose.yml ├── grafana └── provisioning │ └── datasources │ └── prometheus_ds.yml └── prometheus ├── alert.yml └── prometheus.yml /README.md: -------------------------------------------------------------------------------- 1 | # Monitoring Stack 2 | 3 | Basic setup of Prometheus, Grafana and AlertManager with docker-compose. 4 | 5 | Source for https://dashdashverbose.medium.com/monitoring-setup-with-docker-compose-part-1-prometheus-3d2c9089ee82 6 | 7 | 8 | [![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/Y8Y1EKYJI) 9 | -------------------------------------------------------------------------------- /alertmanager/alertmanager.yml: -------------------------------------------------------------------------------- 1 | route: 2 | group_by: [ alertname ] 3 | receiver: 'mail' # default receiver 4 | repeat_interval: 24h 5 | routes: 6 | - receiver: 'teams' 7 | repeat_interval: 12h 8 | matchers: 9 | - severity="medium" 10 | 11 | - receiver: 'teams' 12 | repeat_interval: 4h 13 | matchers: 14 | - severity="high" 15 | 16 | 17 | receivers: 18 | - name: 'mail' 19 | email_configs: 20 | - smarthost: 'yourmailhost.com:465' 21 | auth_username: 'yourmail@yourmailhost.com' 22 | auth_password: "your mail password" 23 | from: 'yourmail@yourmailhost.com' 24 | to: 'someonesmail@yourmailhost.com' 25 | require_tls: false 26 | 27 | - name: 'teams' 28 | webhook_configs: 29 | - url: "http://prom2teams:8089" 30 | send_resolved: true 31 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | 3 | services: 4 | prometheus: 5 | image: prom/prometheus:v2.30.3 6 | ports: 7 | - 9000:9090 8 | volumes: 9 | - ./prometheus:/etc/prometheus 10 | - prometheus-data:/prometheus 11 | command: --web.enable-lifecycle --config.file=/etc/prometheus/prometheus.yml 12 | 13 | 14 | grafana: 15 | image: grafana/grafana:8.2.2 16 | ports: 17 | - 3000:3000 18 | restart: unless-stopped 19 | volumes: 20 | - ./grafana/provisioning/datasources:/etc/grafana/provisioning/datasources 21 | - grafana-data:/var/lib/grafana 22 | 23 | alertmanager: 24 | image: prom/alertmanager:v0.23.0 25 | restart: unless-stopped 26 | ports: 27 | - "9093:9093" 28 | volumes: 29 | - "./alertmanager:/config" 30 | - alertmanager-data:/data 31 | command: --config.file=/config/alertmanager.yml --log.level=debug 32 | 33 | prom2teams: 34 | image: idealista/prom2teams:3.2.3 35 | restart: unless-stopped 36 | environment: 37 | PROM2TEAMS_CONNECTOR: "https://og2gether.webhook.office.com/webhookb2/b5370781-89c2-45ba-be14-453e29dfb0a9@8794e153-c3bd-4479-8bea-61aeaf167d5a/IncomingWebhook/57e69e8f10dd49ce8dae3b816159e228/4eb361c9-e566-4b66-ab30-bed630f495a5" 38 | ports: 39 | - 8089:8089 40 | 41 | 42 | volumes: 43 | prometheus-data: 44 | 45 | grafana-data: 46 | 47 | alertmanager-data: 48 | -------------------------------------------------------------------------------- /grafana/provisioning/datasources/prometheus_ds.yml: -------------------------------------------------------------------------------- 1 | datasources: 2 | - name: Prometheus 3 | access: proxy 4 | type: prometheus 5 | url: http://prometheus:9090 6 | isDefault: true 7 | -------------------------------------------------------------------------------- /prometheus/alert.yml: -------------------------------------------------------------------------------- 1 | groups: 2 | - name: DemoAlerts 3 | rules: 4 | - alert: InstanceDown 5 | expr: up{job="services"} < 1 6 | for: 1m 7 | labels: 8 | severity: low 9 | annotations: 10 | summary: 'Alert with low severity.' 11 | 12 | - alert: InstanceDownCritical 13 | expr: up{job="services"} < 1 14 | for: 1m 15 | labels: 16 | severity: high 17 | annotations: 18 | summary: 'Alert with high severity.' 19 | -------------------------------------------------------------------------------- /prometheus/prometheus.yml: -------------------------------------------------------------------------------- 1 | global: 2 | scrape_interval: 30s 3 | scrape_timeout: 10s 4 | 5 | rule_files: 6 | - alert.yml 7 | 8 | alerting: 9 | alertmanagers: 10 | - scheme: http 11 | static_configs: 12 | - targets: [ 'alertmanager:9093' ] 13 | 14 | scrape_configs: 15 | - job_name: services 16 | metrics_path: /metrics 17 | static_configs: 18 | - targets: 19 | - 'prometheus:9090' 20 | - 'idonotexists:564' 21 | 22 | 23 | --------------------------------------------------------------------------------