-
Notifications
You must be signed in to change notification settings - Fork 24
/
metricsToDash.go
80 lines (69 loc) · 3.6 KB
/
metricsToDash.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package metricsToDash
import (
"fmt"
_ "embed"
"github.com/maticnetwork/polygon-cli/dashboard"
"github.com/spf13/cobra"
)
var (
//go:embed usage.md
usage string
inputMetricsToDashFile *string
inputMetricsToDashPrefix *string
inputMetricsToDashTitle *string
inputMetricsToDashDesc *string
inputMetricsToDashHeight *int
inputMetricsToDashWidth *int
inputMetricsToDashTemplateVars *[]string
inputMetricsToDashTemplateVarDefaults *[]string
inputMetricsToDashStripPrefixes *[]string
inputMetricsToDashPretty *bool
inputMetricsToDashShowHelp *bool
)
// MetricsToDashCmd represents the metricsToDash command
var MetricsToDashCmd = &cobra.Command{
Use: "metrics-to-dash",
Aliases: []string{"metricstodash", "metricsToDash"},
Short: "Create a dashboard from an Openmetrics / Prometheus response.",
Long: usage,
RunE: func(cmd *cobra.Command, args []string) error {
do := dashboard.DashboardOptions{
File: *inputMetricsToDashFile,
Title: *inputMetricsToDashTitle,
Prefix: *inputMetricsToDashPrefix,
Description: *inputMetricsToDashDesc,
WidgetHeight: *inputMetricsToDashHeight,
WidgetWidth: *inputMetricsToDashWidth,
TemplateVars: *inputMetricsToDashTemplateVars,
TemplateVarDefaults: *inputMetricsToDashTemplateVarDefaults,
StripPrefixes: *inputMetricsToDashStripPrefixes,
Pretty: *inputMetricsToDashPretty,
ShowHelp: *inputMetricsToDashShowHelp,
}
data, err := dashboard.ConvertMetricsToDashboard(&do)
if err != nil {
return err
}
fmt.Println(string(data))
return nil
},
}
func init() {
// Here you will define your flags and configuration settings.
// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
inputMetricsToDashFile = MetricsToDashCmd.PersistentFlags().StringP("input-file", "i", "", "the metrics file to be used")
inputMetricsToDashPrefix = MetricsToDashCmd.PersistentFlags().StringP("prefix", "p", "", "prefix to use before all metrics")
inputMetricsToDashTitle = MetricsToDashCmd.PersistentFlags().StringP("title", "t", "Polycli Dashboard", "title for the dashboard")
inputMetricsToDashDesc = MetricsToDashCmd.PersistentFlags().StringP("desc", "d", "Polycli Dashboard", "description for the dashboard")
inputMetricsToDashWidth = MetricsToDashCmd.PersistentFlags().IntP("width", "W", 4, "widget width")
inputMetricsToDashHeight = MetricsToDashCmd.PersistentFlags().IntP("height", "H", 3, "widget height")
inputMetricsToDashTemplateVars = MetricsToDashCmd.PersistentFlags().StringArrayP("template-vars", "T", []string{}, "The template variables to use for the dashboard")
inputMetricsToDashTemplateVarDefaults = MetricsToDashCmd.PersistentFlags().StringArrayP("template-var-defaults", "D", []string{}, "The defaults to use for the template variables")
inputMetricsToDashStripPrefixes = MetricsToDashCmd.PersistentFlags().StringArrayP("strip-prefix", "s", []string{}, "A prefix that can be removed from the metrics")
inputMetricsToDashPretty = MetricsToDashCmd.PersistentFlags().BoolP("pretty-name", "P", true, "Should the metric names be prettified")
inputMetricsToDashShowHelp = MetricsToDashCmd.PersistentFlags().BoolP("show-help", "S", false, "Should we show the help text for each metric")
// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// MetricsToDashCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}