influxdb+grafana+telegraf服务器统计

吐槽、建议、解惑入口网址

influxdb+grafana+telegraf服务器统计

influxdb

类似mysql数据库,时序图的数据库
开源Influxdb安装指引

应用 配置文件 数据文件 命令
influx /etc/influxdb/influxdb.conf
设置meta、data、wal数据存放地址
/var/lib/influxdb/… influxd config: 输出influxdb的配置文件

备注:

  • 当前启动influxdb失败,可能存在meta、data、wal数据存放地址用户组没有访问权限导致的。chown -R influxdb:influxdb [meta、data、wal数据存放地址]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# 第一步 设置influxdb的仓库源
cat <<EOF | sudo tee /etc/yum.repos.d/influxdb.repo
[influxdb]
name = InfluxDB Repository - RHEL \$releasever
baseurl = https://repos.influxdata.com/rhel/\$releasever/\$basearch/stable
enabled = 1
gpgcheck = 1
gpgkey = https://repos.influxdata.com/influxdb.key
EOF

# 第二步 启动influxdb和设置开机自启动服务
sudo yum install influxdb
sudo service influxdb start
sudo chkconfig influxdb on

//////////
sudo yum install influxdb
sudo systemctl start influxdb
sudo systemctl enable influxdb

influxdb连接与操作

命令 操作
influx 连接influxdb的server
influx -precision rfc3339 以rfc3339协议格式连接influxdb的server
show databases 显示所有数据库
use [xxx] 进入[xxx]数据库
show measurements 显示[xxx]数据库中的表
其他命令跟mysql命令差不多

http访问influxdb
默认端口 8086
eg: 192.168.100.100:8086

grafana

展示influxdb时序数据的Web应用
grafana centos 安装

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# 第一步 设置grafana的仓库源
vi /ect/yum.repos.d/grafana.repo

[grafana]
name=grafana
baseurl=https://packages.grafana.com/oss/rpm
repo_gpgcheck=1
enabled=1
gpgcheck=1
gpgkey=https://packages.grafana.com/gpg.key
sslverify=1
sslcacert=/etc/pki/tls/certs/ca-bundle.crt

# 第二步 启动grafana和设置开机自启动服务
sudo yum install grafana
sudo service grafana-server start
sudo chkconfig --add grafana-server

配置grafana访问和数据源

grafana config配置
grafana Web配置数据源

应用 配置文件 数据文件 命令
grafana /etc/grafana/grafana.ini

修改访问grafana网页端口

1
2
# The HTTP port  to use
;http_port = 3000

默认管理员: admin admin
eg:
访问地址: 192.168.100.100:3000

grafanaWeb数据源配置

telegraf

服务器性能数据cpu等性能统计
telegraf 安装

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# 第一步 设置telegraf的仓库源
cat <<EOF | sudo tee /etc/yum.repos.d/influxdb.repo
[influxdb]
name = InfluxDB Repository - RHEL \$releasever
baseurl = https://repos.influxdata.com/rhel/\$releasever/\$basearch/stable
enabled = 1
gpgcheck = 1
gpgkey = https://repos.influxdata.com/influxdb.key
EOF

# 第二步 启动telegraf和设置开机自启动服务
sudo yum install telegraf
sudo service telegraf start
sudo chkconfig telegraf on

//////////
sudo yum install telegraf
sudo systemctl start telegraf
sudo systemctl enable telegraf
应用 配置文件 数据文件 命令
telegraf /etc/telegraf/telegraf.conf

修改config

设置指定influxdb数据源、数据库名称、当前服务器hostname

urls = [“http://192.168.100.100:8086"]
database = “telegraf”
hostname = “172.18.0.x” # (可以用开机脚本修改)

配置开机时自动修改hostname

1
2
3
4
5
6
7
vi /etc/rc.local

# centos6:
IP=$(/sbin/ifconfig | /bin/awk '/inet addr/{print substr($2,6)}'|grep 172.16) && /bin/sed -i -E "s/hostname\s*=\s*\".*?\"/hostname=\"$IP\"/" /etc/telegraf/telegraf.conf

# centos7:
IP=$(/sbin/ifconfig | /bin/awk '/inet /{print substr($2,1)}'|grep 172.16) && /bin/sed -i -E "s/hostname\s*=\s*\".*?\"/hostname=\"$IP\"/" /etc/telegraf/telegraf.conf
不曾拥有,所以努力。(坚持原创技术分享,您的支持将鼓励我继续创作!)