Allow to export metrics list to a file #214
1 changed files with 56 additions and 0 deletions
56
scripts/export-metrics/main.go
Normal file
56
scripts/export-metrics/main.go
Normal file
|
@ -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() {
|
||||||
fyrchik marked this conversation as resolved
Outdated
|
|||||||
|
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)
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue
What you think about having a couple of unit tests in metrics package that print list of metrics for IR and Storage into stdout instead of having a separate application? These tests can be ignored with build tag.
I like the idea, but I've thought we need to integrate it into some pipeline.
Probably some
go:generate
is enough, though.