1. 更新系统

1
2
yum update -y
yum install epel-release -y

2. 安装influxDB

下载influxDB package 在https://repos.influxdata.com/centos/7/x86_64/stable/

1
yum install https://repos.influxdata.com/centos/7/x86_64/stable/influxdb-0.9.6.1-1.x86_64.rpm

配置启动influxDB

1
2
# vi /etc/influxdb/influxdb.conf
reporting-disabled = true
1
2
3
# systemctl start influxdb
# systemctl enable influxdb
# systemctl status influxdb

访问 http://your_server_ip:8083 点击配置,Connection Settings,添加IP地址,使用默认用户名root和密码root

3. 安装配置collectd

collectd 用于收集系统性能数据 发送到 influxDB

1
yum install -y collectd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[root@grafana ~]# grep "^\s*[^# \t].*$" /etc/collectd.conf
Hostname "grafana"
BaseDir "/var/lib/collectd"
PIDFile "/var/run/collectd.pid"
PluginDir "/usr/lib64/collectd"
TypesDB "/usr/share/collectd/types.db"
LoadPlugin syslog
LoadPlugin cpu
LoadPlugin interface
LoadPlugin load
LoadPlugin memory
LoadPlugin network
<Plugin network>
Server "127.0.0.1" "8096"
</Plugin>
Include "/etc/collectd.d"
1
2
3
4
#测试配置文件
[root@grafana ~]# collectd -t
#启动collectd服务
[root@grafana ~]# systemctl start collectd

4. 配置 InfluxDB 收集 collectd 数据

编辑 /etc/Influxdb/Influxdb.conf

1
2
3
4
5
[collectd]
enabled = true
bind-address = ":8096"
database = "metrics"
typesdb = "/usr/share/collectd/types.db"

重启influxdb

1
# systemctl restart influxdb

验证influxdb

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
[root@grafana ~]# influx
Visit https://enterprise.influxdata.com to register for updates, InfluxDB server management, and monitoring.
Connected to http://localhost:8086 version 0.9.6.1
InfluxDB shell 0.9.6.1
> show databases
name: databases
---------------
name
_internal
metrics
> use metrics
Using database metrics
> show series
> show measurements
name: measurements
------------------
name
cpu_value
interface_rx
interface_tx
load_longterm
load_midterm
load_shortterm
memory_value

> select * from memory_value
name: memory_value
------------------
time host type type_instance value
1460697403852057000 grafana memory slab_unrecl 3.1891456e+07
1460697403852057000 grafana memory slab_recl 6.877184e+07
1460697403852057000 grafana memory used 9.3622272e+07
1460697403852057000 grafana memory buffered 1.855488e+06

5. 安装 Grafana

官方安装文档http://docs.grafana.org/installation/rpm/

1
# yum install https://grafanarel.s3.amazonaws.com/builds/grafana-3.0.0-beta41460581169.x86_64.rpm

手工安装

1
2
# yum install initscripts fontconfig
# rpm -ivh grafana-3.0.0-beta41460581169.x86_64.rpm

启动 grafana

1
2
3
[root@grafana ~]# systemctl daemon-reload
[root@grafana ~]# systemctl start grafana-server
[root@grafana ~]# systemctl status grafana-server

grafana服务

  • 默认http端口3000,
  • 默认用户admin/admin
  • 默认配置文件 /etc/grafana/grafana.ini
  • 默认日志 /var/log/grafana
  • 默认数据库 sqlite3 路径/var/lib/grafana/grafana.db,升级grafana前请备份数据库

也支持mysql postgres 数据库,更改数据库配置请看http://docs.grafana.org/installation/configuration/#database

6. 在grafana上添加influxDB数据源

登录 grafana配置页面 http://your_server_ip:3000

点击Data Sources -> Add New

1
2
3
4
5
6
7
8
Name: influxDB
Type: influxDB
Url: http://localhost:8086
Access: proxy
Basic Auth: 不选
Database: metrics
User: root
Password: root

点击Add

7. 创建grafana面板

1
2
SELECT derivative("value") AS "value" FROM "interface_rx" WHERE "host" = 'grafana' AND "type" = 'if_octets' AND "instance" = 'enp0s8'
SELECT derivative("value") AS "value" FROM "interface_tx" WHERE "host" = 'grafana' AND "type" = 'if_octets' AND "instance" = 'enp0s8'

8. 参考