@adonia
2016-07-22T08:46:21.000000Z
字数 3972
阅读 714
运维
说明:测试环境为
centos 6.8
或者使用docker镜像,执行docker pull influxdb
。(influxdb对接collectd时,需要开启udp端口,待验证)
解压之后,influxdb
的安装目录内容如下:
├── etc
│ ├── influxdb
│ │ ├── influxdb.conf
│ │ └── influxdb.conf.template
│ └── logrotate.d
│ └── influxdb
├── usr
│ ├── bin
│ │ ├── influx
│ │ ├── influxd
│ │ ├── influx_inspect
│ │ ├── influx_stress
│ │ └── influx_tsm
│ └── lib
│ └── influxdb
│ └── scripts
│ ├── influxdb.service
│ └── init.sh
└── var
├── lib
│ └── influxdb
└── log
└── influxdb
其中,usr/bin/influxd
为influxdb
的引导程序;etc/influxdb/influxdb.conf
为配置文件。
Tips: 在修改
etc/influxdb/influxdb.conf
配置之前,先备份一份。
需要注意的是influxdb
的三部分配置---admin
、http
和collectd
,分别是influxdb
管理控制台、HTTP API以及对接collectd
的配置。其中可以保持admin
和http
的配置不动。
Tips:
admin
和http
使用的端口分别是8083
和8086
,只要保证端口不冲突即可。
对接collectd
的默认配置如下:
[[collectd]]
enabled = false
# bind-address = ""
# database = ""
# typesdb = ""
# These next lines control how batching works. You should have this enabled
# otherwise you could get dropped metrics or poor performance. Batching
# will buffer points in memory if you have many coming in.
# batch-size = 1000 # will flush if this many points get buffered
# batch-pending = 5 # number of batches that may be pending in memory
# batch-timeout = "1s" # will flush at least this often even if we haven't hit buffer limit
# read-buffer = 0 # UDP Read buffer size, 0 means OS default. UDP listener will fail if set above OS max.
将其修改为:
[[collectd]]
enabled = true
bind-address = ":25826"
database = "collectd"
# typesdb = ""
# These next lines control how batching works. You should have this enabled
# otherwise you could get dropped metrics or poor performance. Batching
# will buffer points in memory if you have many coming in.
# batch-size = 1000 # will flush if this many points get buffered
# batch-pending = 5 # number of batches that may be pending in memory
# batch-timeout = "1s" # will flush at least this often even if we haven't hit buffer limit
# read-buffer = 0 # UDP Read buffer size, 0 means OS default. UDP listener will fail if set above OS max.
- 将
[collectd][enabled]
置为true
;- 设置对接
collectd
的udp端口为25826
;- 设置
influxdb
中存储collectd
数据的数据库为collectd
。
在influxdb
的安装目录下执行:
./usr/bin/influxd run -config /opt/influxdb/etc/influxdb/influxdb.conf
/opt/influxdb
为influxdb
的安装目录,注意替换成实际目录。
或者执行如下命令,将influxd
作为后台程序启动:
nohup /opt/influxdb/usr/bin/influxd run -config /opt/influxdb/etc/influxdb/influxdb.conf &
启动之后,查看有无错误日志。
在influxdb
对接collectd
的配置后,在启动influxdb
时,会自动创建collectd
数据库。
可通过influxdb
的管理控制台或者RESTful接口查询其中的数据库来验证。
192.168.102.16:8083
,在Query
中输入查询语句---show databases
GET 192.168.102.16:8086/query?pretty=true&q=show databases
查询结果应如下:
{
"results": [
{
"series": [
{
"name": "databases",
"columns": [
"name"
],
"values": [
[
"_internal"
],
[
"graphite"
],
[
"collectd"
]
]
}
]
}
]
}
参考collectd安装。
修改/etc/collectd.conf
,如下:
Hostname "localhost"
LoadPlugin interface
LoadPlugin cpu
LoadPlugin memory
LoadPlugin network
LoadPlugin df
<Plugin interface>
Interface "eth0"
IgnoreSelected false
</Plugin>
<Plugin network>
<Server "192.168.102.16" "25826">
</Server>
</Plugin>
25826
即为collectd
上报数据的udp端口,与influxdb
中配置的保持一致。
保存,执行service collectd restart
,重启collectd
。
启动完成之后,collectd
会定期收集操作系统的数据,之后,将数据上报至influxdb
中。
在influxdb
的管理控制台---192.168.102.16:8083
的菜单栏的Database
下拉栏中选择collectd
,在Query
输入下述查询语句:
show measurements
--- 查询collectd
数据库中的表,结果如下:
select * from cpu_value
--- 查询cpu使用信息
通过docker镜像的方式安装grafana
:
docker pull grafana/grafana
docker run -d -p 3000:3000 grafana/grafana
grafana
对外暴露的端口是3000
,启动时,指定VM的端口与其对应。
访问192.168.102.16:3000
,默认账号是 admin/admin
。
influxdb
数据库 Data Sources
---> Add data source
,如下:Tips:
- 在
InfluxDB Details
指定Database
为collectd
,User
为默认的root/root
。
下面将collectd
数据库中的cpu_value
、df_value
和memory_value
的数据绘制成数据图表。
1) 首先,选择+ New
,新建Dashboard
,如下:
2) 在新建的Dashboard
页面,点击+ADD ROW
,在左侧选择新建Graph
,如下:
之后,新创建的Graph
页面如下:
会有个默认数据图表,点击右侧的删除。
3) 在Panel data source
中选择collectd
数据库,点击+ Add Query
添加查询语句,如下:
比如,需要展示剩余的CPU,对应的数据库查询语句为select value from cpu_value where type_instance = 'idle' and type = 'cpu'
。
select measurement
选择cpu_value
点击
where
后的+
增加过滤语句点击第二行(
SELECT
)的mean()
上方位置,会出现x
,将其删除同样操作,将第三行(
GROUP BY
)的time ($interval)
和fill (null)
移除
最终结果:
4) 保存Dashboard
选择菜单栏中的新建的Dashboard,选择新建的Dashboard,就可以看到所有的数据图表了。
效果如下:
点击Graph的名称,选择share
,如下:
在Link
页签中,包含了访问该图表的链接;在Embed
中指明了通过iframe
的方式,将该图表嵌入至其他页面的方式。