본문 바로가기
ops/kubernetes

워커노드의 disk-usage에 따라 alert발생 시키기 - 3(alert 설정)

by seohan1010 2026. 1. 12.

디스크 사용량이 75%이상일때로 수정하여 진행 (node_exporter의 pod eviction을 방지)


#local machine에 알림을 보내는 명령어를 실행할 서버 프로그램 설정 

#alertmanager의 webhook을 처리할 로직 
from flask import Flask, request
import subprocess

app = Flask(__name__)

@app.route("/alert", methods=["GET"])
def alert():
    node = request.args.get("node")
    usage = request.args.get("usage")

    title = "🚨 Prometheus Disk Alert"
    message = f"Node: {node}\nDisk Usage: {usage}%"

    subprocess.run([
        "notify-send",
        "-u", "critical",
        "-i", "dialog-error",
        title,
        message
    ])

    return "ok", 200

if __name__ == "__main__":
    app.run(host="0.0.0.0", port=5000)


실행 및 테스트 

#서버 실행
python alert.py

* Serving Flask app 'alert'
 * Debug mode: off
WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
 * Running on all addresses (0.0.0.0)
 * Running on http://127.0.0.1:5000
 * Running on http://192.168.151.161:5000
Press CTRL+C to quit

#서버로 요청 전송 
curl http://localhost:5000/alert?node=test-node&usage=75

 


alert 노출