在说gweb的event 前, 我先举个例子 :
在办公室有时会听到NOC的同事大喊, 流量飙升了, 怎么回事?
然后一般会有同事回应可能是在跨机房拷贝一些文件或者数据什么的, 又或者是在做跨机房的数据备份什么的.
如果在流量图上有标记的话, 那么NOC的同事对待这种流量突变的情况也不会一惊一乍.
gweb支持配置event, 这里指的event就是用户定义的时间段标签.
例如 :
配置文件目录和customize view的目录一样
http://blog.163.com/digoal@126/blog/static/1638770402014815105622529/
/data01/web/ganglia-web/conf/events.json
包含的内容举例 :
[
{ "event_id":"1234", # 事件 ID
"start_time":1308496361, # 开始时间
"end_time":1308496961, # 结束时间
"summary":"DB Backup", # summary
"description":"Prod daily db backup", # 事件描述
"grid":"*",
"cluster":"*",
"host_regex":"centos1" # 主机名规则表达式
},
{ "event_id":"2345", # 第二个事件的内容
"start_time":1308497211,
"summary":"FS cleanup",
"grid":"*",
"cluster":"*",
"host_regex":"centos1"
}
]
当events很多时, 解析JSON可能会增加CPU负载, 可以考虑使用mdb2格式, 即将event存入MYSQL数据库. 需要修改conf.php
默认的conf.php中event相关的配置如下 :
# What is the provider use to provide events.
# Examples: "json", "mdb2"
$conf['overlay_events_provider'] = "json";
# Where is the Overlay events file stored
$conf['overlay_events_file'] = $conf['conf_dir'] . "/events.json";
# If using MDB2, connection string:
$conf['overlay_events_dsn'] = "mysql://dbuser:dbpassword@localhost/ganglia";
$conf['overlay_events_color_map_file'] = $conf['conf_dir'] . "/event_color.json";
例子, 使用events.json添加event.
获得一个时间, 用于start_time
digoal=# SELECT EXTRACT(EPOCH FROM now()),now();
date_part | now
------------------+-------------------------------
1410765863.10149 | 2014-09-15 15:24:23.101488+08
(1 row)
编辑events.json
[root@db-172-16-3-221 conf]# vi events.json
[
{ "event_id":"digoal",
"start_time":1410765863,
"end_time":1410765999,
"summary":"DB Backup",
"description":"Prod daily db backup",
"grid":"*",
"cluster":"*",
"host_regex":".*"
}
]
现在在图中就可以看到这个事件了. summary会显示在图中 :
通过这个图我们就知道这个时候正在做数据库备份, 如果流量上升的话可以得到合理的解释.
(当然不排除恰巧同时也发生了其他事件到在图形的异常)
除了使用events.json来编辑创建event, 还可以使用web界面或者API来创建event.
使用WEB 界面来创建event.
也可以使用API来创建event :
通过HTTP GET或POST请求来创建event.
An easy way to manipulate events is through the Ganglia Events API, which is available
from your gweb interface at /ganglia/api/events.php. To use it, invoke the URL along
with key/value pairs that define events. Key/value pairs can be supplied as either GET
or POST arguments. The full list of key/value pairs is provided in :
Key: Value
action: addto add a new event, editto edit, removeor deleteto remove an event.
start_time: Start time of an event. Allowed options are now(uses current system time), UNIX timestamp, or any other well formed date, as supported by PHP’s strtotime function.
end_time: Optional. Same format as start_time.
summary: Summary of an event. It will be shown in the graph legend.
host_regex: Host regular expression, such as web-|app-.
例子 :
curl "http://mygangliahost.com/ganglia/api/events.php?\
action=add&start_time=now&\
summary=Prod DB Backup&host_regex=db02"
OR
curl -X POST --data " action=add&start_time=now\
&summary=Prod DB Backup&host_regex=db02" \
http://mygangliahost.com/ganglia/api/events.php
返回值 :
API will return a JSON-encoded status message with either status = ok or status = error.
If you are adding an event, you will also get the event_idof the event that was just
added in case you want to edit it later, such as to add an end_time.
[参考]
1. http://blog.163.com/digoal@126/blog/static/1638770402014810227936/
2. http://blog.163.com/digoal@126/blog/static/1638770402014815105622529/