初始化prometheus全套配置
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
#!/usr/bin/env python3
|
||||
from flask import Flask, request
|
||||
import json
|
||||
import time
|
||||
import requests
|
||||
|
||||
app = Flask(__name__)
|
||||
LOKI_PUSH = "http://127.0.0.1:3100/loki/api/v1/push"
|
||||
|
||||
@app.route("/alert-relay", methods=["POST"])
|
||||
def handle_alert():
|
||||
# 接收Alertmanager告警
|
||||
am_raw = request.get_json()
|
||||
# 转Loki标准推送格式
|
||||
payload = {
|
||||
"streams": [
|
||||
{
|
||||
"stream": {"job": "alertmanager"},
|
||||
"values": [
|
||||
# 纳秒级时间戳 + 告警完整json字符串
|
||||
[str(int(time.time() * 1000000000)), json.dumps(am_raw)]
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
# 推送到Loki
|
||||
requests.post(LOKI_PUSH, json=payload)
|
||||
return "success", 200
|
||||
|
||||
if __name__ == "__main__":
|
||||
# 仅本地127.0.0.1监听9080,外部无法访问
|
||||
app.run(host="127.0.0.1", port=9081, debug=False)
|
||||
@@ -0,0 +1,23 @@
|
||||
services:
|
||||
loki:
|
||||
image: grafana/loki:2.9.9
|
||||
container_name: loki
|
||||
network_mode: host
|
||||
volumes:
|
||||
- loki-data:/loki
|
||||
command: -config.file=/etc/loki/local-config.yaml
|
||||
restart: always
|
||||
|
||||
promtail:
|
||||
image: grafana/promtail:2.9.0
|
||||
container_name: promtail
|
||||
network_mode: host
|
||||
volumes:
|
||||
- ./promtail.yml:/etc/promtail/promtail.yml:ro
|
||||
- promtail-pos:/var/lib/promtail
|
||||
command: -config.file=/etc/promtail/promtail.yml
|
||||
restart: always
|
||||
|
||||
volumes:
|
||||
loki-data:
|
||||
promtail-pos:
|
||||
@@ -0,0 +1,53 @@
|
||||
auth_enabled: false
|
||||
|
||||
server:
|
||||
http_listen_port: 3100
|
||||
grpc_listen_port: 9096
|
||||
|
||||
ingester:
|
||||
wal:
|
||||
enabled: true
|
||||
dir: /loki/wal
|
||||
lifecycler:
|
||||
address: 10.150.117.190
|
||||
ring:
|
||||
kvstore:
|
||||
store: inmemory
|
||||
replication_factor: 1
|
||||
final_sleep: 0s
|
||||
chunk_idle_period: 1h
|
||||
max_chunk_age: 1h
|
||||
chunk_target_size: 1048576
|
||||
chunk_retain_period: 30s
|
||||
max_transfer_retries: 0
|
||||
|
||||
schema_config:
|
||||
configs:
|
||||
- from: 2020-10-24
|
||||
store: boltdb-shipper
|
||||
object_store: filesystem
|
||||
schema: v11
|
||||
index:
|
||||
prefix: index_
|
||||
period: 24h
|
||||
|
||||
storage_config:
|
||||
boltdb_shipper:
|
||||
active_index_directory: /loki/boltdb-shipper-active
|
||||
cache_location: /loki/boltdb-shipper-cache
|
||||
cache_ttl: 24h
|
||||
shared_store: filesystem
|
||||
filesystem:
|
||||
directory: /loki/chunks
|
||||
|
||||
limits_config:
|
||||
enforce_metric_name: false
|
||||
reject_old_samples: true
|
||||
reject_old_samples_max_age: 168h
|
||||
|
||||
chunk_store_config:
|
||||
max_look_back_period: 0s
|
||||
|
||||
table_manager:
|
||||
retention_deletes_enabled: false
|
||||
retention_period: 0s
|
||||
@@ -0,0 +1,12 @@
|
||||
server:
|
||||
http_listen_port: 9080
|
||||
grpc_listen_port: 0
|
||||
|
||||
positions:
|
||||
filename: /var/lib/promtail/positions.yaml
|
||||
|
||||
clients:
|
||||
- url: http://10.150.117.190:3100/loki/api/v1/push
|
||||
|
||||
# 我们不用采集日志文件,scrape_configs留空即可
|
||||
scrape_configs: []
|
||||
@@ -0,0 +1,7 @@
|
||||
nohup: ignoring input
|
||||
* Serving Flask app "alert-relay" (lazy loading)
|
||||
* Environment: production
|
||||
WARNING: This is a development server. Do not use it in a production deployment.
|
||||
Use a production WSGI server instead.
|
||||
* Debug mode: off
|
||||
* Running on http://127.0.0.1:9081/ (Press CTRL+C to quit)
|
||||
Reference in New Issue
Block a user