├── Dockerfile ├── README.md └── conf ├── alert.rules └── prometheus.yml /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM alpine 2 | 3 | LABEL maintainer="jeferson@linuxtips.com.br" 4 | LABEL version="1.0" 5 | 6 | ENV prometheus_version 2.8.1 7 | 8 | RUN adduser -s /bin/false -D -H prometheus \ 9 | && adduser -s /bin/false -D -H node_exporter \ 10 | && apk update \ 11 | && apk --no-cache add curl \ 12 | && curl -LO https://github.com/prometheus/prometheus/releases/download/v${prometheus_version}/prometheus-${prometheus_version}.linux-amd64.tar.gz \ 13 | && tar -xvzf prometheus-${prometheus_version}.linux-amd64.tar.gz \ 14 | && mkdir -p /etc/prometheus /var/lib/prometheus \ 15 | && cp prometheus-${prometheus_version}.linux-amd64/promtool /usr/local/bin/ \ 16 | && cp prometheus-${prometheus_version}.linux-amd64/prometheus /usr/local/bin/ \ 17 | && cp -R prometheus-${prometheus_version}.linux-amd64/console_libraries/ /etc/prometheus/ \ 18 | && cp -R prometheus-${prometheus_version}.linux-amd64/consoles/ /etc/prometheus/ \ 19 | && rm -rf prometheus-${prometheus_version}.linux-amd64* \ 20 | && chown prometheus:prometheus /usr/local/bin/prometheus \ 21 | && chown prometheus:prometheus /usr/local/bin/promtool \ 22 | && chown -R prometheus:prometheus /etc/prometheus \ 23 | && chown prometheus:prometheus /var/lib/prometheus \ 24 | && apk del curl 25 | 26 | VOLUME /etc/prometheus 27 | 28 | VOLUME /var/lib/prometheus 29 | 30 | ADD conf/prometheus.yml /etc/prometheus/ 31 | ADD conf/alert.rules /etc/prometheus/ 32 | 33 | ENTRYPOINT /usr/local/bin/prometheus \ 34 | --config.file /etc/prometheus/prometheus.yml \ 35 | --storage.tsdb.path /var/lib/prometheus/ \ 36 | --web.console.libraries=/usr/share/prometheus/console_libraries \ 37 | --web.console.templates=/usr/share/prometheus/consoles 38 | 39 | EXPOSE 9090 40 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Prometheus on Alpine 2 | 3 | ## To run this image, execute: 4 | ``` 5 | # docker container run -d --name prometheus -p 9090:9090 linuxtips/prometheus_alpine 6 | ``` 7 | 8 | Open http://your_ip:9090 to access the interface of Prometheus. 9 | 10 | ## To view the logs, execute: 11 | ``` 12 | # docker container logs -f 13 | ``` 14 | 15 | ## To create a swarm service, execute: 16 | ``` 17 | # docker service create --name prometheus -p 9090:9090 linuxtips/prometheus_alpine 18 | ``` 19 | -------------------------------------------------------------------------------- /conf/alert.rules: -------------------------------------------------------------------------------- 1 | groups: 2 | - name: example 3 | rules: 4 | 5 | # Alert for any instance that is unreachable for >5 minutes. 6 | - alert: service_down 7 | expr: up == 0 8 | for: 2m 9 | labels: 10 | severity: page 11 | annotations: 12 | summary: "Instance {{ $labels.instance }} down" 13 | description: "{{ $labels.instance }} of job {{ $labels.job }} has been down for more than 2 minutes." 14 | 15 | - alert: high_load 16 | expr: node_load1 > 0.5 17 | for: 2m 18 | labels: 19 | severity: page 20 | annotations: 21 | summary: "Instance {{ $labels.instance }} under high load" 22 | description: "{{ $labels.instance }} of job {{ $labels.job }} is under high load." -------------------------------------------------------------------------------- /conf/prometheus.yml: -------------------------------------------------------------------------------- 1 | global: 2 | scrape_interval: 10s 3 | evaluation_interval: 10s 4 | rule_files: 5 | - 'alert.rules' 6 | 7 | consul_sd_configs: 8 | - server: 'localhost:8500' 9 | scheme: https 10 | 11 | scrape_configs: 12 | - job_name: 'prometheus' 13 | scrape_interval: 5s 14 | static_configs: 15 | - targets: ['localhost:9090'] 16 | --------------------------------------------------------------------------------