MCPcopy Create free account
hub / github.com/deepflowio/deepflow / statsSubCommand

Function statsSubCommand

cli/ctl/promql.go:48–119  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

46}
47
48func statsSubCommand() *cobra.Command {
49 var metric string
50 var labelFlag bool
51 stats := &cobra.Command{
52 Use: "stats",
53 Short: "stats --metric",
54 Run: func(cmd *cobra.Command, args []string) {
55 from, to, err := getQueryTime(cmd)
56 if err != nil {
57 fmt.Fprintf(os.Stderr, "parse time error: %v\n", err)
58 return
59 }
60 var targetLabel, appLabel []string
61 if labelFlag {
62 targetLabel = []string{"*"}
63 appLabel = []string{"*"}
64 }
65 err = statsQuery(cmd, from, to, metric, targetLabel, appLabel)
66 if err != nil {
67 fmt.Fprintf(os.Stderr, "promql stats query error: %v\n", err)
68 }
69 },
70 }
71 stats.PersistentFlags().StringVarP(&metric, "metric", "m", "", "target metric name for stats analysis")
72 stats.PersistentFlags().BoolVarP(&labelFlag, "all-labels", "A", false, "query metric and all labels stats info")
73
74 var targetLabels []string
75 target := &cobra.Command{
76 Use: "target",
77 Short: "stats target --target-labels",
78 Run: func(cmd *cobra.Command, args []string) {
79 from, to, err := getQueryTime(cmd)
80 if err != nil {
81 fmt.Fprintf(os.Stderr, "parse time error: %v\n", err)
82 return
83 }
84 if len(targetLabels) == 0 {
85 targetLabels = []string{"*"}
86 }
87 err = statsQuery(cmd, from, to, metric, targetLabels, nil)
88 if err != nil {
89 fmt.Fprintf(os.Stderr, "promql stats query error: %v\n", err)
90 }
91 },
92 }
93 target.Flags().StringArrayVarP(&targetLabels, "target-labels", "l", nil, "specific target labels for stats analysis, default: [all]")
94 stats.AddCommand(target)
95
96 var appLabels []string
97 app := &cobra.Command{
98 Use: "app",
99 Short: "stats app --app-labels",
100 Run: func(cmd *cobra.Command, args []string) {
101 from, to, err := getQueryTime(cmd)
102 if err != nil {
103 fmt.Fprintf(os.Stderr, "parse time error: %v\n", err)
104 return
105 }

Callers 1

RegisterPromQLCommandFunction · 0.85

Calls 2

getQueryTimeFunction · 0.85
statsQueryFunction · 0.85

Tested by

no test coverage detected