Some checks failed
DCO action / DCO (pull_request) Failing after 5m11s
Tests and linters / Staticcheck (pull_request) Failing after 5m3s
Vulncheck / Vulncheck (pull_request) Failing after 5m7s
Build / Build Components (1.21) (pull_request) Failing after 5m52s
Build / Build Components (1.20) (pull_request) Failing after 6m6s
Tests and linters / Lint (pull_request) Failing after 6m43s
Tests and linters / Tests (1.21) (pull_request) Failing after 8m1s
Tests and linters / Tests (1.20) (pull_request) Failing after 8m16s
Tests and linters / Tests with -race (pull_request) Failing after 8m17s
Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
85 lines
2 KiB
Go
85 lines
2 KiB
Go
package main
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/json"
|
|
"flag"
|
|
"fmt"
|
|
"os"
|
|
"sort"
|
|
"strings"
|
|
|
|
local_metrics "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/metrics"
|
|
"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.")
|
|
format = flag.String("format", "json", "Format to export in. Supported formats: json (default), md.")
|
|
)
|
|
|
|
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()
|
|
filename = *node
|
|
case *ir != "":
|
|
_ = local_metrics.NewInnerRingMetrics()
|
|
filename = *ir
|
|
|
|
default:
|
|
flag.Usage()
|
|
os.Exit(1)
|
|
}
|
|
|
|
var data []byte
|
|
var err error
|
|
|
|
ds := metrics.DescribeAll()
|
|
switch *format {
|
|
case "md":
|
|
sort.Slice(ds, func(i, j int) bool {
|
|
return ds[i].Name < ds[j].Name
|
|
})
|
|
b := bytes.NewBuffer(nil)
|
|
b.WriteString("# FrostFS Node prometheus metrics\n")
|
|
b.WriteString("Name | Description | Constant labels | Variable labels\n")
|
|
b.WriteString("-- | -- | -- | --\n")
|
|
for i := range ds {
|
|
constLabels := make([]string, 0, len(ds[i].ConstantLabels))
|
|
for key, value := range ds[i].ConstantLabels {
|
|
constLabels = append(constLabels, fmt.Sprintf("`%s=%s`", key, value))
|
|
}
|
|
|
|
// FIXME omg do it better
|
|
ss := make([]string, len(ds[i].VariableLabels))
|
|
copy(ss, ds[i].VariableLabels)
|
|
for i := range ss {
|
|
ss[i] = fmt.Sprintf("`%s`", ss[i])
|
|
}
|
|
varLabels := strings.Join(ss, "<br>")
|
|
fmt.Fprintf(b, "`%s` | %s | %s | %s\n", ds[i].Name, ds[i].Help, strings.Join(constLabels, "<br>"), varLabels)
|
|
}
|
|
data = b.Bytes()
|
|
default:
|
|
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, 0o644); err != nil {
|
|
fmt.Fprintf(os.Stderr, "Could write to file: %v\n", err)
|
|
os.Exit(1)
|
|
}
|
|
}
|