diff --git a/cmd/cloudmon/main_exec.go b/cmd/cloudmon/main_exec.go index 8a27f236c9..f3b302fcda 100644 --- a/cmd/cloudmon/main_exec.go +++ b/cmd/cloudmon/main_exec.go @@ -75,7 +75,7 @@ func TestCron() { err = parser.ParseArgs2(os.Args[1:], false, false) - opts := parser.Options().(*options.CloudMonOptions) + opts := parser.Options().(*options.SubCloudMonOptions) if opts.Help { fmt.Println(parser.HelpString()) @@ -141,7 +141,7 @@ func TestCron() { }() var session *mcclient.ClientSession - session, err = newClientSession(opts) + session, err = newClientSession(&opts.CloudMonOptions) if err != nil { showErrorAndExit(err) } diff --git a/pkg/apis/monitor/metric.go b/pkg/apis/monitor/metric.go index 01ca767768..16793f57c0 100644 --- a/pkg/apis/monitor/metric.go +++ b/pkg/apis/monitor/metric.go @@ -30,6 +30,8 @@ const ( METRIC_RES_TYPE_DOMAIN = "domain" METRIC_RES_TYPE_STORAGE = "storage" METRIC_RES_TYPE_ELB = "elb" + METRIC_RES_TYPE_K8S = "k8s" + //ext is prefix! METRIC_RES_TYPE_JENKINS = "ext_jenkins" METRIC_RES_TYPE_EXT_MYSQL = "ext_mysql" diff --git a/pkg/cloudmon/options/options.go b/pkg/cloudmon/options/options.go index b009c50d7d..4f95065591 100644 --- a/pkg/cloudmon/options/options.go +++ b/pkg/cloudmon/options/options.go @@ -37,7 +37,10 @@ type CloudMonOptions struct { KeyFile string `help:"private key file"` InfluxDatabase string `help:"influxdb database name, default telegraf" default:"telegraf"` +} +type SubCloudMonOptions struct { + CloudMonOptions Subcommand string `help:"climc subcommand" subcommand:"true"` } @@ -63,7 +66,7 @@ type PingProbeOptions struct { } func GetArgumentParser() (*structarg.ArgumentParser, error) { - parse, e := structarg.NewArgumentParser(&Options, + parse, e := structarg.NewArgumentParser(&SubOptions, "cloudmon", `Command-line interface to collect cloud monitoring data.`, `See "cloudmon help COMMAND" for help on a specific command.`) @@ -97,5 +100,6 @@ func GetArgumentParser() (*structarg.ArgumentParser, error) { } var ( - Options CloudMonOptions + Options CloudMonOptions + SubOptions SubCloudMonOptions ) diff --git a/pkg/monitor/dbinit/metric_dbinit.go b/pkg/monitor/dbinit/metric_dbinit.go index 110a00a4e7..c273decfd3 100644 --- a/pkg/monitor/dbinit/metric_dbinit.go +++ b/pkg/monitor/dbinit/metric_dbinit.go @@ -455,4 +455,29 @@ func init() { newMetricFieldCreateInput("messages", "messages", monitor.METRIC_UNIT_COUNT, 4), }) + // k8s + // pod + RegistryMetricCreateInput("k8s_pod", "k8s pod", + monitor.METRIC_RES_TYPE_K8S, monitor.METRIC_DATABASE_TELE, 1, []monitor.MetricFieldCreateInput{ + newMetricFieldCreateInput("cpu_used_percent", "CPU active state utilization rate", monitor.METRIC_UNIT_PERCENT, 1), + newMetricFieldCreateInput("mem_used_percent", "Used memory rate", monitor.METRIC_UNIT_PERCENT, 2), + newMetricFieldCreateInput("restart_total", "pod restart count", monitor.METRIC_UNIT_COUNT, 3), + }) + // deploy/daemonset + RegistryMetricCreateInput("k8s_deploy", "k8s deploy", + monitor.METRIC_RES_TYPE_K8S, monitor.METRIC_DATABASE_TELE, 2, []monitor.MetricFieldCreateInput{ + newMetricFieldCreateInput("pod_oom_total", "oom pod count", monitor.METRIC_UNIT_COUNT, 1), + newMetricFieldCreateInput("pod_restarting_total", "restarting pod count", monitor.METRIC_UNIT_COUNT, 2), + }) + // node + RegistryMetricCreateInput("k8s_node", "k8s node", + monitor.METRIC_RES_TYPE_K8S, monitor.METRIC_DATABASE_TELE, 3, []monitor.MetricFieldCreateInput{ + newMetricFieldCreateInput("cpu_used_percent", "CPU active state utilization rate", monitor.METRIC_UNIT_PERCENT, 1), + newMetricFieldCreateInput("mem_used_percent", "Used memory rate", monitor.METRIC_UNIT_PERCENT, 2), + newMetricFieldCreateInput("disk_used_percent", "Percentage of used disks", monitor.METRIC_UNIT_PERCENT, 3), + newMetricFieldCreateInput("bps_sent", "Send traffic per second", monitor.METRIC_UNIT_BPS, 3), + newMetricFieldCreateInput("bps_recv", "Received traffic per second", monitor.METRIC_UNIT_BPS, 4), + newMetricFieldCreateInput("pod_restart_total", "pod restart count in node", monitor.METRIC_UNIT_COUNT, 4), + }) + }