当在IT的不归路上越陷越深的时候,手上的服务器也渐渐多了起来,Web、FTP、NFS、SMB、WDS、DHCP、AD DC、DNS、WSUS、数据库……差不多都部署了个遍,多了就有照顾不到的机器,比如在LA的Web服务器挂了一周我才发现23333~
随即寻找服务器性能监控的方案,倾向于实时显示数据的那种,也就是数据可视化的,就找到了这个Telegraf+InfluxDB+Grafana的方案,一套大数据可视化方案。Telegraf负责采集服务器性能指标并发送给InfluxDB,InfluxDB 是一个时间序列数据库,用于处理海量写入与负载查询。InfluxDB旨在用作涉及大量时间戳数据的任何用例(包括DevOps监控,应用程序指标,物联网传感器数据和实时分析)的后端存储。Grafana是一个开源的度量分析与可视化套件。经常被用作基础设施的时间序列数据和应用程序分析的可视化,它在其他领域也被广泛的使用包括工业传感器、家庭自动化、天气和过程控制等。操作方便而且界面相当的高大上!
看了看三个工具的官网(准确来说是两个,Telegraf和InfluxDB是一家的),都支持ARM平台,正好手上有块树莓派3B,一脸坏笑的看着树莓派3B,嘿嘿嘿,就你了!
下载地址:
【Telegraf+InfluxDB】
https://portal.influxdata.com/downloads/
【Grafana】
https://grafana.com/grafana/download
部署InfluxDB
到 https://portal.influxdata.com/downloads/ 选择下载InfluxDB,找到对应的架构的二进制文件直接下载就OK,树莓派是ARM架构的,直接在树莓派上下载解压
pi@raspberrypi:~ $ wget https://dl.influxdata.com/influxdb/releases/influxdb-1.7.5_linux_armhf.tar.gz pi@raspberrypi:~ $ tar xvfz influxdb-1.7.5_linux_armhf.tar.gz
解压过后会看到三个文件夹,将这三个文件夹中的文件与根目录的合并即可
pi@raspberrypi:~ $ ls influxdb-1.7.5-1 influxdb-1.7.5_linux_armhf.tar.gz pi@raspberrypi:~ $ cd influxdb-1.7.5-1 pi@raspberrypi:~/influxdb-1.7.5-1 $ ls etc usr var pi@raspberrypi:~/influxdb-1.7.5-1 $ sudo cp -r etc/* /etc/ pi@raspberrypi:~/influxdb-1.7.5-1 $ sudo cp -r usr/* /usr/ pi@raspberrypi:~/influxdb-1.7.5-1 $ sudo cp -r var/* /var/
安装即完成,sudo influxd启动InfluxDB,即可看到以下信息:
pi@raspberrypi:~/influxdb-1.7.5-1 $ sudo influxd 8888888 .d888 888 8888888b. 888888b. 888 d88P* 888 888 *Y88b 888 *88b 888 888 888 888 888 888 .88P 888 88888b. 888888 888 888 888 888 888 888 888 8888888K. 888 888 88b 888 888 888 888 Y8bd8P 888 888 888 Y88b 888 888 888 888 888 888 888 X88K 888 888 888 888 888 888 888 888 888 Y88b 888 .d8**8b. 888 .d88P 888 d88P 8888888 888 888 888 888 Y88888 888 888 8888888P 8888888P 2019-04-05T11:37:24.087626ZinfoInfluxDB starting{"log_id": "0EcKTaTl000", "version": "1.7.5", "branch": "1.7", "commit": "2f49e00f7f3801a506304c3b6d8165b2f4039f3d"} 2019-04-05T11:37:24.087723ZinfoGo runtime{"log_id": "0EcKTaTl000", "version": "go1.11", "maxprocs": 4} 2019-04-05T11:37:24.189289ZinfoUsing data dir{"log_id": "0EcKTaTl000", "service": "store", "path": "/var/lib/influxdb/data"} 2019-04-05T11:37:24.189438ZinfoCompaction settings{"log_id": "0EcKTaTl000", "service": "store", "max_concurrent_compactions": 2, "throughput_bytes_per_second": 50331648, "throughput_bytes_per_second_burst": 50331648} 2019-04-05T11:37:24.189509ZinfoOpen store (start){"log_id": "0EcKTaTl000", "service": "store", "trace_id": "0EcKTasG000", "op_name": "tsdb_open", "op_event": "start"} 2019-04-05T11:37:24.196671ZinfoReading file{"log_id": "0EcKTaTl000", "engine": "tsm1", "service": "cacheloader", "path": "/var/lib/influxdb/wal/ServerMonitor/oneDay/4/_00001.wal", "size": 141291} 2019-04-05T11:37:24.202443ZinfoReading file{"log_id": "0EcKTaTl000", "engine": "tsm1", "service": "cacheloader", "path": "/var/lib/influxdb/wal/_internal/monitor/1/_00001.wal", "size": 7732511} 2019-04-05T11:37:24.294285ZinfoOpened shard{"log_id": "0EcKTaTl000", "service": "store", "trace_id": "0EcKTasG000", "op_name": "tsdb_open", "index_version": "inmem", "path": "/var/lib/influxdb/data/ServerMonitor/oneDay/4", "duration": "100.122ms"} 2019-04-05T11:37:28.899180ZinfoOpened shard{"log_id": "0EcKTaTl000", "service": "store", "trace_id": "0EcKTasG000", "op_name": "tsdb_open", "index_version": "inmem", "path": "/var/lib/influxdb/data/_internal/monitor/1", "duration": "4698.292ms"} 2019-04-05T11:37:28.899461ZinfoOpen store (end){"log_id": "0EcKTaTl000", "service": "store", "trace_id": "0EcKTasG000", "op_name": "tsdb_open", "op_event": "end", "op_elapsed": "4709.946ms"} 2019-04-05T11:37:28.899643ZinfoOpened service{"log_id": "0EcKTaTl000", "service": "subscriber"} 2019-04-05T11:37:28.899694ZinfoStarting monitor service{"log_id": "0EcKTaTl000", "service": "monitor"} 2019-04-05T11:37:28.899747ZinfoRegistered diagnostics client{"log_id": "0EcKTaTl000", "service": "monitor", "name": "build"} 2019-04-05T11:37:28.899786ZinfoRegistered diagnostics client{"log_id": "0EcKTaTl000", "service": "monitor", "name": "runtime"} 2019-04-05T11:37:28.899824ZinfoRegistered diagnostics client{"log_id": "0EcKTaTl000", "service": "monitor", "name": "network"} 2019-04-05T11:37:28.899880ZinfoRegistered diagnostics client{"log_id": "0EcKTaTl000", "service": "monitor", "name": "system"} 2019-04-05T11:37:28.899993ZinfoStarting precreation service{"log_id": "0EcKTaTl000", "service": "shard-precreation", "check_interval": "10m", "advance_period": "30m"} 2019-04-05T11:37:28.900041ZinfoStarting snapshot service{"log_id": "0EcKTaTl000", "service": "snapshot"} 2019-04-05T11:37:28.900083ZinfoStarting continuous query service{"log_id": "0EcKTaTl000", "service": "continuous_querier"} 2019-04-05T11:37:28.900155ZinfoStarting HTTP service{"log_id": "0EcKTaTl000", "service": "httpd", "authentication": false} 2019-04-05T11:37:28.900198Zinfoopened HTTP access log{"log_id": "0EcKTaTl000", "service": "httpd", "path": "stderr"} 2019-04-05T11:37:28.900248ZinfoStoring statistics{"log_id": "0EcKTaTl000", "service": "monitor", "db_instance": "_internal", "db_rp": "monitor", "interval": "10s"} 2019-04-05T11:37:28.900483ZinfoListening on HTTP{"log_id": "0EcKTaTl000", "service": "httpd", "addr": "[::]:8086", "https": false} 2019-04-05T11:37:28.900562ZinfoStarting retention policy enforcement service{"log_id": "0EcKTaTl000", "service": "retention", "check_interval": "30m"} 2019-04-05T11:37:28.900835ZinfoListening for signals{"log_id": "0EcKTaTl000"} 2019-04-05T11:37:28.901123ZinfoSending usage statistics to usage.influxdata.com{"log_id": "0EcKTaTl000"} ………
按Ctrl+C将influxd进程停止掉,接下来将InfluxDB配置为Service的形式随树莓派开机启动:
pi@raspberrypi:~ $ cp -f /usr/lib/influxdb/scripts/init.sh /etc/init.d/influxdb pi@raspberrypi:~ $ cp -f /usr/lib/influxdb/scripts/influxdb.service /lib/systemd/system/influxdb.service pi@raspberrypi:~ $ systemctl enable influxdb|| true pi@raspberrypi:~ $ systemctl daemon-reload || true pi@raspberrypi:~ $ sudo service influxdb start
接下来是在树莓派上安装Grafana,Telegraf是安装在要监控的机器上的,我将最后安装他。
安装Grafana
到Grafana官网 https://grafana.com/grafana/download 下载Grafana,Grafana不仅提供了ARM平台的二进制包,还提供了ARM平台的deb包和rpm包,我树莓派上安装的是2018-11-13-raspbian-stretch-lite.img树莓派官方的系统镜像,所以直接下载了deb包
pi@raspberrypi:~ $ wget https://dl.grafana.com/oss/release/grafana_6.1.1_armhf.deb pi@raspberrypi:~ $ sudo dpkg -i grafana_6.1.1_armhf.deb
dpkg解压安装的过程中可能会出现依赖缺失的问题,上f大法修复之后再来一遍就行了
pi@raspberrypi:~ $ sudo apt-get -f install pi@raspberrypi:~ $ sudo dpkg -i grafana_6.1.1_armhf.deb
执行结束后就安装完成了,启动:
pi@raspberrypi:~ $ service grafana-server start
打开浏览器,输入http://raspberrypi_ip:3000 就能打开Grafana了,Grafana默认的端口是3000,如需修改
pi@raspberrypi:~ $ vim /etc/grafana/grafana.ini
修改grafana.ini文件,找到# http_port = 3000,取消注释,换成你的端口就ok了
#################################### Server #################################### [server] # Protocol (http, https, socket) ;protocol = http # The ip address to bind to, empty will bind to all interfaces ;http_addr = # The http port to use http_port = 4000
下一篇
至此,树莓派上的操作完成,篇二将介绍如何安装InfluxDB以及配置Grafana数据可视化
更新
树莓派官方源中有influxdb的包,但是很老的包,我已经将最新的InfluxDB以及Telegraf、Chronograf、Kapacitor打包并放在了GayHub上,可以前去直接下载安装。
https://github.com/JinkunTian/TICK_Raspberry_Pi