Skip to content

Commit

Permalink
[Controller] Add new alarm policy
Browse files Browse the repository at this point in the history
 - run automation test(basic&upgrade) pass
  • Loading branch information
Ericsssss authored and SongZhen0704 committed May 11, 2024
1 parent b40d355 commit 3e6f639
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
17 changes: 16 additions & 1 deletion server/controller/db/mysql/migration/rawsql/init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1362,7 +1362,7 @@ set @lcuuid = (select uuid());
INSERT INTO alarm_policy(user_id, sub_view_type, tag_conditions, query_conditions, query_url, query_params, sub_view_metrics, name, level, state,
app_type, sub_type, contrast_type, target_line_uid, target_line_name, target_field,
threshold_warning, lcuuid)
values(1, 1, "过滤项: N/A | 分组项: tag.host", "", "/v1/stats/querier/UniversalHistory", "{\"DATABASE\":\"deepflow_system\",\"TABLE\":\"deepflow_agent_monitor\",\"interval\":60,\"fill\": \"none\",\"window_size\":5,\"QUERIES\":[{\"QUERY_ID\":\"R1\",\"SELECT\":\"Min(`metrics.cpu_percent`/`metrics.max_cpus`) AS `cpu_usage`\",\"WHERE\":\"1=1\",\"GROUP_BY\":\"`tag.host`\",\"METRICS\":[\"Min(`metrics.cpu_percent`/`metrics.max_cpus`) AS `cpu_usage`\"]}]}",
values(1, 1, "过滤项: N/A | 分组项: tag.host", "", "/v1/stats/querier/UniversalHistory", "{\"DATABASE\":\"deepflow_system\",\"TABLE\":\"deepflow_agent_monitor\",\"interval\":60,\"fill\": \"none\",\"window_size\":5,\"QUERIES\":[{\"QUERY_ID\":\"R1\",\"SELECT\":\"(Min(`metrics.cpu_percent`/`metrics.max_millicpus`)*1000) AS `cpu_usage`\",\"WHERE\":\"1=1\",\"GROUP_BY\":\"`tag.host`\",\"METRICS\":[\"(Min(`metrics.cpu_percent`/`metrics.max_millicpus`)*1000) AS `cpu_usage`\"]}]}",
"[{\"METRIC_LABEL\":\"cpu_usage\",\"return_field_description\":\"持续 5 分钟 (CPU用量/阈值)\",\"unit\":\"%\"}]", "采集器 CPU 超限", 0, 1, 1, 21, 1, "", "", "{\"displayName\":\"cpu_usage\", \"unit\": \"%\"}", "{\"OP\":\">=\",\"VALUE\":70}", @lcuuid);

set @lcuuid = (select uuid());
Expand Down Expand Up @@ -1449,6 +1449,13 @@ INSERT INTO alarm_policy(user_id, sub_view_type, tag_conditions, query_condition
values(1, 1, "过滤项: N/A | 分组项: tag.cluster_id", "", "/v1/stats/querier/UniversalHistory", "{\"DATABASE\":\"deepflow_system\",\"TABLE\":\"deepflow_server_controller_genesis_k8sinfo_delay\",\"interval\":60,\"fill\": \"none\",\"window_size\":1,\"QUERIES\":[{\"QUERY_ID\":\"R1\",\"SELECT\":\"Last(`metrics.avg`) AS `delay`\",\"WHERE\":\"1=1\",\"GROUP_BY\":\"`tag.cluster_id`\",\"METRICS\":[\"Last(`metrics.avg`) AS `delay`\"]}]}",
"[{\"METRIC_LABEL\":\"delay\",\"return_field_description\":\"资源同步滞后时间\",\"unit\":\" 秒\"}]", "K8s 资源同步滞后", 1, 1, 1, 23, 1, "", "", "{\"displayName\":\"delay\", \"unit\": \"秒\"}", "{\"OP\":\">=\",\"VALUE\":600}", @lcuuid);

set @lcuuid = (select uuid());
INSERT INTO alarm_policy(user_id, sub_view_type, tag_conditions, query_conditions, query_url, query_params, sub_view_metrics, name, level, state,
app_type, sub_type, contrast_type, target_line_uid, target_line_name, target_field,
threshold_warning, lcuuid)
values(1, 1, "过滤项: N/A | 分组项: tag.db, tag.table", "", "/v1/stats/querier/UniversalHistory", "{\"DATABASE\":\"deepflow_system\",\"TABLE\":\"deepflow_server_ingester_force_delete_clickhouse_data\",\"interval\":60,\"fill\": \"none\",\"window_size\":5,\"QUERIES\":[{\"QUERY_ID\":\"R1\",\"SELECT\":\"Count(row) AS `force_delete_clickhouse_data_count`\",\"WHERE\":\"1=1\",\"GROUP_BY\":\"`tag.db`, `tag.table`\",\"METRICS\":[\"Count(row) AS `force_delete_clickhouse_data_count`\"]}]}",
"[{\"METRIC_LABEL\":\"force_delete_clickhouse_data_count\",\"return_field_description\":\"最近 1 分钟 数据库修改次数\",\"unit\":\"次\"}]", "数据节点数据强制删除", 0, 1, 1, 21, 1, "", "", "{\"displayName\":\"force_delete_clickhouse_data_count\", \"unit\": \"次\"}", "{\"OP\":\">=\",\"VALUE\":1}", @lcuuid);

set @lcuuid = (select uuid());
INSERT INTO alarm_policy(user_id, sub_view_type, tag_conditions, query_conditions, query_url, query_params, sub_view_metrics, name, level, state,
app_type, sub_type, contrast_type, target_line_uid, target_line_name, target_field,
Expand Down Expand Up @@ -1521,6 +1528,14 @@ INSERT INTO alarm_policy(user_id, sub_view_type, tag_conditions, query_condition
"[{\"METRIC_LABEL\":\"drop_packets\",\"return_field_description\":\"最近 1 分钟 flow_map.metrics.drop_by_window\",\"unit\":\"\"}]",
"采集器数据丢失 (flow_map.metrics.drop_by_window)", 0, 1, 1, 21, 1, "", "", "{\"displayName\":\"flow_map.metrics.drop_by_window\", \"unit\": \"\"}", "{\"OP\":\">=\",\"VALUE\":1}", @lcuuid);

set @lcuuid = (select uuid());
INSERT INTO alarm_policy(user_id, sub_view_type, tag_conditions, query_conditions, query_url, query_params, sub_view_metrics, name, level, state,
app_type, sub_type, contrast_type, target_line_uid, target_line_name, target_field,
threshold_warning, lcuuid)
values(1, 1, "过滤项: N/A | 分组项: tag.host", "", "/v1/stats/querier/UniversalHistory", "{\"DATABASE\":\"deepflow_system\",\"TABLE\":\"deepflow_agent_flow_map\",\"interval\":60,\"fill\": \"none\",\"window_size\":1,\"QUERIES\":[{\"QUERY_ID\":\"R1\",\"SELECT\":\"Sum(`metrics.drop_by_capacity`) AS `flow_map.metrics.drop_by_capacity`\",\"WHERE\":\"1=1\",\"GROUP_BY\":\"`tag.host`\",\"METRICS\":[\"Sum(`metrics.drop_by_capacity`) AS `flow_map.metrics.drop_by_capacity`\"]}]}",
"[{\"METRIC_LABEL\":\"drop_packets\",\"return_field_description\":\"最近 1 分钟 flow_map.metrics.drop_by_capacity\",\"unit\":\"\"}]",
"采集器数据丢失 (flow_map.metrics.drop_by_capacity)", 0, 1, 1, 21, 1, "", "", "{\"displayName\":\"flow_map.metrics.drop_by_capacity\", \"unit\": \"\"}", "{\"OP\":\">=\",\"VALUE\":1}", @lcuuid);

set @lcuuid = (select uuid());
INSERT INTO alarm_policy(user_id, sub_view_type, tag_conditions, query_conditions, query_url, query_params, sub_view_metrics, name, level, state,
app_type, sub_type, contrast_type, target_line_uid, target_line_name, target_field,
Expand Down
32 changes: 32 additions & 0 deletions server/controller/db/mysql/migration/rawsql/issu/6.5.1.30.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
START TRANSACTION;

-- modify start, add upgrade sql

UPDATE alarm_policy SET query_params="{\"DATABASE\":\"deepflow_system\",\"TABLE\":\"deepflow_agent_monitor\",\"interval\":60,\"fill\": \"none\",\"window_size\":5,\"QUERIES\":[{\"QUERY_ID\":\"R1\",\"SELECT\":\"(Min(`metrics.cpu_percent`/`metrics.max_millicpus`)*1000) AS `cpu_usage`\",\"WHERE\":\"1=1\",\"GROUP_BY\":\"`tag.host`\",\"METRICS\":[\"(Min(`metrics.cpu_percent`/`metrics.max_millicpus`)*1000) AS `cpu_usage`\"]}]}" WHERE name="采集器 CPU 超限";

set @lcuuid = (select uuid());
INSERT INTO alarm_policy(user_id, sub_view_type, tag_conditions, query_conditions, query_url, query_params, sub_view_metrics, name, level, state,
app_type, sub_type, contrast_type, target_line_uid, target_line_name, target_field,
threshold_warning, lcuuid)
SELECT 1, 1, "过滤项: N/A | 分组项: tag.host", "", "/v1/stats/querier/UniversalHistory", "{\"DATABASE\":\"deepflow_system\",\"TABLE\":\"deepflow_agent_flow_map\",\"interval\":60,\"fill\": \"none\",\"window_size\":1,\"QUERIES\":[{\"QUERY_ID\":\"R1\",\"SELECT\":\"Sum(`metrics.drop_by_capacity`) AS `flow_map.metrics.drop_by_capacity`\",\"WHERE\":\"1=1\",\"GROUP_BY\":\"`tag.host`\",\"METRICS\":[\"Sum(`metrics.drop_by_capacity`) AS `flow_map.metrics.drop_by_capacity`\"]}]}",
"[{\"METRIC_LABEL\":\"drop_packets\",\"return_field_description\":\"最近 1 分钟 flow_map.metrics.drop_by_capacity\",\"unit\":\"\"}]",
"采集器数据丢失 (flow_map.metrics.drop_by_capacity)", 0, 1, 1, 21, 1, "", "", "{\"displayName\":\"flow_map.metrics.drop_by_capacity\", \"unit\": \"\"}", "{\"OP\":\">=\",\"VALUE\":1}", @lcuuid
WHERE NOT EXISTS (
SELECT * FROM alarm_policy WHERE name="采集器数据丢失 (flow_map.metrics.drop_by_capacity)"
);

set @lcuuid = (select uuid());
INSERT INTO alarm_policy(user_id, sub_view_type, tag_conditions, query_conditions, query_url, query_params, sub_view_metrics, name, level, state,
app_type, sub_type, contrast_type, target_line_uid, target_line_name, target_field,
threshold_warning, lcuuid)
SELECT 1, 1, "过滤项: N/A | 分组项: tag.db, tag.table", "", "/v1/stats/querier/UniversalHistory", "{\"DATABASE\":\"deepflow_system\",\"TABLE\":\"deepflow_server_ingester_force_delete_clickhouse_data\",\"interval\":60,\"fill\": \"none\",\"window_size\":5,\"QUERIES\":[{\"QUERY_ID\":\"R1\",\"SELECT\":\"Count(row) AS `force_delete_clickhouse_data_count`\",\"WHERE\":\"1=1\",\"GROUP_BY\":\"`tag.db`, `tag.table`\",\"METRICS\":[\"Count(row) AS `force_delete_clickhouse_data_count`\"]}]}",
"[{\"METRIC_LABEL\":\"force_delete_clickhouse_data_count\",\"return_field_description\":\"最近 1 分钟 数据库修改次数\",\"unit\":\"次\"}]", "数据节点数据强制删除", 0, 1, 1, 21, 1, "", "", "{\"displayName\":\"force_delete_clickhouse_data_count\", \"unit\": \"次\"}", "{\"OP\":\">=\",\"VALUE\":1}", @lcuuid
WHERE NOT EXISTS (
SELECT * FROM alarm_policy WHERE name="数据节点数据强制删除"
);

-- update db_version to latest, remeber update DB_VERSION_EXPECT in migrate/init.go
UPDATE db_version SET version='6.5.1.30';
-- modify end

COMMIT;
2 changes: 1 addition & 1 deletion server/controller/db/mysql/migration/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ package migration

const (
DB_VERSION_TABLE = "db_version"
DB_VERSION_EXPECTED = "6.5.1.29"
DB_VERSION_EXPECTED = "6.5.1.30"
)

0 comments on commit 3e6f639

Please sign in to comment.