Kapacitor总体介绍
介绍见 链接
用户可以创建自定义逻辑或用户定义的函数,以便为基于时间的操作创建查询。
特点(摘抄自官方博客)
1.Action Oriented
遵循 publish-subscribe design pattern:发布订阅者模式
2.Streaming Analytics
新点:预处理和down sampling
3.Anomaly Detection
提供了一个simple plugin architecture
允许灵活地将流生成到任意函数并继续处理该函数的输出。
4.流框架与Grafana
一种持续监控的方式。
Kapacitor功能
- 流处理与批处理:Process both
streaming data
andbatch data.
- 数据接收
- 数据转换:Perform any transformation currently possible in InfluxQL.
- 数据写回
- 阈值警报
- 模式匹配
- 异常检测
值得注意的是:
- Kapacitor不仅支持从InfluxDB读取数据并处理,还支持预处理和降采样(处理极高速数据?)
- kapacitor支持InfluxQL和lambda表达式语法;启动任务以SQL或者单独的脚本触发
InfluxDB+Telegraf+Kapacitor+Grafana启动
以MacOS
为例,通过homebrew
安装并启动。
注意:
Mac+homebrew
会将配置文件放到/usr/local/etc/telegraf.conf
、bin安装到/usr/local/bin
。作为对比,linux是/etc/telegraf/telegraf.conf
下面。- 官方最新文档不全,只提到Linux下通过
systemctl
启动,但Mac系统不同。可以通过brew services start
或kapacitor的特定命令启动。
influxdb启动
安装略过。
influxd -config /usr/local/etc/influxdb.conf
# 或
brew services start influxdb
第二条运行后,
ps -ef|grep influxdb
可以看到,运行的命令是默认命令,即influxd -config /usr/local/etc/influxdb.conf
如果想指定其他conf文件:
# 各个组件都类似,导出
influxd config > ~/my-influxd.conf
# 修改my-influxd.conf配置文件
dir = "~/.influxdb/data-test"
# 启动:
influxd -config ~/influxdb.conf
# 已经看到新的数据文件
ls .influxdb
brew services start
还没找到改配置参数的方法。
telegraf安装与启动
Telegraf 是一个用 Go 编写的代理程序,可收集系统和服务的统计数据,并写入到 InfluxDB 数据库。内存占用小,通过插件系统可轻松添加支持其他服务的扩展。
1.5版官方文档没写怎么用到mac上。
0.12github官方文档 记载了方法。
brew update
brew install telegraf
telegraf -config /usr/local/etc/telegraf.conf
运行:
不断采集机器数据写入influxdb。查询:
curl -G 'http://localhost:8086/query?db=telegraf' --data-urlencode 'q=SELECT mean(usage_idle) FROM cpu'
# result:
{"results":[{"statement_id":0,"series":[{"name":"cpu","columns":["time","mean"],"values":[["1970-01-01T00:00:00Z",86.02170298021207]]}]}]}
也可以访问网址:
http://localhost:8086/query?db=telegraf&q=SELECT mean(usage_idle) FROM cpu
其他通过cli查看已写入的数据,详见0.12github官方文档 。
Kapacitor安装
同样的,1.5的文档没有Mac的启动方法,启动方法见 0.13官网文档 。
为使用 launchd
启动Kapacitor:(不知道为什么)
ln -sfv /usr/local/opt/kapacitor/*.plist ~/Library/LaunchAgents
Then to load Kapacitor now:
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.kapacitor.plist
# 这种启动是静默启动,不显示log到屏幕上
Or, if you don’t want/need lanchctl
, you can just run:
kapacitord -config /usr/local/etc/kapacitor.conf
# 出现log到屏幕
运行两个命令并不会提示"already running",会启动两个进程。
grafana安装与启动
安装启动仍然是:
brew update
brew install grafana
brew services start grafana
登录 http://127.0.0.1:3000/,本机密码 admin/admin
。参见 博客。
1.创建dashboard
:
2.重命名:
3.编辑datasource
,变量等,注意这条线不是telegraf
生成的cpu
曲线:
5.完成。上图已经画出了如下SQL:
SELECT usage_idle FROM cpu where cpu='cpu-total'
kapacitor用户案例
待续。