mirror of
https://github.com/prometheus/prometheus.git
synced 2024-12-26 22:19:40 -08:00
Merge pull request #90 from prometheus/feature/scraping/named-target-state
Improve the Representations of /status
This commit is contained in:
commit
bd7ec4d5e1
|
@ -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
|
||||||
|
|
|
@ -28,6 +28,19 @@ const (
|
||||||
// The state of the given Target.
|
// The state of the given Target.
|
||||||
type TargetState int
|
type TargetState int
|
||||||
|
|
||||||
|
func (t TargetState) String() string {
|
||||||
|
switch t {
|
||||||
|
case UNKNOWN:
|
||||||
|
return "UNKNOWN"
|
||||||
|
case ALIVE:
|
||||||
|
return "ALIVE"
|
||||||
|
case UNREACHABLE:
|
||||||
|
return "UNREACHABLE"
|
||||||
|
}
|
||||||
|
|
||||||
|
panic("unknown state")
|
||||||
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// The Target has not been seen; we know nothing about it, except that it is
|
// The Target has not been seen; we know nothing about it, except that it is
|
||||||
// on our docket for examination.
|
// on our docket for examination.
|
||||||
|
|
|
@ -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 a new issue