frostfs-node/scripts/export-metrics/main.go
Anton Nikiforov 994f48f8bb [#680] metrics: Export log and morph with script
Signed-off-by: Anton Nikiforov <an.nikiforov@yadro.com>
2023-10-11 17:08:03 +03:00

55 lines
1.1 KiB
Go

package main
import (
"encoding/json"
"flag"
"fmt"
"os"
local_metrics "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/metrics"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger"
"git.frostfs.info/TrueCloudLab/frostfs-observability/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 != "":
_ = local_metrics.NewNodeMetrics()
_ = logger.NewLogMetrics("frostfs_node")
filename = *node
case *ir != "":
_ = local_metrics.NewInnerRingMetrics()
_ = logger.NewLogMetrics("frostfs_ir")
filename = *ir
default:
flag.Usage()
os.Exit(1)
}
ds := metrics.DescribeAll()
data, err := json.Marshal(ds)
if err != nil {
fmt.Fprintf(os.Stderr, "Could not parse marshal: %v\n", err)
os.Exit(1)
}
if err := os.WriteFile(filename, data, 0644); err != nil {
fmt.Fprintf(os.Stderr, "Could write to file: %v\n", err)
os.Exit(1)
}
}