Prometheus+Grafana实现服务监控

Prometheus+Grafana实现服务监控

项目引入依赖:

implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'io.micrometer:micrometer-registry-prometheus'

yml暴露端点:

management:
  endpoints:
    web:
      exposure:
        include: '*'		#暴露所有

启动项目访问http://localhost:PORT/actuator/prometheus

在这里插入图片描述

整合Prometheus

使用docker安装:

  1. 检查docker是否运行(systemctl status docker)

在这里插入图片描述

  1. 安装运行Prometheus

官网地址:https://prometheus.io/docs/prometheus/latest/getting_started/

  • 在/home/admin/prometheus目录下建一个prometheus.yml

    global:
      scrape_interval:     15s # By default, scrape targets every 15 seconds.
    
      # Attach these labels to any time series or alerts when communicating with
      # external systems (federation, remote storage, Alertmanager).
      external_labels:
        monitor: 'codelab-monitor'
    
    # 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'
    
        # Override the global default and scrape targets from this job every 5 seconds.
        scrape_interval: 5s
    
        static_configs:
          - targets: ['localhost:9090']
    
  • 运行下面语句进行安装运行

docker run  -p 9090:9090 -v /home/admin/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml prom/prometheus
  • 访问 http://虚拟机IP:9090/
    在这里插入图片描述

  • 整合项目

    修改prometheus.yml

global:
  scrape_interval:     15s # By default, scrape targets every 15 seconds.
  external_labels:
    monitor: 'codelab-monitor'
scrape_configs:
  - job_name: 'prometheus'
    scrape_interval: 5s
    static_configs:
      - targets: ['localhost:9090']
  - job_name: 'abs-gateway'		#名称,任意不重复
    metrics_path: '/actuator/prometheus'	#制定获取路径
    scrape_interval: 5s	#间隔
    static_configs:
      - targets: ['192.168.0.105:8000']	#实例的IP,默认协议是http

​ 重新启动容器:
在这里插入图片描述

​ 重新访问 http://虚拟机IP:9090/

在这里插入图片描述

整合Grafana

docker运行安装Grafana

docker run -d --name=grafana-3000 -p 3000:3000 grafana/grafana

访问 http://虚拟机IP:3000/

image-20210105101437439

默认账号密码都是admin,登陆后会让你重新输入密码,可选择跳过。

image-20210105101624450

在这里插入图片描述

选择Prometheus数据源

在这里插入图片描述

在这里插入图片描述

然后点击保存并测试。

创建一个panel

在这里插入图片描述

选择你刚刚配置的prometheus数据源:
在这里插入图片描述

然后选择你要查询的内容
在这里插入图片描述

至此整合完成。docker安装下次更新。。。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值