zoukankan      html  css  js  c++  java
  • 监控平台

    Spring Boot Actutaur + Telegraf + InFluxDB + Grafana

    完成一套精准,漂亮图形化监控系统从这里开始第一步

    Telegraf是收集和报告指标和数据的代理

      它是TICK堆栈的一部分,是一个用于收集报告指标的插件驱动的服务器代理。Telegraf拥有插件或集成功能,可直接从运行的系统获取各种指标,从第三方API获取指标,甚至通过StatsD和Kafka消费者服务来收听指标。它还具有输出插件,可将指标发送到各种其他数据存储服务消息队列,包括InfluxDB,Graphite,OpenTSDB,Datadog,Librato,Kafka,MQTT,NSQ等等。

    Spring Boot Actuator

      Spring Boot Actuator包含一个带“metrics”和“gauge”支持的度量服务。“量表”记录单个值; '计数器'记录增量(增量或减量)。Spring Boot Actuator还提供了一个PublicMetrics可以实现的 界面,用于公开您无法通过这两种机制之一记录的指标。看SystemPublicMetrics 一个例子。

      将你的springboot项目中依赖Spring Boot Actuator 的包,启动之后会发现控制台打出的mapped变得很多了,例如/env、/health、/info等等的信息,恭喜你已经成功使用了metric对程序进行了简单的监控了,在浏览器中输入本地的ip项目访问地址如:http://localhost:8080/metrics,就会出现如下的数据

      

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    {
        "counter.status.200.root": 20,
        "counter.status.200.metrics": 3,
        "counter.status.200.star-star": 5,
        "counter.status.401.root": 4,
        "gauge.response.star-star": 6,
        "gauge.response.root": 2,
        "gauge.response.metrics": 3,
        "classes": 5808,
        "classes.loaded": 5808,
        "classes.unloaded": 0,
        "heap": 3728384,
        "heap.committed": 986624,
        "heap.init": 262144,
        "heap.used": 52765,
        "nonheap": 0,
        "nonheap.committed": 77568,
        "nonheap.init": 2496,
        "nonheap.used": 75826,
        "mem": 986624,
        "mem.free": 933858,
        "processors": 8,
        "threads": 15,
        "threads.daemon": 11,
        "threads.peak": 15,
        "threads.totalStarted": 42,
        "uptime": 494836,
        "instance.uptime": 489782,
        "datasource.primary.active": 5,
        "datasource.primary.usage": 0.25
    }

    管理员功能

      通过指定spring.application.admin.enabled属性可以为应用程序启用与管理相关的功能 。这暴露 SpringApplicationAdminMXBean 了平台上MBeanServer。您可以使用此功能远程管理您的Spring Boot应用程序。这对于任何服务包装器实现也是有用的。

    复制代码
    引入spring-boot-admin依赖  
    <dependency>  
        <groupId>de.codecentric</groupId>  
        <artifactId>spring-boot-admin-server</artifactId>  
        <version>1.4.0</version>  
    </dependency>  
      
    <dependency>  
        <groupId>de.codecentric</groupId>  
        <artifactId>spring-boot-admin-server-ui</artifactId>  
        <version>1.4.0</version>  
    </dependency>  
    复制代码

      如果您想知道应用程序在哪个HTTP端口上运行,请使用密钥获取该属性local.server.port

      当启用此功能时要小心,因为MBean公开了关闭应用程序的方法。

    使用Jolokia进行JMX over HTTP

      Jolokia是一个JMX-HTTP桥梁,它提供了访问JMX bean的另一种方法。要使用Jolokia,只需添加依赖项即可org.jolokia:jolokia-core。例如,使用Maven你可以添加以下内容:

       

    <dependency> 
        <groupId> org.jolokia </ groupId> 
        <artifactId> jolokia-core </ artifactId> 
     </ dependency>

      在application.yaml后者application.properties中配置响应的配置

    jolokia.config.debug=true  
    endpoints.jolokia.enabled=true  
    #endpoints.jolokia.sensitive=true  
    endpoints.jolokia.path=/jolokia 

    环境搭建

    下载Telegraf、influxdb 、grafana,我个人建议先搭建一个windows版本的环境自己配置玩一玩

    https://portal.influxdata.com/downloads#influxdb
    https://grafana.com/grafana/download?platform=windows

    1 Influxdb配置

          修改influxdb.conf,设置日志文件目录:

    复制代码
    #cd 到安装解压的修改influxdb.conf

    [admin]
    # Determines whether the admin service is enabled.
    enabled = true

    # The default bind address used by the admin service.
    bind-address = ":8083"

    复制代码

    其他配置都是默认好的,不用修改,如果版本下载不一样可能需要修改,不妨给我留言,我会及时回复的

    2启动

      通过cmd命令窗口,切换到influxdb安装目录,执行如下命令:

         influxd -config influxdb.conf

     通过cmd命令窗口,切换到Telegraf安装目录,执行如下命令:

        telegraf -config telegraf.conf

        切换到Grafana安装目录中的bin目录下,双击grafana-server.exe启动程序

    访问http://locahost:8090,这是可以配置的端口号,可以访问了:

    使用:

    访问http://localhost:8086,使用admin/admin登录本机Grafana,新建influxdb数据源:

    【注意】Telegraf启动后,向InfluxDb中上报数据时,会默认创建一个telegraf数据库,所以上面我们配置DataBase是telegraf

    点击new创建一个Dashboards

    配置编辑会出来可配置页面:

    点击General:配置基本的图表信息

    点击metrics,配置收集到的收据信息,实际就是写sql查询,不同数据库数据sql书写方式不同

    查看http://localhost:8083,可以发现telegraf库中,默认有4个Measurements(表):

     

    配置Grafana中的面板完成后,这样一个简易的本机监控系统就搭建完了:

     

  • 相关阅读:
    php安装xcache (5.4)
    nginx博客系统(内含nginx图片缩略图处理代码,不错)
    一个mysql开启多个端口
    mysql源码重启
    ecshop支付时减库存方法
    n阶幻方问题
    codeforces 710A King Moves(水)
    关于ios::sync_with_stdio(false);和 cin.tie(0)加速c++输入输出流
    codeforces 701C. They Are Everywhere(尺取法)
    codeforces 701 B. Cells Not Under Attack
  • 原文地址:https://www.cnblogs.com/Leo_wl/p/8574540.html
Copyright © 2011-2022 走看看