scripts: Allow to export metrics in markdorn

Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
Evgenii Stratonikov 2024-01-31 10:28:14 +03:00
parent c916a75948
commit cb08bc85a9

View file

@ -1,18 +1,22 @@
package main package main
import ( import (
"bytes"
"encoding/json" "encoding/json"
"flag" "flag"
"fmt" "fmt"
"os" "os"
"sort"
"strings"
local_metrics "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/metrics" local_metrics "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/metrics"
"git.frostfs.info/TrueCloudLab/frostfs-observability/metrics" "git.frostfs.info/TrueCloudLab/frostfs-observability/metrics"
) )
var ( var (
node = flag.String("node", "", "File to export storage node metrics to.") node = flag.String("node", "", "File to export storage node metrics to.")
ir = flag.String("ir", "", "File to export innerring 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() { func main() {
@ -37,12 +41,34 @@ func main() {
os.Exit(1) os.Exit(1)
} }
ds := metrics.DescribeAll() var data []byte
var err error
data, err := json.Marshal(ds) ds := metrics.DescribeAll()
if err != nil { switch *format {
fmt.Fprintf(os.Stderr, "Could not parse marshal: %v\n", err) case "md":
os.Exit(1) 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))
}
varLabels := strings.Join(ds[i].VariableLabels, "; ")
fmt.Fprintf(b, "%s | %s | %s | %s\n", ds[i].Name, ds[i].Help, strings.Join(constLabels, "; "), 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 { if err := os.WriteFile(filename, data, 0o644); err != nil {