标签:des mode 磁盘容量 数据解析 rev-parse 接口 退出 timeout 使用
agent的目的是收集目标机器上的所有数据,并动态同步hbs中的配置信息,将数据上报到transfer中,是所有监控数据的产生源头。
agent上报的数据主要分为三类:
agent起了一个定时任务,定时与HBS同步一些信息,获取一些动态数据以及上报自己的状态信息。默认上报时间间隔是一分钟。
上报给HBS的数据:
agent版本plugin版本 脚本所在git目录的版本,git rev-parse HEAD)从HBS获取的数据:
agent提供了HTTP服务,用于管理者检查agent服务是否正常,远程操作agent等。
主要提供的Http服务如下:
agent源码得分块分析,下面是各个块的源码分析:
下面是agent的默认配置,已在下面源码中做了注释
{
"debug": true, // 开启debug模式
"hostname": "", // 定义主机名,如果没定义,则会去获取本机主机名
"ip": "", // 定义上报时的IP地址,若未配置则自动获取本机IP
"plugin": { // 关于插件的配置,配置插件目录,git地址等
"enabled": false,
"dir": "./plugin",
"git": "https://github.com/open-falcon/plugin.git",
"logs": "./logs"
},
"heartbeat": { // 配置HBS服务地址和同步数据周期,默认是60秒
"enabled": true,
"addr": "127.0.0.1:6030",
"interval": 60,
"timeout": 1000
},
"transfer": { // 配置transfer集群地址,以及同步数据周期,默认是60秒同步一次
"enabled": true,
"addrs": [
"127.0.0.1:8433",
"127.0.0.1:8433"
],
"interval": 60,
"timeout": 1000
},
"http": { // 配置http服务启动端口
"enabled": true,
"listen": ":1988",
"backdoor": false
},
"collector": { // 配置网卡名称开头,因为在linux物理机上,网卡名并不一定都是以eth开头
"ifacePrefix": ["eth", "em"],
"mountPoint": []
},
"default_tags": { // 设置默认tags
},
"ignore": { // 忽略的上报数据,有些内置的上报数据是用户不关心的,可以在这里配置不上报这些数据
"cpu.busy": true,
"df.bytes.free": true,
"df.bytes.total": true,
"df.bytes.used": true,
"df.bytes.used.percent": true,
"df.inodes.total": true,
"df.inodes.free": true,
"df.inodes.used": true,
"df.inodes.used.percent": true,
"mem.memtotal": true,
"mem.memused": true,
"mem.memused.percent": true,
"mem.memfree": true,
"mem.swaptotal": true,
"mem.swapused": true,
"mem.swapfree": true
}
}
IP和rpc连接池 big mapperHBS获取本地连接HBS的网口的IP地址。HBS通信。下面是创建的big mapper的源码,把各种需要获取的内置监控项的数据都存储在这个大列表中,等待发送到transfer中。
type FuncsAndInterval struct {
Fs []func() []*model.MetricValue
Interval int
}
var Mappers []FuncsAndInterval
func BuildMappers() {
interval := g.Config().Transfer.Interval
Mappers = []FuncsAndInterval{
{
Fs: []func() []*model.MetricValue{
AgentMetrics,
CpuMetrics,
NetMetrics,
KernelMetrics,
LoadAvgMetrics,
MemMetrics,
DiskIOMetrics,
IOStatsMetrics,
NetstatMetrics,
ProcMetrics,
UdpMetrics,
},
Interval: interval,
},
{
Fs: []func() []*model.MetricValue{
DeviceMetrics,
},
Interval: interval,
},
{
Fs: []func() []*model.MetricValue{
PortMetrics,
SocketStatSummaryMetrics,
},
Interval: interval,
},
{
Fs: []func() []*model.MetricValue{
DuMetrics,
},
Interval: interval,
},
{
Fs: []func() []*model.MetricValue{
UrlMetrics,
},
Interval: interval,
},
}
}
cron.InitDataHistory方法每隔一秒钟同步一次CPU状态和disk list状态,只保留最近两次的数据。cron.ReportAgentStatus方法每隔60秒向HBS上报自己的信息,数据包括:
cron.SyncMinePlugins方法同步HBS中的MinePlugins,获取最新的plugins路径,再删除旧的路径添加新的路径cron.SyncBuiltinMetrics方法同步HBS中的BuiltinMetrics,获取需要监控的ports,paths,procs,urls,并把这些组合成相应的metrics,插入到需要监控的metrics中cron.SyncTrustableIps方法同步HBS中的TrustableIps,获取信任IP列表,在这个列表中的IP可以通过agent执行shell命令cron.Collect方法默认每隔60将big mapper中的数据向transfer汇报一次,Endpoint是获取的hostname,若cfg中配置了则用cfg的配置,这时候会检查cfg中如果配置了default_tags,则会在上传每条数据之前,在其Tags中增加default_tags中的tags。注意,在cfg中如果配置了多个transfer地址,则每份数据都会发给所有的transfer节点。Http服务提供的路由接口代码如下:
func init() {
configAdminRoutes()
configCpuRoutes()
configDfRoutes()
configHealthRoutes()
configIoStatRoutes()
configKernelRoutes()
configMemoryRoutes()
configPageRoutes()
configPluginRoutes()
configPushRoutes()
configRunRoutes()
configSystemRoutes()
}
configAdminRoutes提供如下api:
"/exit"退出agentJ进程"/config/reload"重载agent的配置"/workdir"获取agent的工作根目录"/ips"获取受信任IP列表configCpuRoutes获取CPU相关的状态信息configDfRoutes获取挂载磁盘容量使用信息configHealthRoutes检查agent是否存活以及版本信息configIoStatRoutes获取磁盘IO状态信息configKernelRoutes获取内核信息configMemoryRoutes获取内存信息configPageRoutes获取页面展示当前主机的监控信息configPluginRoutes可查看、更新plugins列表,从git同步plugins到指定目录configPushRoutes通过"/v1/push"接口可以将其他服务收集的数据push到agent中转发给transferconfigRunRoutes执行shell命令并返回给客户,需要验证客户IP地址是否是受信任IPconfigSystemRoutes获取一些系统当前时间,启动信息等数据标签:des mode 磁盘容量 数据解析 rev-parse 接口 退出 timeout 使用
原文地址:http://www.cnblogs.com/bingabcd/p/7749533.html