Grafana+InfluxDB+Collectd构建监控系统

架构原理

Contents

Collectd(数据采集,配置Server连接InfluxDB的25826端口) -> InfluxDB(数据存储,启用collectd插件监听25826端口) —> Grafana(数据展示)

  • Collectd : C 语言开发的一个守护(daemon)进程,周期性收集统计数据和存储,拥有丰富的插件包括监控Ceph,DRBD,OpenLDAP,ZK等,类似statD(graphite也可以用来采集数据,不过展示功能没有Grafana丰富),数据可以存储在Kafka,InfluxDB,OpenTSDB等上
  • InfluxDB: GO开发的开源分布式时序数据库,适合存储指标,时间,分析等数据
  • Grafana: 是一个开源的,具有丰富指标仪表盘的数据展示和图表编辑工具,支持Graphite,Elasticsearch,OpenTSDB,Prometheus和influxDB,Zabbix等

Collectd

  1. 安装collectd
yum -y  installperl-ExtUtils-Embedperl-ExtUtils-MakeMaker  liboping* 
wgethttps://collectd.org/files/collectd-5.5.0.tar.gz
tarxfcollectd-5.5.0.tar.gz
cdcollectd-5.5.0
./configure --enable-cpu  --enable-df --enable-disk --enable-interface --enable-load --enable-memory --enable-ping --enable-swap --enable-users --enable-uptime
make && makeinstall
cpcontrib/redhat/init.d-collectd  /etc/rc.d/init.d/collectd
chmod +x /etc/rc.d/init.d/collectd
ln -s /opt/collectd/sbin/collectdmon  /usr/sbin/
ln -s /opt/collectd/sbin/collectd  /usr/sbin/
 
  1. 配置collectd
    vim /etc/collectd.conf
    BaseDir "/opt/collectd"
    PIDFile "/run/collectd.pid"
    Hostname "host.example.com"
    Interval 60
    
    Interval 120
    
    LoadPlugindisk
    LoadPlugininterface
    LoadPluginload
    LoadPluginmemory
    LoadPluginnetwork
    LoadPluginprocesses
    LoadPluginusers
    
    Interface "eth1"
    IgnoreSelectedfalse
    
    
    Server "10.44.38.244" "25826"
    
     
    
  2. 说明
    默认collectd进程会每10s中调用注册在配置文件中的插件,默认全局参数interval=10s(10s上报一次数据到influxdb等),针对不同的插件可以配置不同的搜集数据的时间间隔interval

InfluxDB

  1. 安装并启动服务
    cat < <EOF | sudotee /etc/yum.repos.d/influxdb.repo
    [influxdb]
    name = InfluxDBRepository - RHEL $releasever
    baseurl = https://repos.influxdata.com/rhel/$releasever/$basearch/stable
    enabled = 1
    gpgcheck = 1
    gpgkey = https://repos.influxdata.com/influxdb.key
    EOF
    yum -y installinfluxdb
    serviceinfluxdbstart
    启动后TCP端口:8083 为InfluxDB 管理控制台
      TCP端口:8086 为客户端和InfluxDB通信时的HTTPAPI
    启动后InfluxDB用户认证默认是关闭的,先创建用户:geekwolfgeekwolf
    命令行输入influx
     
    
  2. 基本使用
    [[email protected] ~]# influx
    Visithttps://enterprise.influxdata.com to register for updates, InfluxDB server management, and monitoring.
    Connectedto http://localhost:8086 version 0.12.2
    InfluxDBshell 0.12.2
    > createdatabasecollectdb
    > createdatabasecollectdb
    > showdatabases
    name: databases
    ------
    name
    _internal
    collectdb
    > createusergeekwolfwithpassword 'geekwolf'
    > showusers
    user            admin
    geekwolf        false
    > grantalloncollectdbfromto geekwolf
    > helpshow
    Usage:
        connect   connectsto anothernodespecifiedbyhost:port
        auth                  promptsfor usernameand password
        pretty                togglesprettyprint for thejsonformat
        use         setscurrentdatabase
        format       specifiestheformatoftheserverresponses: json, csv, or column
        precision     specifiestheformatofthetimestamp: rfc3339, h, m, s, ms, u or ns
        consistency   setswriteconsistencylevel: any, one, quorum, or all
        history              displayscommandhistory
        settings              outputsthecurrentsettingsfor theshell
        exit/quit/ctrl+d      quitstheinfluxshell
     
        showdatabases        showdatabasenames
        showseries          showseriesinformation
        showmeasurements    showmeasurementinformation
        showtagkeys        showtagkeyinformation
        showfieldkeys      showfieldkeyinformation
     
        A fulllist ofinfluxqlcommandscanbefoundat:
        https://docs.influxdata.com/influxdb/v0.10/query_language/spec
     
    
  3. 启用认证
    修改配置文件启用认证
    sed -i ’s#auth-enabled = false#auth-enabled = true#g’ /etc/influxdb/influxdb.conf
    serviceinfluxdbrestart
     
    

配置InfluxDB支持Collectd

  1. 修改配置
    vim /etc/influxdb/influxdb.conf
    [collectd]
    enabled = true
    bind-address = "10.44.38.244:25826"
    database = "collectdb"
    typesdb = "/opt/collectd/share/collectd/types.db"
    batch-size = 5000
    batch-pending = 10
    batch-timeout = "10s"
    read-buffer = 0
    serviceinfluxdbrestart
     
     
    
  2. 查看metrics信息
[[email protected] ~]# influx
Visithttps://enterprise.influxdata.com to register for updates, InfluxDB server management, and monitoring.
Connectedto http://localhost:8086 version 0.12.2
InfluxDBshell 0.12.2
> use collectdb
Usingdatabasecollectdb
> showfieldkeys
name: cpu_value
---------------
fieldKey
value
 
name: df_free
-------------
fieldKey
value
 
name: df_used
-------------
fieldKey
value
 
name: disk_read
---------------
fieldKey
value
> select * fromcpu_valuelimit 15;
name: cpu_value
---------------
time                    host                    instance        type    type_instance  value
1461657293000000000    host.example.com        1              cpu    idle            1.59845e+06
1461657293000000000    host.example.com        1              cpu    system          2316
1461657293000000000    host.example.com        1              cpu    nice            508
1461657293000000000    host.example.com        0              cpu    steal          0
1461657293000000000    host.example.com        1              cpu    user            11619
1461657293000000000    host.example.com        1              cpu    interrupt      0
1461657293000000000    host.example.com        1              cpu    steal          0
1461657293000000000    host.example.com        1              cpu    wait            172
1461657293000000000    host.example.com        1              cpu    softirq        0
1461657303000000000    host.example.com        1              cpu    wait            172
1461657303000000000    host.example.com        1              cpu    softirq        0
1461657303000000000    host.example.com        1              cpu    nice            508
1461657303000000000    host.example.com        0              cpu    idle            1.587007e+06
1461657303000000000    host.example.com        0              cpu    softirq        127
1461657303000000000    host.example.com        0              cpu    interrupt      54
 

安装配置Grafana

yuminstallhttps://grafanarel.s3.amazonaws.com/builds/grafana-3.0.0-beta51460725904.x86_64.rpm
目录结构
/usr/sbin/grafana-server
/etc/init.d/grafana-server          上述命令的拷贝,启动脚本
/etc/sysconfig/grafana-server      环境变量
/etc/grafana/grafana.ini            配置文件
/var/log/grafana/grafana.log        日志文件
/var/lib/grafana/grafana.db    sqlite3数据库
 
启动服务: servicegrafana-serverstart
        chkconfiggrafana-serveron
 
 

访问地址:http://10.44.38.244:3000 默认账号为admin admin关闭Grafana注册功能:

sed -i ’s/#allow_sign_up = true/allow_sign_up = false/g’  /etc/grafana/grafana.ini,重启服务
 
  • 添加InfluxDB数据源

  • 添加ping图的例子

  • 图表展示

详细demo可参考:http://play.grafana.org/

问题总结

问题 :在使用influxdb0.12.x版本和Grafana2.6时出现multiple query syntax的bug,原因是influxdb的apiwent

解决方法: 升级Grafana2.6到Grafana3.0-beta1以上版本https://github.com/grafana/grafana/commit/ed62822d442569e7ba287ff63d83a069a596c458

参考文档

http://docs.grafana.org

https://collectd.org/wiki/index.php/Table_of_Plugins

https://docs.influxdata.com/influxdb/v0.12/introduction/getting_started/

稿源:Geekwolf's Blog (源链) | 关于 | 阅读提示

本站遵循[CC BY-NC-SA 4.0]。如您有版权、意见投诉等问题,请通过eMail联系我们处理。
酷辣虫 » 后端存储 » Grafana+InfluxDB+Collectd构建监控系统

喜欢 (0)or分享给?

专业 x 专注 x 聚合 x 分享 CC BY-NC-SA 4.0

使用声明 | 英豪名录