目标:
掌握aodh资源模型与主要表结构
目录:
1 进入数据库
2 alarm资源模型
3 alarm_history资源模型
1 进入数据库
cat /etc/aodh/aodh.conf|grep mysql
connection = mysql+pymysql://aodh:[email protected]:3306/aodh
mysql -uaodh -pct15k08j
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 715428
Server version: 10.1.30-MariaDB-1~jessie mariadb.org binary distribution
Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> use aodh;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
MariaDB [aodh]> show tables;
+-----------------+
| Tables_in_aodh |
+-----------------+
| alarm |
| alarm_history |
| alembic_version |
+-----------------+
2 alarm资源模型
alarm表作用: 存储云平台创建的告警
MariaDB [aodh]> desc alarm;
+---------------------------+---------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------------------------+---------------+------+-----+---------+-------+
| alarm_id | varchar(128) | NO | PRI | NULL | |
| enabled | tinyint(1) | YES | MUL | NULL | |
| name | text | YES | | NULL | |
| type | varchar(50) | YES | MUL | NULL | |
| severity | varchar(50) | YES | | NULL | |
| description | text | YES | | NULL | |
| timestamp | decimal(20,6) | YES | | NULL | |
| user_id | varchar(128) | YES | MUL | NULL | |
| project_id | varchar(128) | YES | MUL | NULL | |
| state | varchar(255) | YES | | NULL | |
| state_timestamp | decimal(20,6) | YES | | NULL | |
| ok_actions | text | YES | | NULL | |
| alarm_actions | text | YES | | NULL | |
| insufficient_data_actions | text | YES | | NULL | |
| repeat_actions | tinyint(1) | YES | | NULL | |
| rule | text | YES | | NULL | |
| time_constraints | text | YES | | NULL | |
+---------------------------+---------------+------+-----+---------+-------+
alarm表结构
名称 属性 描述
alarm_id string 告警id
enabled int 告警是否开启
name string 告警名称
type string 告警类型,可选的值有: gnocchi_resources_threshold, threshold
severity string 告警级别
description string 告警描述信息
timestamp decimal 告警时间
user_id string 用户id
project_id string 项目id
state string 告警状态,可选的值有: alarm, insufficient data, ok
state_timestamp decimal 告警状态时间
ok_actions array 状态为正常状态ok时执行的action列表,每个元素是一个字符串
alarm_actions array 状态为告警状态alarm时执行的action列表,每个元素是一个字符串
insufficient_data_actions array 状态为数据不足状态insufficient_data时执行的action列表,每个元素是一个字符串
repeat_actions int 是否重复执行action
rule string 告警规则,根据不同的告警类型,有不同的告警规则。经过处理后可以转换为字典。
time_constraints string
记录样例:
属性 值
alarm_id 9f710d60-a633-4c1c-a3af-9c3ff20a9bc8
enabled 1
name cpu_alarm
type gnocchi_resources_threshold
severity low
description cpu告警
timestamp 1591689521.738982
user_id 8c49145bbbab409a90bbc7e570c61403
project_id 8a0ef29ca2a04af7bd39860d89016014
state insufficient data
state_timestamp 1591689521.738982
ok_actions []
alarm_actions ["email://[email protected]?admin"]
insufficient_data_actions []
repeat_actions 0
rule {"evaluation_periods": 1, "metric": "cpu_util", "resource_id": "7fa004dd-d880-4928-8fe2-99d5928dcb9a", "aggregation_method": "mean", "granularity": 300, "threshold": 100.0, "comparison_operator": "lt", "resource_type": "instance"}
time_constraints []
3 alarm_history资源模型
alarm_history表的主要作用就是记录每次告警状态发生改变时的记录
MariaDB [aodh]> desc alarm_history;
+--------------+---------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------------+---------------+------+-----+---------+-------+
| event_id | varchar(128) | NO | PRI | NULL | |
| alarm_id | varchar(128) | YES | MUL | NULL | |
| on_behalf_of | varchar(128) | YES | | NULL | |
| project_id | varchar(128) | YES | | NULL | |
| user_id | varchar(128) | YES | | NULL | |
| type | varchar(20) | YES | | NULL | |
| detail | text | YES | | NULL | |
| timestamp | decimal(20,6) | YES | | NULL | |
| severity | varchar(50) | YES | | NULL | |
+--------------+---------------+------+-----+---------+-------+
alarm_history表结构
名称 属性 描述
event_id string 主健,唯一标识这条记录
alarm_id string 告警id
on_behalf_of string
project_id string 项目id
user_id string 用户id
type string 生成该记录的原因,可选的值: "state transition", "creation"
detail string 该告警历史记录的详细信息
timestamp decimal 生成该记录的时间
severity string 等级
记录样例:
名称 值
event_id 14e7d4ee-acb1-4329-9576-0a4fca0efd65
alarm_id 9f710d60-a633-4c1c-a3af-9c3ff20a9bc8
on_behalf_of 8a0ef29ca2a04af7bd39860d89016014
project_id NULL
user_id NULL
type state transition
detail {"transition_reason": "Transition to alarm due to 1 samples outside threshold, most recent:0.106674908586", "state": "alarm"}
timestamp 1591689705.701722
severity NULL
参考:
newton版本aodh代码