设为首页 收藏本站
查看: 2227|回复: 0

[经验分享] Grafana+InfluxDB+Collectd构建监控系统

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2017-1-24 09:42:01 | 显示全部楼层 |阅读模式
架构原理

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

    安装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/

    配置collectd

    vim /etc/collectd.confBaseDir "/opt/collectd"PIDFile "/run/collectd.pid"Hostname "host.example.com"Interval 60<loadplugindf>Interval 120</loadplugin>LoadPlugindiskLoadPlugininterfaceLoadPluginloadLoadPluginmemoryLoadPluginnetworkLoadPluginprocessesLoadPluginusers<plugininterface>Interface "eth1"IgnoreSelectedfalse</plugin><pluginnetwork>Server "10.44.38.244" "25826"</plugin>

    说明
    默认collectd进程会每10s中调用注册在配置文件中的插件,默认全局参数interval=10s(10s上报一次数据到influxdb等),针对不同的插件可以配置不同的搜集数据的时间间隔interval

InfluxDB

    安装并启动服务

    cat < <EOF | sudotee /etc/yum.repos.d/influxdb.repo
    [influxdb]
    name = InfluxDBRepository - RHEL \$releaseverbaseurl = https://repos.influxdata.com/rhel/\$releasever/\$basearch/stable
    enabled = 1gpgcheck = 1gpgkey = https://repos.influxdata.com/influxdb.key
    EOF
    yum -y installinfluxdb
    serviceinfluxdbstart
    启动后TCP端口:8083 为InfluxDB 管理控制台
      TCP端口:8086 为客户端和InfluxDB通信时的HTTPAPI
    启动后InfluxDB用户认证默认是关闭的,先创建用户:geekwolfgeekwolf
    命令行输入influx

    基本使用

    [iyunv@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 <host:port>  connectsto anothernodespecifiedbyhost:port    auth                  promptsfor usernameand password
        pretty                togglesprettyprint for thejsonformat
        use <db_name>        setscurrentdatabase
        format <format>      specifiestheformatoftheserverresponses: json, csv, or column
        precision </format><format>    specifiestheformatofthetimestamp: rfc3339, h, m, s, ms, u or ns
        consistency <level>  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

    启用认证

    修改配置文件启用认证
    sed -i ’s#auth-enabled = false#auth-enabled = true#g’ /etc/influxdb/influxdb.conf
    serviceinfluxdbrestart

配置InfluxDB支持Collectd

    修改配置

    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

    查看metrics信息

[iyunv@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. ... 60725904.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数据源及监控例子即可





运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-332768-1-1.html 上篇帖子: 基于CentOS7安装DNS服务器及配置 下篇帖子: rsync + crontab + expect 快速搭建同步 监控系统
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表