From c501123b6e0fcbb334cbf1525e31e3f0f293881a Mon Sep 17 00:00:00 2001 From: zhaoxiangchun <1422928955@qq.com> Date: Mon, 10 May 2021 15:52:54 +0800 Subject: [PATCH] feat(monitor): add storage monitor metric MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1.增加块存储storage监控信息: 1)增加对应翻译信息 2)监控信息和modules.Strorages接口进行交集取值 3)返回信息处理 --- pkg/apis/monitor/alertquery_const.go | 15 +++++++++++++++ pkg/apis/monitor/metric.go | 3 +++ pkg/apis/monitor/unifiedmonitor_const.go | 14 ++++++++------ pkg/monitor/alerting/conditions/query.go | 5 +++++ pkg/monitor/dbinit/metric_dbinit.go | 5 +++++ 5 files changed, 36 insertions(+), 6 deletions(-) diff --git a/pkg/apis/monitor/alertquery_const.go b/pkg/apis/monitor/alertquery_const.go index 161d742cc9..32c0003554 100644 --- a/pkg/apis/monitor/alertquery_const.go +++ b/pkg/apis/monitor/alertquery_const.go @@ -144,4 +144,19 @@ var ( "domain_id": "id", "project_domain": "name", } + + StorageTags = map[string]string{ + "id": "storage_id", + "name": "storage_name", + "zone": "zone", + "zone_id": "zone_id", + "zone_ext_id": "zone_ext_id", + "status": "status", + "cloudregion": "cloudregion", + "cloudregion_id": "cloudregion_id", + "region_ext_id": "region_ext_id", + "brand": "brand", + "domain_id": "domain_id", + "project_domain": "project_domain", + } ) diff --git a/pkg/apis/monitor/metric.go b/pkg/apis/monitor/metric.go index 0ae2d63f75..6c598143f1 100644 --- a/pkg/apis/monitor/metric.go +++ b/pkg/apis/monitor/metric.go @@ -11,6 +11,7 @@ const ( METRIC_RES_TYPE_CLOUDACCOUNT = "cloudaccount" METRIC_RES_TYPE_TENANT = "tenant" METRIC_RES_TYPE_DOMAIN = "domain" + METRIC_RES_TYPE_STORAGE = "storage" METRIC_UNIT_PERCENT = "%" METRIC_UNIT_BPS = "bps" @@ -21,6 +22,7 @@ const ( METRIC_UNIT_MS = "ms" METRIC_UNIT_BYTE = "byte" METRIC_UNIT_RMB = "RMB" + METRIC_UNIT_MB = "Mb" METRIC_DATABASE_TELE = "telegraf" METRIC_DATABASE_METER = "meter_db" @@ -38,6 +40,7 @@ var ( METRIC_RES_TYPE_RDS: 4, METRIC_RES_TYPE_REDIS: 5, METRIC_RES_TYPE_CLOUDACCOUNT: 6, + METRIC_RES_TYPE_STORAGE: 7, } ) diff --git a/pkg/apis/monitor/unifiedmonitor_const.go b/pkg/apis/monitor/unifiedmonitor_const.go index eb166efec6..ea99e99de1 100644 --- a/pkg/apis/monitor/unifiedmonitor_const.go +++ b/pkg/apis/monitor/unifiedmonitor_const.go @@ -13,12 +13,13 @@ var ( } MEASUREMENT_TAG_KEYWORD = map[string]string{ - "host": "host", - "guest": "vm_name", - "redis": "redis_name", - "rds": "rds_name", - "oss": "oss_name", - "cloudaccount": "cloudaccount_name", + METRIC_RES_TYPE_HOST: "host", + METRIC_RES_TYPE_GUEST: "vm_name", + METRIC_RES_TYPE_REDIS: "redis_name", + METRIC_RES_TYPE_RDS: "rds_name", + METRIC_RES_TYPE_OSS: "oss_name", + METRIC_RES_TYPE_CLOUDACCOUNT: "cloudaccount_name", + METRIC_RES_TYPE_STORAGE: "storage_name", } MEASUREMENT_TAG_ID = map[string]string{ METRIC_RES_TYPE_HOST: "host_id", @@ -29,6 +30,7 @@ var ( METRIC_RES_TYPE_CLOUDACCOUNT: "cloudaccount_id", METRIC_RES_TYPE_TENANT: "tenant_id", METRIC_RES_TYPE_DOMAIN: "domain_id", + METRIC_RES_TYPE_STORAGE: "storage_id", } AlertReduceFunc = map[string]string{ "avg": "average value", diff --git a/pkg/monitor/alerting/conditions/query.go b/pkg/monitor/alerting/conditions/query.go index 6699dba36b..c695b1be81 100644 --- a/pkg/monitor/alerting/conditions/query.go +++ b/pkg/monitor/alerting/conditions/query.go @@ -562,6 +562,9 @@ func (c *QueryCondition) getOnecloudResources() ([]jsonutils.JSONObject, error) allResources, err = ListAllResources(&mc_mds.Projects, query) case monitor.METRIC_RES_TYPE_DOMAIN: allResources, err = ListAllResources(&mc_mds.Domains, query) + case monitor.METRIC_RES_TYPE_STORAGE: + query.Remove("status") + allResources, err = ListAllResources(&mc_mds.Storages, query) default: query := jsonutils.NewDict() query.Set("brand", jsonutils.NewString(hostconsts.TELEGRAF_TAG_ONECLOUD_BRAND)) @@ -730,6 +733,8 @@ func (c *QueryCondition) getTagKeyRelationMap() map[string]string { relationMap = monitor.TenantTags case monitor.METRIC_RES_TYPE_DOMAIN: relationMap = monitor.DomainTags + case monitor.METRIC_RES_TYPE_STORAGE: + relationMap = monitor.StorageTags default: relationMap = monitor.HostTags } diff --git a/pkg/monitor/dbinit/metric_dbinit.go b/pkg/monitor/dbinit/metric_dbinit.go index 9c4687dbf8..8d64dae527 100644 --- a/pkg/monitor/dbinit/metric_dbinit.go +++ b/pkg/monitor/dbinit/metric_dbinit.go @@ -266,4 +266,9 @@ func init() { newMetricFieldCreateInput("balance", "balance", monitor.METRIC_UNIT_RMB, 1), }) + RegistryMetricCreateInput("storage", "Storage usage", + monitor.METRIC_RES_TYPE_STORAGE, monitor.METRIC_DATABASE_TELE, 1, []monitor.MetricFieldCreateInput{ + newMetricFieldCreateInput("usage_active", "Storage utilization rate", monitor.METRIC_UNIT_PERCENT, 1), + newMetricFieldCreateInput("free", "Free storage", monitor.METRIC_UNIT_MB, 2), + }) }