diff --git a/pkg/apis/monitor/metric.go b/pkg/apis/monitor/metric.go index 0ae2d63f75..c67c430773 100644 --- a/pkg/apis/monitor/metric.go +++ b/pkg/apis/monitor/metric.go @@ -9,6 +9,7 @@ const ( METRIC_RES_TYPE_OSS = "oss" METRIC_RES_TYPE_RDS = "rds" METRIC_RES_TYPE_CLOUDACCOUNT = "cloudaccount" + METRIC_RES_TYPE_AGENT = "agent" METRIC_RES_TYPE_TENANT = "tenant" METRIC_RES_TYPE_DOMAIN = "domain" @@ -31,8 +32,9 @@ var ( METRIC_RES_TYPE_RDS, METRIC_RES_TYPE_CLOUDACCOUNT} MetricUnit = []string{METRIC_UNIT_PERCENT, METRIC_UNIT_BPS, METRIC_UNIT_MBPS, METRIC_UNIT_BYTEPS, "count/s", METRIC_UNIT_COUNT, METRIC_UNIT_MS, METRIC_UNIT_BYTE, METRIC_UNIT_RMB} - ResTypeScoreMap = map[string]int{ + ResTypeScoreMap = map[string]float64{ METRIC_RES_TYPE_GUEST: 1, + METRIC_RES_TYPE_AGENT: 1.1, METRIC_RES_TYPE_HOST: 2, METRIC_RES_TYPE_OSS: 3, METRIC_RES_TYPE_RDS: 4, diff --git a/pkg/apis/monitor/unifiedmonitor_const.go b/pkg/apis/monitor/unifiedmonitor_const.go index eb166efec6..608e982417 100644 --- a/pkg/apis/monitor/unifiedmonitor_const.go +++ b/pkg/apis/monitor/unifiedmonitor_const.go @@ -23,6 +23,7 @@ var ( MEASUREMENT_TAG_ID = map[string]string{ METRIC_RES_TYPE_HOST: "host_id", METRIC_RES_TYPE_GUEST: "vm_id", + METRIC_RES_TYPE_AGENT: "vm_id", METRIC_RES_TYPE_REDIS: "redis_id", METRIC_RES_TYPE_RDS: "rds_id", METRIC_RES_TYPE_OSS: "oss_id", diff --git a/pkg/monitor/alerting/conditions/query.go b/pkg/monitor/alerting/conditions/query.go index 7fd27cf828..7ac38ba96e 100644 --- a/pkg/monitor/alerting/conditions/query.go +++ b/pkg/monitor/alerting/conditions/query.go @@ -549,6 +549,8 @@ func (c *QueryCondition) getOnecloudResources() ([]jsonutils.JSONObject, error) allResources, err = ListAllResources(&mc_mds.Hosts, query) case monitor.METRIC_RES_TYPE_GUEST: allResources, err = ListAllResources(&mc_mds.Servers, query) + case monitor.METRIC_RES_TYPE_AGENT: + allResources, err = ListAllResources(&mc_mds.Servers, query) case monitor.METRIC_RES_TYPE_RDS: allResources, err = ListAllResources(&mc_mds.DBInstance, query) case monitor.METRIC_RES_TYPE_REDIS: diff --git a/pkg/monitor/dbinit/metric_dbinit.go b/pkg/monitor/dbinit/metric_dbinit.go index 9c4687dbf8..6493159a6c 100644 --- a/pkg/monitor/dbinit/metric_dbinit.go +++ b/pkg/monitor/dbinit/metric_dbinit.go @@ -266,4 +266,77 @@ func init() { newMetricFieldCreateInput("balance", "balance", monitor.METRIC_UNIT_RMB, 1), }) + // cpu + RegistryMetricCreateInput("agent_cpu", "CPU usage", monitor.METRIC_RES_TYPE_AGENT, monitor.METRIC_DATABASE_TELE, 1, + []monitor.MetricFieldCreateInput{ + newMetricFieldCreateInput("usage_active", "CPU active state utilization rate", monitor.METRIC_UNIT_PERCENT, 1), + newMetricFieldCreateInput("usage_idle", "CPU idle state utilization rate", monitor.METRIC_UNIT_PERCENT, 2), + newMetricFieldCreateInput("usage_system", "CPU system state utilization rate", monitor.METRIC_UNIT_PERCENT, 3), + newMetricFieldCreateInput("usage_user", "CPU user mode utilization rate", monitor.METRIC_UNIT_PERCENT, 4), + newMetricFieldCreateInput("usage_iowait", "CPU IO usage", monitor.METRIC_UNIT_PERCENT, 5), + newMetricFieldCreateInput("usage_irq", "CPU IRQ usage", monitor.METRIC_UNIT_PERCENT, 6), + newMetricFieldCreateInput("usage_guest", "CPU guest usage", monitor.METRIC_UNIT_PERCENT, 7), + newMetricFieldCreateInput("usage_nice", "CPU priority switch utilization", monitor.METRIC_UNIT_PERCENT, 8), + newMetricFieldCreateInput("usage_softirq", "CPU softirq usage", monitor.METRIC_UNIT_PERCENT, 9), + }) + + // disk + RegistryMetricCreateInput("agent_disk", "Disk usage", monitor.METRIC_RES_TYPE_AGENT, + monitor.METRIC_DATABASE_TELE, 3, + []monitor.MetricFieldCreateInput{ + newMetricFieldCreateInput("used_percent", "Percentage of used disks", monitor.METRIC_UNIT_PERCENT, 1), + newMetricFieldCreateInput("free", "Free space size", monitor.METRIC_UNIT_BYTE, 2), + newMetricFieldCreateInput("used", "Used disk size", monitor.METRIC_UNIT_BYTE, 3), + newMetricFieldCreateInput("total", "Total disk size", monitor.METRIC_UNIT_BYTE, 4), + newMetricFieldCreateInput("inodes_free", "Available inode", monitor.METRIC_UNIT_COUNT, 5), + newMetricFieldCreateInput("inodes_used", "Number of inodes used", monitor.METRIC_UNIT_COUNT, 6), + newMetricFieldCreateInput("inodes_total", "Total inodes", monitor.METRIC_UNIT_COUNT, 7), + }) + + // diskio + RegistryMetricCreateInput("agent_diskio", "Disk traffic and timing", + monitor.METRIC_RES_TYPE_AGENT, monitor.METRIC_DATABASE_TELE, 4, []monitor.MetricFieldCreateInput{ + newMetricFieldCreateInput("read_bps", "Disk read rate", monitor.METRIC_UNIT_BPS, 1), + newMetricFieldCreateInput("write_bps", "Disk write rate", monitor.METRIC_UNIT_BPS, 2), + newMetricFieldCreateInput("read_iops", "Disk read operate rate", monitor.METRIC_UNIT_COUNT, 3), + newMetricFieldCreateInput("write_iops", "Disk write operate rate", monitor.METRIC_UNIT_COUNT, 4), + newMetricFieldCreateInput("reads", "Number of reads", monitor.METRIC_UNIT_COUNT, 5), + newMetricFieldCreateInput("writes", "Number of writes", monitor.METRIC_UNIT_COUNT, 6), + newMetricFieldCreateInput("read_bytes", "Bytes read", monitor.METRIC_UNIT_BYTE, 7), + newMetricFieldCreateInput("write_bytes", "Bytes write", monitor.METRIC_UNIT_BYTE, 8), + newMetricFieldCreateInput("write_time", "Time to wait for write", monitor.METRIC_UNIT_MS, 9), + newMetricFieldCreateInput("io_time", "I / O request queuing time", monitor.METRIC_UNIT_MS, 10), + newMetricFieldCreateInput("weighted_io_time", "I / O request waiting time", monitor.METRIC_UNIT_MS, 11), + newMetricFieldCreateInput("iops_in_progress", "Number of I / O requests issued but not yet completed", monitor.METRIC_UNIT_COUNT, 12), + }) + + // mem + RegistryMetricCreateInput("agent_mem", "Memory", monitor.METRIC_RES_TYPE_AGENT, + monitor.METRIC_DATABASE_TELE, 2, []monitor.MetricFieldCreateInput{ + newMetricFieldCreateInput("used_percent", "Used memory rate", monitor.METRIC_UNIT_PERCENT, 1), + newMetricFieldCreateInput("available_percent", "Available memory rate", monitor.METRIC_UNIT_PERCENT, 2), + newMetricFieldCreateInput("used", "Used memory", monitor.METRIC_UNIT_BYTE, 3), + newMetricFieldCreateInput("free", "Free memory", monitor.METRIC_UNIT_BYTE, 4), + newMetricFieldCreateInput("active", "The amount of active memory", monitor.METRIC_UNIT_BYTE, 5), + newMetricFieldCreateInput("inactive", "The amount of inactive memory", monitor.METRIC_UNIT_BYTE, 6), + newMetricFieldCreateInput("cached", "Cache memory", monitor.METRIC_UNIT_BYTE, 7), + newMetricFieldCreateInput("buffered", "Buffer memory", monitor.METRIC_UNIT_BYTE, 7), + newMetricFieldCreateInput("slab", "Number of kernel caches", monitor.METRIC_UNIT_BYTE, 8), + newMetricFieldCreateInput("available", "Available memory", monitor.METRIC_UNIT_BYTE, 9), + newMetricFieldCreateInput("total", "Total memory", monitor.METRIC_UNIT_BYTE, 10), + }) + + // net + RegistryMetricCreateInput("agent_net", "Network interface and protocol usage", + monitor.METRIC_RES_TYPE_AGENT, monitor.METRIC_DATABASE_TELE, 5, []monitor.MetricFieldCreateInput{ + newMetricFieldCreateInput("bytes_sent", "The total number of bytes sent by the network interface", monitor.METRIC_UNIT_BYTE, 1), + newMetricFieldCreateInput("bytes_recv", "The total number of bytes received by the network interface", monitor.METRIC_UNIT_BYTE, 2), + newMetricFieldCreateInput("packets_sent", "The total number of packets sent by the network interface", monitor.METRIC_UNIT_COUNT, 3), + newMetricFieldCreateInput("packets_recv", "The total number of packets received by the network interface", monitor.METRIC_UNIT_COUNT, 4), + newMetricFieldCreateInput("err_in", "The total number of receive errors detected by the network interface", monitor.METRIC_UNIT_COUNT, 5), + newMetricFieldCreateInput("err_out", "The total number of transmission errors detected by the network interface", monitor.METRIC_UNIT_COUNT, 6), + newMetricFieldCreateInput("drop_in", "The total number of received packets dropped by the network interface", monitor.METRIC_UNIT_COUNT, 7), + newMetricFieldCreateInput("drop_out", "The total number of transmission packets dropped by the network interface", monitor.METRIC_UNIT_COUNT, 8), + }) + }