看完本文,你就可以部署一个监控服务器的可视化应用,并且可以自己导入数据源进行展示。
参考:https://blog.csdn.net/TTchengcheng/article/details/79742574
参考:https://docs.influxdata.com/influxdb/v1.6/introduction/installation/
1 InfluxDB
InfluxDB是一个开源的时序数据库,使用GO语言开发,特别适合用于处理和分析资源监控数据这种时序相关数据。
1.1 安装
curl -sL https://repos.influxdata.com/influxdb.key | sudo apt-key add -
source /etc/lsb-release
echo "deb https://repos.influxdata.com/${DISTRIB_ID,,} ${DISTRIB_CODENAME} stable" | sudo tee /etc/apt/sources.list.d/influxdb.list
下载key的过程会较慢,可以先直接通过浏览器下载下来,然后使用sudo apt-key add influxdb.key
添加
1.2 启动server
influx
InfluxDB
的server地址为http://localhost:8086
1.3 基本命令
Connected to http://localhost:8086 version 1.2.4
InfluxDB shell version: 1.2.4
# 新建数据库
> create database mydb
# 显示所有数据库
> show databases
name: databases
name
----
_internal
mydb
# 进入数据库
> use mydb
Using database mydb
# 插入数据(下面的cpu一般称为measurement,host和region我们称为tags)
> INSERT cpu,host=serverA,region=us_west value=0.64
# 查询数据
> select * from cpu
name: cpu
time host region value
---- ---- ------ -----
1541153053182009062 serverA us_west 0.64
从上面的操作过程中可以看到,基本语句与mysql差别不大
1.4 启动admin后台
修改配置文件
vim /etc/influxdb/influxdb.conf
按照下面的内容进行修改
[admin]
# Determines whether the admin service is enabled.
enabled = true # 将这一句取消注释
# The default bind address used by the admin service.
# bind-address = ":8083"
# Whether the admin service should use HTTPS.
# https-enabled = false
# The SSL certificate used when HTTPS is enabled.
# https-certificate = "/etc/ssl/influxdb.pem"
访问http://127.0.0.1:8083/
即可看到如下页面
在Query
输入框中输入select * from cpu
即可看到数据
右上角可以切换db
2 telegraf
Telegraf是一个用Go编写的代理程序,可收集系统和服务的统计数据,并写入到多种数据库。
官网文档
2.1 安装
点击链接下载telegraf指定版本:下载安装包
执行命令安装
sudo dpkg -i telegraf_1.5.3-1_amd64.deb
2.2 修改配置文件
修改配置文件用于向infludb写入数据
sudo vim /etc/telegraf/telegraf.conf
按照下面的内容修改
[[outputs.influxdb]]
## The full HTTP or UDP URL for your InfluxDB instance.
##
## Multiple URLs can be specified for a single cluster, only ONE of the
## urls will be written to each interval.
# urls = ["unix:///var/run/influxdb.sock"]
# urls = ["udp://127.0.0.1:8089"]
urls = ["http://127.0.0.1:8086"] # 取消注释
## The target database for metrics; will be created as needed.
database = "telegraf" # 取消注释
现在telegraf会默默的向influxdb里面写入cpu、内存、硬盘等硬件的时序参数。
3 grafana
Grafana是一个开源的度量分析与可视化套件。经常被用作基础设施的时间序列数据和应用程序分析的可视化,支持多种数据源。
官网
3.1 安装
安装并启动服务
wget https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana_5.0.3_amd64.deb
sudo dpkg -i grafana_5.0.3_amd64.deb
sudo service grafana-server start
访问http://127.0.0.1:3000
即可以进入可视化界面
3.2 配置数据源
点击Data Sources
点击Add data source
新增数据源
按照下图配置数据源的相关参数,主要是选择数据库类型和数据库
保存后,就可以开始制作面板了
3.3 面板
创建新Dashboard
作以下配置,显示CPU的运行曲线
点击Last 6 hours
按钮,修改refreshing every
参数为10s,面板会每十秒钟刷新一次数据
点击保存即可
查看效果(这里使用了Zabbix插件)