zoukankan      html  css  js  c++  java
  • 利用Metrics+influxdb+grafana构建监控平台(转)

    转自http://www.jianshu.com/p/fadcf4d92b0e

    这里再配合InfluxdbGrafana可以构建一个非常漂亮的实时监控界面。


    Grafana监控界面

    采集数据(Metrics)-> 存储数据(InfluxDB) -> 显示数据(Grafana)。

    资源有限,我把这一套服务搭建在了一台CentOS 7的服务器上。

    安装influxdb

    InfluxDB是Go语言写的一个时序型数据库,可以通过rpm的方式来安装它,这里最好能安装InfluxDB的最新版本,否则跟Grafana的交互会有一些不兼容。

    wget https://dl.influxdata.com/influxdb/releases/influxdb-1.2.4.x86_64.rpm
    sudo yum localinstall influxdb-1.2.4.x86_64.rpm
     

    安装完成之后,启动并查看这个服务是否在正常运行:

    systemctl start influxdb.service
    [root@metrics ~]# systemctl status influxdb.service
    ● influxdb.service - InfluxDB is an open-source, distributed, time series database
       Loaded: loaded (/usr/lib/systemd/system/influxdb.service; enabled; vendor preset: disabled)
       Active: active (running) since 一 2016-04-25 17:50:04 CST; 1 day 1h ago
         Docs: https://docs.influxdata.com/influxdb/
     Main PID: 17871 (sh)
       CGroup: /system.slice/influxdb.service
               ├─17871 /bin/sh -c /usr/bin/influxd -config /etc/influxdb/influxdb.conf  >>/dev/nul...
               └─17872 /usr/bin/influxd -config /etc/influxdb/influxdb.conf
    
    4月 25 17:50:04 metrics systemd[1]: Started InfluxDB is an open-source, distributed...se.
    4月 25 17:50:04 metrics systemd[1]: Starting InfluxDB is an open-source, distribute......
    Hint: Some lines were ellipsized, use -l to show in full.

    启动后打开 web 管理界面 http://192.168.2.183:8083/ 默认用户名和密码是 root 和 root. InfluxDB 的 Web 管理界面端口是 8083,HTTP API 监听端口是 8086,如果需要更改这些默认设定,修改 InfluxDB 的配置文件(/etc/influxdb/influxdb.conf)并重启就可以了。

    安装 Grafana

    Grafana是一个非常好看的监控界面,它的安装方式也非常简单,通过yum,一条命令就可以在server上完成安装。

    wget https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana-4.3.2-1.x86_64.rpm 
    sudo yum localinstall grafana-4.3.2-1.x86_64.rpm 


    完成安装之后,启动并检查它的状态:

    [root@metrics ~]# systemctl start grafana-server.service
    [root@metrics ~]# systemctl status grafana-server.service
    ● grafana-server.service - Starts and stops a single grafana instance on this system
       Loaded: loaded (/usr/lib/systemd/system/grafana-server.service; disabled; vendor preset: disabled)
       Active: active (running) since 一 2016-04-25 09:37:07 CST; 1 day 10h ago
         Docs: http://docs.grafana.org
     Main PID: 10309 (grafana-server)
       CGroup: /system.slice/grafana-server.service
               └─10309 /usr/sbin/grafana-server --config=/etc/grafana/grafana.ini --pidfile= cfg:d...

    用浏览器访问 Grafana,默认端口是3000,默认的帐号密码都是 admin(可以在配置文件中找到),登录之后配置数据库


    设置数据源

    Metrics Reporter

    之前提到Metrics只需要配置它的Reporter就可以输出到对应的地方,对于Influxdb,在github上找到了一个InfluxdbReporter(https://github.com/davidB/metrics-influxdb)。

    Maven中引入:

    <dependency>
        <groupId>com.github.davidb</groupId>
        <artifactId>metrics-influxdb</artifactId>
        <version>0.8.2</version>
    </dependency>

    并在代码中配置Influxdb的数据源:

    @Bean(name = "influxdbReporter")
    public ScheduledReporter influxdbReporter(MetricRegistry metrics) throws Exception {
    
        return InfluxdbReporter.forRegistry(metrics)
                .protocol(InfluxdbProtocols.http("host_ip_address", port, "username", "password", "database"))
                .convertRatesTo(TimeUnit.SECONDS)
                .convertDurationsTo(TimeUnit.MILLISECONDS)
                .filter(MetricFilter.ALL)
                .skipIdleMetrics(false)
                .build();
    }

    启动项目之后,我们开始配置我们需要看到的图表信息:


    配置图标信息

    最后我们利用wrk测试工具并发访问连接:

    ➜  ~ wrk -t 10 -c 50 -d 5s http://127.0.0.1:8888/hello
    Running 5s test @ http://127.0.0.1:8888/hello
      10 threads and 50 connections
      Thread Stats   Avg      Stdev     Max   +/- Stdev
        Latency     6.59ms   12.17ms 210.05ms   92.16%
        Req/Sec     1.40k   427.51     2.79k    71.80%
      69902 requests in 5.04s, 10.28MB read
    Requests/sec:  13873.71
    Transfer/sec:      2.04MB

    于此同时Grafana界面上系统实时的数据信息也展现出来了:

  • 相关阅读:
    在线pdm查看
    vscode
    idea for Mac 代码提示设置
    定位功能
    canvas刮奖
    jquery生成二维码
    Redux DevTools浏览器插件调试redux
    .gitignore
    HBuilder在MAC下的SVN
    UMD编码规范
  • 原文地址:https://www.cnblogs.com/mrblue/p/7087619.html
Copyright © 2011-2022 走看看