scripts: Allow to export metrics in markdorn
Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
parent
c916a75948
commit
cb08bc85a9
1 changed files with 33 additions and 7 deletions
|
@ -1,10 +1,13 @@
|
|||
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"
|
||||
|
@ -13,6 +16,7 @@ import (
|
|||
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() {
|
||||
|
@ -37,13 +41,35 @@ func main() {
|
|||
os.Exit(1)
|
||||
}
|
||||
|
||||
ds := metrics.DescribeAll()
|
||||
var data []byte
|
||||
var err error
|
||||
|
||||
data, err := json.Marshal(ds)
|
||||
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))
|
||||
}
|
||||
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 {
|
||||
fmt.Fprintf(os.Stderr, "Could write to file: %v\n", err)
|
||||
|
|
Loading…
Reference in a new issue