架构原理

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-uptimemake && makeinstall
cpcontrib/redhat/init.d-collectd  /etc/rc.d/init.d/collectd
chmod +x /etc/rc.d/init.d/collectdln -s /opt/collectd/sbin/collectdmon  /usr/sbin/ln -s /opt/collectd/sbin/collectd  /usr/sbin/
  1. 配置collectd

    vim /etc/collectd.confBaseDir "/opt/collectd"PIDFile "/run/collectd.pid"Hostname "host.example.com"Interval 60Interval 120LoadPlugindiskLoadPlugininterfaceLoadPluginloadLoadPluginmemoryLoadPluginnetworkLoadPluginprocessesLoadPluginusersInterface "eth1"IgnoreSelectedfalseServer "10.44.38.244" "25826"
  2. 说明 
    默认collectd进程会每10s中调用注册在配置文件中的插件,默认全局参数interval=10s(10s上报一次数据到influxdb等),针对不同的插件可以配置不同的搜集数据的时间间隔interval

InfluxDB

  1. 安装并启动服务

    cat < 
  2. 基本使用

    [root@geekwolf ~]# influx
    Visithttps://enterprise.influxdata.com to register for updates, InfluxDB server management, and monitoring.
    Connectedto http://localhost:8086 version 0.12.2InfluxDBshell 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 = 5000batch-pending = 10batch-timeout = "10s"read-buffer = 0serviceinfluxdbrestart
  2. 查看metrics信息

[root@geekwolf ~]# influx
Visithttps://enterprise.influxdata.com to register for updates, InfluxDB server management, and monitoring.Connectedto http://localhost:8086 version 0.12.2InfluxDBshell 0.12.2> use collectdb
Usingdatabasecollectdb
> showfieldkeysname: 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  value1461657293000000000    host.example.com        1              cpu    idle            1.59845e+061461657293000000000    host.example.com        1              cpu    system          23161461657293000000000    host.example.com        1              cpu    nice            5081461657293000000000    host.example.com        0              cpu    steal          01461657293000000000    host.example.com        1              cpu    user            116191461657293000000000    host.example.com        1              cpu    interrupt      01461657293000000000    host.example.com        1              cpu    steal          01461657293000000000    host.example.com        1              cpu    wait            1721461657293000000000    host.example.com        1              cpu    softirq        01461657303000000000    host.example.com        1              cpu    wait            1721461657303000000000    host.example.com        1              cpu    softirq        01461657303000000000    host.example.com        1              cpu    nice            5081461657303000000000    host.example.com        0              cpu    idle            1.587007e+061461657303000000000    host.example.com        0              cpu    softirq        1271461657303000000000    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数据源及监控例子即可