mirror of
https://github.com/prometheus/prometheus
synced 2025-02-05 06:37:38 +00:00
Improve the base label representation in /status.
The base label representation under /status needs improvement to enhance readability; namely, add sorting and make the label representation concise.
This commit is contained in:
parent
5a9417f80a
commit
05a9c3cd0b
@ -14,6 +14,7 @@
|
|||||||
package model
|
package model
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"crypto/md5"
|
"crypto/md5"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"fmt"
|
"fmt"
|
||||||
@ -44,6 +45,53 @@ type LabelValue string
|
|||||||
// match.
|
// match.
|
||||||
type LabelSet map[LabelName]LabelValue
|
type LabelSet map[LabelName]LabelValue
|
||||||
|
|
||||||
|
func (l LabelSet) String() string {
|
||||||
|
var (
|
||||||
|
buffer bytes.Buffer
|
||||||
|
labels LabelNames
|
||||||
|
labelCount int = len(l)
|
||||||
|
)
|
||||||
|
|
||||||
|
for name := range l {
|
||||||
|
labels = append(labels, name)
|
||||||
|
}
|
||||||
|
|
||||||
|
sort.Sort(labels)
|
||||||
|
|
||||||
|
fmt.Fprintf(&buffer, "{")
|
||||||
|
for i := 0; i < labelCount; i++ {
|
||||||
|
var (
|
||||||
|
label = labels[i]
|
||||||
|
value = l[label]
|
||||||
|
)
|
||||||
|
|
||||||
|
switch i {
|
||||||
|
case labelCount - 1:
|
||||||
|
fmt.Fprintf(&buffer, "%s=%s", label, value)
|
||||||
|
default:
|
||||||
|
fmt.Fprintf(&buffer, "%s=%s, ", label, value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Fprintf(&buffer, "}")
|
||||||
|
|
||||||
|
return buffer.String()
|
||||||
|
}
|
||||||
|
|
||||||
|
type LabelNames []LabelName
|
||||||
|
|
||||||
|
func (l LabelNames) Len() int {
|
||||||
|
return len(l)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l LabelNames) Less(i, j int) bool {
|
||||||
|
return l[i] < l[j]
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l LabelNames) Swap(i, j int) {
|
||||||
|
l[i], l[j] = l[j], l[i]
|
||||||
|
}
|
||||||
|
|
||||||
// A Metric is similar to a LabelSet, but the key difference is that a Metric is
|
// A Metric is similar to a LabelSet, but the key difference is that a Metric is
|
||||||
// a singleton and refers to one and only one stream of samples.
|
// a singleton and refers to one and only one stream of samples.
|
||||||
type Metric map[LabelName]LabelValue
|
type Metric map[LabelName]LabelValue
|
||||||
|
@ -33,7 +33,7 @@
|
|||||||
<ul>
|
<ul>
|
||||||
{{range $pool.Targets}}
|
{{range $pool.Targets}}
|
||||||
<li>
|
<li>
|
||||||
<a href="{{.Address}}">{{.Address}}</a> (State: {{.State}}, Base labels: {{.BaseLabels}})
|
<a href="{{.Address}}">{{.Address}}</a> (State: {{.State}}, Base Labels: {{.BaseLabels}})
|
||||||
</li>
|
</li>
|
||||||
{{end}}
|
{{end}}
|
||||||
</ul>
|
</ul>
|
||||||
|
Loading…
Reference in New Issue
Block a user