一、常用插件介绍
获取指定端口的连接状态ESTABLISHED、CLOSE_WAIT、LISTEN等
tcpconns:
<Plugin tcpconns>
ListeningPorts false
LocalPort "80"
RemotePort "80"
</Plugin>
获取Nginx的状态
nginx:
<Plugin nginx>
URL "http://test.tt.com/NginxStatus"
</Plugin>
ping:
<Plugin ping>
Host "172.18.2.125"
Interval 10.0
Timeout 1.0
</Plugin>
获取网卡的流量
interface:
<Plugin interface>
Interface "eth0"
</Plugin>
以下插件直接取消注释即可
cpu
load
memory
processes
二、通过influxDB的HTTP API操作数据库
1.创建数据库
#curl -G http://172.18.1.113:8086/query --data-urlencode "q=CREATE DATABASE mydb"
2.插入数据
#插入单条数据
#curl -i -XPOST ‘http://172.18.1.113:8086/write?db=mydb‘ --data-binary ‘cpu_load_short,host=server01,region=us-west value=0.66‘
#一次插入多条数据提高效率
#curl -i -XPOST ‘http://172.18.1.113:8086/write?db=mydb‘ --data-binary ‘cpu_load_short,host=server02 value=0.67
cpu_load_short,host=server02,region=us-west value=0.55
cpu_load_short,direction=in,host=server01,region=us-west value=2.0‘
#将数据写入文件一次性插入
#curl -i -XPOST ‘http://172.18.1.113:8086/write?db=mydb‘ --data-binary @test.txt
#cat test.txt
cpu_load_short,host=server02 value=0.67
cpu_load_short,host=server02,region=us-west value=0.75
cpu_load_short,direction=in,host=server01,region=us-west value=7.0
3.查询数据
#curl -G ‘http://172.18.1.113:8086/query?pretty=true‘ --data-urlencode "db=mydb" --data-urlencode "q=SELECT value FROM cpu_load_short WHERE region=‘us-west‘"
使用命令行查询
#influx > show databases; name: databases --------------- name _internal collectd grafana mydb > use collectd; Using database collectd > select * from /load/ where host=‘t125‘ limit 2; name: load_longterm ------------------- timehosttypevalue 1456453923000000000t125load0 1456453933000000000t125load0 name: load_midterm ------------------ timehosttypevalue 1456453923000000000t125load0 1456453933000000000t125load0 name: load_shortterm -------------------- timehosttypevalue 1456453923000000000t125load0 1456453933000000000t125load0
三、自定义监控数据
示例:监控站点的响应时间
#!bin/bash time=`curl -o /dev/null -s -w %{time_connect}:%{time_starttransfer}:%{http_code} --connect-timeout 60 http://www.baidu.com time_connect=`echo $time|cut -d ‘:‘ -f1` time_starttransfer=`echo $time|cut -d ‘:‘ -f2` http_code=`echo $time|cut -d ‘:‘ -f3` response_time=($(echo $time_starttransfer-$time_connect|bc)) curl -i -XPOST ‘http://127.0.0.1:8086/write?db=collectd‘ --data-binary "oss_web,url=$1,type=response_time value=$response_time oss_web,url=$1,type=time_connect value=$time_connect oss_web,url=$1,type=time_starttransfer value=$time_starttransfer oss_web,url=$1,type=http_code value=$http_code"
加入定时任务一分钟执行一次。然后去grafana绘图
本文出自 “无技术不疯魔” 博客,请务必保留此出处http://s8576.blog.51cto.com/9510968/1749196
Grafana、collectd 和 InfluxDB 打造酷炫监控系统(四)常用插件介绍和自定义数据篇
原文地址:http://s8576.blog.51cto.com/9510968/1749196