From c70306b3240bc265b11dddaf4c1f04d68970bad3 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Wed, 5 Apr 2023 13:47:40 +0300 Subject: [PATCH] [#164] scripts: Add metrics description exporter Signed-off-by: Evgenii Stratonikov --- scripts/export-metrics/main.go | 56 ++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 scripts/export-metrics/main.go diff --git a/scripts/export-metrics/main.go b/scripts/export-metrics/main.go new file mode 100644 index 000000000..ac6e786ab --- /dev/null +++ b/scripts/export-metrics/main.go @@ -0,0 +1,56 @@ +package main + +import ( + "encoding/json" + "flag" + "fmt" + "io/ioutil" + "os" + + "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/metrics" +) + +var ( + node = flag.String("node", "", "File to export storage node metrics to.") + ir = flag.String("ir", "", "File to export innerring node metrics to.") +) + +func main() { + flag.Parse() + + if *node != "" && *ir != "" { + fmt.Println("-node and -ir flags are mutually exclusive") + os.Exit(1) + } + + var filename string + switch { + case *node != "": + _ = metrics.NewNodeMetrics() + filename = *node + case *ir != "": + _ = metrics.NewInnerRingMetrics() + filename = *ir + + default: + flag.Usage() + os.Exit(1) + } + + ds, err := metrics.DescribeAll() + if err != nil { + fmt.Fprintf(os.Stderr, "Could not parse metric descriptions: %v\n", err) + os.Exit(1) + } + + data, err := json.Marshal(ds) + if err != nil { + fmt.Fprintf(os.Stderr, "Could not parse marshal: %v\n", err) + os.Exit(1) + } + + if err := ioutil.WriteFile(filename, data, 0644); err != nil { + fmt.Fprintf(os.Stderr, "Could write to file: %v\n", err) + os.Exit(1) + } +}