-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Andreyev Dias de Melo
committed
Feb 9, 2024
0 parents
commit c5bd7c7
Showing
8 changed files
with
274 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# prometheus_hands-on | ||
Just a simple repository with the aim of demonstrating the concepts of Prometheus. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
route: | ||
receiver: 'default' | ||
routes: | ||
- match: | ||
alertname: healthchecks watchdog | ||
receiver: healthchecks.io | ||
group_wait: 0s | ||
group_interval: 1m | ||
repeat_interval: 6m | ||
|
||
receivers: | ||
- name: 'default' | ||
- name: healthchecks.io | ||
webhook_configs: | ||
- url: https://hc-ping.com/840c3490-a705-4f23-801b-43462657752e |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#Example | ||
#https://github.com/prometheus/blackbox_exporter/blob/master/example.yml | ||
modules: | ||
http_2xx: | ||
prober: http | ||
timeout: 10s | ||
http: | ||
valid_http_versions: ["HTTP/1.1", "HTTP/2"] | ||
valid_status_codes: [200] | ||
method: GET | ||
no_follow_redirects: false | ||
fail_if_ssl: false | ||
preferred_ip_protocol: "ip4" | ||
ip_protocol_fallback: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
FROM python:3 | ||
|
||
WORKDIR /usr/src/app | ||
|
||
COPY demo.py . | ||
|
||
RUN pip install prometheus_client | ||
|
||
EXPOSE 8001 | ||
EXPOSE 8002 | ||
|
||
CMD [ "python", "./demo.py" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#!/usr/bin/env python | ||
# coding:utf-8 | ||
'''Exemplo de instrumentação do Prometheus.''' | ||
|
||
import http.server | ||
import random | ||
import time | ||
from prometheus_client import start_http_server | ||
from prometheus_client import Counter | ||
from prometheus_client import Gauge | ||
|
||
SUM = Counter('demo_sum', 'Sum Demo requests duration.') | ||
REQUESTS = Counter('demo_count', 'Count Demo requests.') | ||
EXCEPTIONS = Counter('demo_exceptions_count', 'Exceptions serving Demo.') | ||
LAST = Gauge('demo_last_time_seconds', 'The last time a Demo was served.') | ||
|
||
class MyHandler(http.server.BaseHTTPRequestHandler): | ||
'''Classe de exemplo.''' | ||
|
||
def do_GET(self): | ||
'''Função com todos os exemplos propostos.''' | ||
rand = random.randrange(10) | ||
time.sleep(rand) | ||
SUM.inc(rand) | ||
REQUESTS.inc() | ||
with EXCEPTIONS.count_exceptions(): | ||
if random.random() < 0.2: | ||
raise Exception | ||
self.send_response(200) | ||
self.end_headers() | ||
self.wfile.write(bytes("Hello World (after %ss)" % rand, "utf-8")) | ||
LAST.set_to_current_time() | ||
|
||
if __name__ == "__main__": | ||
start_http_server(8001) | ||
SERVER = http.server.HTTPServer(('', 8002), MyHandler) | ||
SERVER.serve_forever() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
version: '3.7' | ||
|
||
volumes: | ||
alertmanager: | ||
grafana: | ||
prometheus: | ||
|
||
networks: | ||
back-tier: | ||
driver: bridge | ||
|
||
services: | ||
prometheus: | ||
image: prom/prometheus | ||
container_name: prometheus | ||
volumes: | ||
- ./prometheus/:/etc/prometheus/ | ||
command: | ||
- '--storage.tsdb.path=/prometheus' | ||
- '--config.file=/etc/prometheus/prometheus.yml' | ||
ports: | ||
- 9090:9090 | ||
networks: | ||
- back-tier | ||
|
||
node-exporter: | ||
container_name: node-exporter | ||
image: prom/node-exporter | ||
depends_on: | ||
- prometheus | ||
volumes: | ||
- /proc:/host/proc | ||
- /sys:/host/sysfs | ||
command: | ||
- '--path.procfs=/host/proc' | ||
- '--path.sysfs=/host/sysfs' | ||
- '--collector.filesystem.ignored-mount-points="^/(sys|proc|dev|host|etc)($$|/)"' | ||
ports: | ||
- 9100:9100 | ||
networks: | ||
- back-tier | ||
|
||
alertmanager: | ||
container_name: alertmanager | ||
image: prom/alertmanager | ||
volumes: | ||
- ./alertmanager/config.yml:/etc/alertmanager/config.yml | ||
depends_on: | ||
- prometheus | ||
- node-exporter | ||
command: | ||
- '--config.file=/etc/alertmanager/config.yml' | ||
- '--storage.path=/alertmanager' | ||
ports: | ||
- 9093:9093 | ||
networks: | ||
- back-tier | ||
|
||
pushgateway: | ||
container_name: pushgateway | ||
image: prom/pushgateway | ||
depends_on: | ||
- prometheus | ||
- node-exporter | ||
- alertmanager | ||
ports: | ||
- 9091:9091 | ||
networks: | ||
- back-tier | ||
|
||
blackbox: | ||
container_name: blackbox | ||
image: prom/blackbox-exporter | ||
volumes: | ||
- ./blackbox:/config | ||
command: | ||
- '--config.file=/config/blackbox.yml' | ||
depends_on: | ||
- prometheus | ||
- node-exporter | ||
- alertmanager | ||
- pushgateway | ||
ports: | ||
- 9115:9115 | ||
networks: | ||
- back-tier | ||
|
||
demo: | ||
container_name: demo | ||
build: ./demo/ | ||
links: | ||
- prometheus:prometheus | ||
depends_on: | ||
- prometheus | ||
- node-exporter | ||
- alertmanager | ||
- pushgateway | ||
- blackbox | ||
ports: | ||
- 8001:8001 | ||
- 8002:8002 | ||
networks: | ||
- back-tier |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
groups: | ||
- name: prometheus | ||
rules: | ||
- alert: InstanceIsDown | ||
expr: up == 0 | ||
for: 1m | ||
labels: | ||
severity: critical | ||
annotations: | ||
summary: "Instance {{ $labels.instance }} down" | ||
description: "Instance {{ $labels.job }} is unavailable." | ||
- alert: "HttpStatusCode" | ||
expr: probe_http_status_code <= 199 OR probe_http_status_code >= 400 | ||
for: 5s | ||
labels: | ||
severity: critical | ||
annotations: | ||
summary: "HTTP Status Code (instance {{ $labels.instance }})" | ||
description: "HTTP status code is not 200-399\n VALUE = {{ $value }}\n LABELS: {{ $labels }}" | ||
- alert: "SiteIsDown" | ||
expr: probe_http_status_code != 200 | ||
for: 5s | ||
labels: | ||
severity: high | ||
annotations: | ||
summary: "Site {{ $labels.instance }} down" | ||
description: "Site {{ $labels.job }} is unavailable." | ||
- alert: "TooManyHttpStatusCode" | ||
expr: count(probe_http_status_code <= 199 or probe_http_status_code >= 400) > 5 | ||
for: 5s | ||
labels: | ||
severity: critical | ||
annotations: | ||
summary: "Too Many HTTP Status Code (instance {{ $labels.instance }})" | ||
description: "Too Many HTTP status code is not 200-399\n VALUE = {{ $value }}\n LABELS: {{ $labels }}" | ||
|
||
- alert: healthchecks watchdog | ||
expr: vector(1) | ||
for: 1m | ||
labels: | ||
severity: none | ||
annotations: | ||
summary: "Prometheus dead men switch" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
global: | ||
scrape_interval: 5s # By default, scrape targets every 15 seconds. | ||
evaluation_interval: 10s # By default, scrape targets every 15 seconds. | ||
|
||
rule_files: | ||
- 'alert.conf' | ||
|
||
alerting: | ||
alertmanagers: | ||
- static_configs: | ||
- targets: | ||
- alertmanager:9093 | ||
|
||
scrape_configs: | ||
- job_name: 'prometheus' | ||
static_configs: | ||
- targets: [ 'prometheus:9090'] | ||
|
||
- job_name: 'node-exporter' | ||
static_configs: | ||
- targets: [ 'node-exporter:9100'] | ||
|
||
- job_name: 'pushgateway' | ||
static_configs: | ||
- targets: [ 'pushgateway:9091'] | ||
|
||
- job_name: 'alertmanager' | ||
static_configs: | ||
- targets: [ 'alertmanager:9093'] | ||
|
||
- job_name: 'demo' | ||
static_configs: | ||
- targets: [ 'demo:8001'] | ||
|
||
- job_name: 'blackbox_http_2xx' | ||
metrics_path: /probe | ||
params: | ||
module: [http_2xx] | ||
static_configs: | ||
- targets: | ||
- https://www.google.com | ||
relabel_configs: | ||
- source_labels: [__address__] | ||
target_label: __param_target | ||
- source_labels: [__param_target] | ||
target_label: instance | ||
- target_label: __address__ | ||
replacement: blackbox:9115 |