Show loaded rules in Status dashboard.

This commit is contained in:
Julius Volz 2013-06-11 11:00:55 +02:00
parent fc97e688c6
commit ba29d07901
4 changed files with 22 additions and 11 deletions

18
main.go
View file

@ -212,6 +212,14 @@ func main() {
targetManager := retrieval.NewTargetManager(scrapeResults, *concurrentRetrievalAllowance)
targetManager.AddTargetsFromConfig(conf)
// Queue depth will need to be exposed
ruleManager := rules.NewRuleManager(ruleResults, conf.EvaluationInterval(), ts)
err = ruleManager.AddRulesFromConfig(conf)
if err != nil {
log.Fatalf("Error loading rule files: %v", err)
}
go ruleManager.Run()
flags := map[string]string{}
flag.VisitAll(func(f *flag.Flag) {
@ -222,6 +230,7 @@ func main() {
PrometheusStatus: &web.PrometheusStatus{
BuildInfo: BuildInfo,
Config: conf.String(),
Rules: ruleManager.Rules(),
TargetPools: targetManager.Pools(),
Flags: flags,
Birth: time.Now(),
@ -321,15 +330,6 @@ func main() {
}
}()
// Queue depth will need to be exposed
ruleManager := rules.NewRuleManager(ruleResults, conf.EvaluationInterval(), ts)
err = ruleManager.AddRulesFromConfig(conf)
if err != nil {
log.Fatalf("Error loading rule files: %v", err)
}
go ruleManager.Run()
go func() {
err := webService.ServeForever()
if err != nil {

View file

@ -30,6 +30,7 @@ type Result struct {
type RuleManager interface {
AddRulesFromConfig(config config.Config) error
Run()
Rules() []Rule
}
type ruleManager struct {
@ -117,3 +118,12 @@ func (m *ruleManager) AddRulesFromConfig(config config.Config) error {
}
return nil
}
func (m *ruleManager) Rules() []Rule {
m.Lock()
defer m.Unlock()
rules := make([]Rule, len(m.rules))
copy(rules, m.rules)
return rules
}

View file

@ -15,6 +15,7 @@ package web
import (
"github.com/prometheus/prometheus/retrieval"
"github.com/prometheus/prometheus/rules"
"github.com/prometheus/prometheus/storage/metric"
"net/http"
"sync"
@ -26,7 +27,7 @@ type PrometheusStatus struct {
Config string
Curation metric.CurationState
Flags map[string]string
Rules string
Rules []rules.Rule
TargetPools map[string]*retrieval.TargetPool
Birth time.Time

View file

@ -35,7 +35,7 @@
<h2>Rules</h2>
<div class="grouping_box">
{{.Rules}}
<pre>{{range .Rules}}{{.String}}{{end}}</pre>
</div>
<h2>Targets</h2>