惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Hacker News - Newest:
Hacker News - Newest: "LLM"
S
Security Affairs
PCI Perspectives
PCI Perspectives
Google Online Security Blog
Google Online Security Blog
W
WeLiveSecurity
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Recent Commits to openclaw:main
Recent Commits to openclaw:main
P
Privacy & Cybersecurity Law Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
S
Security @ Cisco Blogs
Security Archives - TechRepublic
Security Archives - TechRepublic
Cyberwarzone
Cyberwarzone
L
Lohrmann on Cybersecurity
TaoSecurity Blog
TaoSecurity Blog
V
Visual Studio Blog
博客园 - 聂微东
Scott Helme
Scott Helme
博客园 - 【当耐特】
K
Kaspersky official blog
Security Latest
Security Latest
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
MyScale Blog
MyScale Blog
Schneier on Security
Schneier on Security
WordPress大学
WordPress大学
博客园 - 叶小钗
C
Check Point Blog
V2EX - 技术
V2EX - 技术
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - Franky
T
Tor Project blog
Apple Machine Learning Research
Apple Machine Learning Research
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
腾讯CDC
雷峰网
雷峰网
博客园_首页
美团技术团队
Y
Y Combinator Blog
C
CERT Recently Published Vulnerability Notes
AWS News Blog
AWS News Blog
月光博客
月光博客
N
Netflix TechBlog - Medium
Last Week in AI
Last Week in AI
Recent Announcements
Recent Announcements
Google DeepMind News
Google DeepMind News
Help Net Security
Help Net Security
P
Proofpoint News Feed
MongoDB | Blog
MongoDB | Blog
C
Cybersecurity and Infrastructure Security Agency CISA

博客园 - py哥

rabbitmq集群docker部署 MongoDB副本集docker部署 MySQL8.0单实例部署 Redis管理平台 k8s网络与本地开发环境网络互通方案 CentOS7 FTP结合ssl/tls实现加密通信安装与配置 数据库运维平台 基于Docker构建Jenkins CI平台 KeepLived + nginx 高可用 k8s-1.16 二进制安装 Ansible自动化部署K8S集群 Kubernetes1.16下部署Prometheus+node-exporter+Grafana+AlertManager 监控系统 在Kubernetes下部署Prometheus docker部署coredns kubeadm部署多master节点高可用k8s1.16.2 二进制搭建一个完整的K8S集群部署文档 kubeadm部署k8s集群 Keepalived+LVS+nginx搭建nginx高可用集群 centos7 dns(bind)安装配置
prometheus 监控 eureka 里面的服务状态
py哥 · 2025-03-10 · via 博客园 - py哥

1.用python写个eureka_exporter.py

pip install flask requests prometheus_client
from flask import Flask, Response
import requests
from prometheus_client import Gauge, generate_latest, REGISTRY
import prometheus_client
from prometheus_client import Counter, Gauge, generate_latest
from prometheus_client.core import CollectorRegistry

app = Flask(__name__)



# 设置 metrics
registry = CollectorRegistry(auto_describe=False)
downgrade = Gauge('eureka', 'eureka', ['instanceId','hostName', 'app', 'status', 'port'], registry=registry)

@app.route("/metrics")
def metrics():
    downgrade.clear()
    # 假设 Eureka 地址为 http://localhost:8761/eureka/apps/
    eureka_url = "http://10.20.11.138:9500/eureka/apps/"

    up_count = 0

    try:
        response = requests.get(eureka_url,headers = {"Content-Type": "application/json", "Accept": "application/json"})

        if response.status_code == 200:
            apps = response.json()['applications']['application']

            # 遍历所有应用并设置其状态
            for app in apps:
                app_name = app['name']
                for instance in app['instance']:
                    status = instance['status']
                    # print(instance)
                    if status == 'UP':
                        downgrade.labels(instanceId=instance['instanceId'], hostName=instance['hostName'], app=app_name, status=status, port=instance['port']['$']).set(1)
                    else:
                        downgrade.labels(instanceId=instance['instanceId'], hostName=instance['hostName'], app=app_name, status=status, port=instance['port']['$']).set(0)




        else:
            print(f"Failed to fetch data from Eureka. Status code: {response.status_code}")
    except Exception as e:
        print(f"Error fetching data from Eureka: {e}")

    metrics_page = prometheus_client.generate_latest(registry)
    return Response(metrics_page, mimetype=prometheus_client.CONTENT_TYPE_LATEST)


if __name__ == '__main__':
    app.run(host='0.0.0.0', port=8000)

2.配置Prometheus:
修改prometheus.yml文件,添加针对Eureka Server的scrape_configs。这里需要指定job_name、scrape_interval、metrics_path以及targets等参数。例如,如果你的Eureka Server运行在10.124.129.42:8000,并且暴露了/metrics端点用于指标收集,那么你的配置可能如下所示:

- job_name: 'eureka_exporter'
  scrape_interval: 10s
  metrics_path: '/metrics'
  static_configs:
    - targets: ['10.124.129.42:8000']

3.告警配置

- name: Eureka_Rules
  rules:

  # Eureka里面的 服务down告警
  - alert: EurekaDown
    expr: eureka==0
    for: 5s  
    labels:
      severity: critical
    annotations:
      summary: "{{ $labels.app }} instance down on {{ $labels.hostName }}"
      description: "{{ $labels.app }} instance {{ $labels.hostName }} has been down for more than 1 minute."
  - alert: 服务数量小于2
    expr: count by (app) (eureka{job="eureka_exporter"}) < 2
    for: 5s  
    labels:
      severity: critical
    annotations:
      summary: "{{ $labels.app }} 数量小于2"
      description: "{{ $labels.app }} 数量小于2 "