aboutsummaryrefslogtreecommitdiff
path: root/pkg/metricsx/metricsx.go
diff options
context:
space:
mode:
authorpg9182 <96569817+pg9182@users.noreply.github.com>2022-11-26 22:51:50 -0500
committerpg9182 <96569817+pg9182@users.noreply.github.com>2022-11-27 02:48:10 -0500
commite3cdce7ada2be1fdf77a5e15130b4fcef3045c26 (patch)
tree2eb31961f58c88126e85a4db9806ce518c22f205 /pkg/metricsx/metricsx.go
parent880acd082d0d184144e3efd066a63c8e53e22ae5 (diff)
downloadAtlas-e3cdce7ada2be1fdf77a5e15130b4fcef3045c26.tar.gz
Atlas-e3cdce7ada2be1fdf77a5e15130b4fcef3045c26.zip
pkg/metricsx: Initial commit
Diffstat (limited to 'pkg/metricsx/metricsx.go')
-rw-r--r--pkg/metricsx/metricsx.go39
1 files changed, 39 insertions, 0 deletions
diff --git a/pkg/metricsx/metricsx.go b/pkg/metricsx/metricsx.go
new file mode 100644
index 0000000..bc37843
--- /dev/null
+++ b/pkg/metricsx/metricsx.go
@@ -0,0 +1,39 @@
+// Package metricsx extends github.com/VictoriaMetrics/metrics.
+package metricsx
+
+import "strings"
+
+func splitName(name string) (base, arg string) {
+ if n := len(name); n != 0 {
+ base = name
+ for i, r := range base {
+ if r == '{' {
+ if j := len(base) - 1; j > i && base[j] == '}' {
+ base, arg = base[:i], base[i+1:j]
+ break
+ }
+ }
+ }
+ }
+ return
+}
+
+func formatName(base, arg string, args ...string) string {
+ var b strings.Builder
+ b.WriteString(base)
+ b.WriteByte('{')
+ if arg != "" {
+ b.WriteString(arg)
+ }
+ for i := 1; i < len(args); i += 2 {
+ if arg != "" || i > 1 {
+ b.WriteByte(',')
+ }
+ b.WriteString(args[i-1])
+ b.WriteString("=\"")
+ b.WriteString(args[i])
+ b.WriteByte('"')
+ }
+ b.WriteByte('}')
+ return b.String()
+}