美文网首页
使用Prometheus+Grafana搭建监控系统

使用Prometheus+Grafana搭建监控系统

作者: 一个神奇的女码农 | 来源:发表于2019-07-18 16:57 被阅读0次

基于spring boot 基础上搭建
1.先添加 pom 依赖

        <dependency>
            <groupId>io.prometheus</groupId>
            <artifactId>simpleclient_spring_boot</artifactId>
            <version>0.1.0</version>
        </dependency>

启动类添加注解

@EnablePrometheusEndpoint
@EnableSpringBootMetricsCollector

配置文件添加

# 默认账号密码
managment.security.enabled=false
spring.application.name=microservice-prometheus

2.安装prometheus
本文中安装的为Windows 版本,如需Linux,下载链接:https://prometheus.io/download/
下载直接解压即可
修改配置文件prometheus.yml

global:
  scrape_interval: 10s
  scrape_timeout: 10s
  evaluation_interval: 10m
scrape_configs:
  - job_name: spring-boot
    scrape_interval: 5s
    scrape_timeout: 5s
    metrics_path: /prometheus 
    scheme: http
    basic_auth:
      username: user
      password: pwd
    static_configs:
      - targets:
        - 127.0.0.1:9393 #此处填写 Spring Boot 应用的 IP + 端口号

启动 prometheus.exe 即可
启动成功后 打开http://localhost:9090/targets
即可看见:

1563437867(1).jpg
3.安装grafana
同上都是使用Windows版本,下载 戳:https://grafana.com/grafana/download?platform=windows
安装就不多说了,双击,选安装地址即可
启动grafana:
进入D:\grafana\grafana\bin目录下双击 grafana-server.exe

启动后访问:http://127.0.0.1:3000/

配置数据源:

选择type为Prometheus的数据源,名称为springboot 2.png
3.png

添加一个dashboard,配置单个指标的可视化监控面板:

4.png
填写指标点:
6.png
提示,此处填写需要监控的指标不能任意填写,只能填已有的指标点,具体的可以监控的指标在 Prometheus 的首页看到,即 http://localhost:9090/graph
7.png

或在explore 上找到:


5.jpg

多配置几个指标之后,即可有如下效果:


8.jpg

到这里大概配置就结束可以使用了

相关文章

网友评论

      本文标题:使用Prometheus+Grafana搭建监控系统

      本文链接:https://www.haomeiwen.com/subject/angllctx.html