springcloud集成prometheus(待完善)

1、准备

1.1 下载prometheus
1.2 下载grafana
1.3 项目地址:https://gitee.com/zhou1124/bat

启动三个项目

1.1 eureka-server
1.2 prometheus
1.3 eureka-client

3 prometheus配置

# my global config
global:
  scrape_interval:     15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
  evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
  # scrape_timeout is set to the global default (10s).

# Alertmanager configuration
alerting:
  alertmanagers:
  - static_configs:
    - targets:
      # - alertmanager:9093

# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
  # - "first_rules.yml"
  # - "second_rules.yml"

# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
  # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
  - job_name: 'prometheus'
  - job_name: 'node_exporter'
  - job_name: redis_exporter
    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.

    static_configs:
    - targets: ['localhost:9090']
    - targets: ['localhost:9100']
    - targets: ['localhost:9121']    
  - job_name: 'bat-eureka-server'
    scheme: http
    metrics_path: '/actuator/prometheus'
    consul_sd_configs:
    #consul 地址
      - server: '127.0.0.1:9091'
        scheme: http
        #注意名称大写 因为eureka名称大写
        services: [PROMETHEUS,EUREKACLIENT]

#####3.1 查看状态
image.png

###4、grafana添加仪表盘
image.png
仪表盘id: https://grafana.com/grafana/dashboards/10280

4.1 结果

image.png

Spring Cloud是一个用于构建分布式系统的开发工具包,而Prometheus是一个开源的监控和警报系统。它们可以结合使用,以实现对Spring Cloud应用程序的监控和指标收集。 在Spring Cloud中,你可以使用Spring Boot Actuator模块来暴露应用程序的运行时指标。这些指标包括HTTP请求的计数、错误率、内存使用情况等。Prometheus可以通过轮询这些指标的端点来收集数据,并将其存储在自己的时间序列数据库中。 要将Spring Cloud与Prometheus集成,你需要做以下几个步骤: 1. 添加Prometheus依赖:在你的Spring Boot项目中,添加Prometheus相关的依赖,如`micrometer-registry-prometheus`。 2. 配置Prometheus端点:在`application.properties`或`application.yml`文件中,配置Spring Boot Actuator的端点路径和Prometheus的路径。 3. 启用Prometheus收集器:通过添加`@EnablePrometheusEndpoint`注解,启用Prometheus收集器。 4. 配置Prometheus收集器:通过添加`@EnableSpringBootMetricsCollector`注解,配置Prometheus收集器的行为。 5. 启动Prometheus服务器:在你的环境中启动Prometheus服务器,并配置它来定期抓取Spring Cloud应用程序的指标。 一旦配置完成,Prometheus就可以定期从你的Spring Cloud应用程序中收集指标,并将其存储在自己的数据库中。你可以使用Prometheus的查询语言(PromQL)来查询和分析这些指标,并创建自定义的监控仪表盘和警报规则。 希望这些信息能对你有所帮助!如果还有其他问题,请随时提问。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值