Show status and build information under /status.

Also add Makefile infrastructure for gathering status information.

Change-Id: Id7dcb9655d0b6024bf47d5dd41a7655df3635922
This commit is contained in:
Julius Volz 2013-08-14 14:02:57 +02:00
parent add9eb231d
commit 02b970b149
5 changed files with 143 additions and 4 deletions

36
Makefile Normal file
View File

@ -0,0 +1,36 @@
# -*- Mode: makefile -*-
# Copyright 2013 Prometheus Team
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
include Makefile.INCLUDE
all: build test
build: config web
$(GO) build $(BUILDFLAGS)
config:
$(MAKE) -C config
web:
$(MAKE) -C web
test: build
$(GO) test -v ./...
clean:
$(MAKE) -C web clean
-rm alertmanager
.PHONY: clean config web

31
Makefile.INCLUDE Normal file
View File

@ -0,0 +1,31 @@
# -*- Mode: makefile -*-
# Copyright 2013 Prometheus Team
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
.SUFFIXES:
GO := $(GOROOT)/bin/go
GOFMT := $(GOROOT)/bin/gofmt
GO_VERSION := 1.1
REV := $(shell git rev-parse --short HEAD)
BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
HOSTNAME := $(shell hostname -f)
BUILD_DATE := $(shell date +%Y%m%d-%H:%M:%S)
BUILDFLAGS := -ldflags \
"-X main.buildVersion $(REV)\
-X main.buildBranch $(BRANCH)\
-X main.buildUser $(USER)@$(HOSTNAME)\
-X main.buildDate $(BUILD_DATE)\
-X main.goVersion $(GO_VERSION)"

17
main.go
View File

@ -16,6 +16,7 @@ package main
import (
"flag"
"log"
"os"
"time"
"github.com/prometheus/alertmanager/config"
@ -32,6 +33,8 @@ var (
func main() {
flag.Parse()
versionInfoTmpl.Execute(os.Stdout, BuildInfo)
conf := config.MustLoadFromFile(*configFile)
silencer := manager.NewSilencer()
@ -57,6 +60,18 @@ func main() {
aggregator := manager.NewAggregator(notifier)
defer aggregator.Close()
flags := map[string]string{}
flag.VisitAll(func(f *flag.Flag) {
flags[f.Name] = f.Value.String()
})
statusHandler := &web.StatusHandler{
Config: conf.String(),
Flags: flags,
BuildInfo: BuildInfo,
Birth: time.Now(),
}
webService := &web.WebService{
// REST API Service.
AlertManagerService: &api.AlertManagerService{
@ -72,6 +87,7 @@ func main() {
SilencesHandler: &web.SilencesHandler{
Silencer: silencer,
},
StatusHandler: statusHandler,
}
go webService.ServeForever()
@ -81,6 +97,7 @@ func main() {
go watcher.Watch(func(conf *config.Config) {
notifier.SetNotificationConfigs(conf.NotificationConfig)
aggregator.SetRules(conf.AggregationRules())
statusHandler.UpdateConfig(conf.String())
})
log.Println("Running summary dispatcher...")

View File

@ -15,10 +15,29 @@ package web
import (
"net/http"
"sync"
"time"
)
type StatusHandler struct{}
type StatusHandler struct {
mu sync.Mutex
BuildInfo map[string]string
Config string
Flags map[string]string
Birth time.Time
}
func (h *StatusHandler) UpdateConfig(c string) {
h.mu.Lock()
defer h.mu.Unlock()
h.Config = c
}
func (h *StatusHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
executeTemplate(w, "status", nil)
h.mu.Lock()
defer h.mu.Unlock()
executeTemplate(w, "status", h)
}

View File

@ -3,6 +3,42 @@
{{define "head"}}{{end}}
{{define "content"}}
<h2>Status</h2>
Everything is going according to plan. Excellent. Move on.
<div class="container-fluid">
<h2>Runtime Information</h2>
<table class="table table-condensed table-bordered table-striped table-hover">
<tbody>
<tr>
<th>Uptime</th>
<td>{{.Birth}}</td>
</tr>
</tbody>
</table>
<h2>Build Information</h2>
<table class="table table-condensed table-bordered table-striped table-hover">
<tbody>
{{range $key, $value := .BuildInfo}}
<tr>
<th scope="row">{{$key}}</th>
<td>{{$value}}</td>
</tr>
{{end}}
</tbody>
</table>
<h2>Configuration</h2>
<pre>{{.Config}}</pre>
<h2>Startup Flags</h2>
<table class="table table-condensed table-bordered table-striped table-hover">
<tbody>
{{range $key, $value := .Flags}}
<tr>
<th scope="row">{{$key}}</th>
<td>{{$value}}</td>
</tr>
{{end}}
</tbody>
</table>
</div>
{{end}}