api: Expose mesh status (#644)
* api: Expose mesh status The weaveworks mesh package reveals information about the current status of the mesh network between alertmanager instances. This commit exposes the current address and connection status of each instance connected to the targeted alertmanager instance via the /status API endpoint. * api: Replace LocalConnectionStatus with PeerStatus Now meshStatus contains all peers (Name, NickName, UID) of the network. Additionally adding Name and Nickname of current target to toplevel of meshNetwork object.
This commit is contained in:
parent
00e3b98614
commit
fced9e126b
38
api/api.go
38
api/api.go
|
@ -34,6 +34,7 @@ import (
|
|||
"github.com/prometheus/alertmanager/silence"
|
||||
"github.com/prometheus/alertmanager/silence/silencepb"
|
||||
"github.com/prometheus/alertmanager/types"
|
||||
"github.com/weaveworks/mesh"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -77,6 +78,7 @@ type API struct {
|
|||
configJSON config.Config
|
||||
resolveTimeout time.Duration
|
||||
uptime time.Time
|
||||
mrouter *mesh.Router
|
||||
|
||||
groups func() dispatch.AlertOverview
|
||||
|
||||
|
@ -86,13 +88,14 @@ type API struct {
|
|||
}
|
||||
|
||||
// New returns a new API.
|
||||
func New(alerts provider.Alerts, silences *silence.Silences, gf func() dispatch.AlertOverview) *API {
|
||||
func New(alerts provider.Alerts, silences *silence.Silences, gf func() dispatch.AlertOverview, router *mesh.Router) *API {
|
||||
return &API{
|
||||
context: route.Context,
|
||||
alerts: alerts,
|
||||
silences: silences,
|
||||
groups: gf,
|
||||
uptime: time.Now(),
|
||||
mrouter: router,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -169,6 +172,7 @@ func (api *API) status(w http.ResponseWriter, req *http.Request) {
|
|||
ConfigJSON config.Config `json:"configJSON"`
|
||||
VersionInfo map[string]string `json:"versionInfo"`
|
||||
Uptime time.Time `json:"uptime"`
|
||||
MeshStatus meshStatus `json:"meshStatus"`
|
||||
}{
|
||||
Config: api.config,
|
||||
ConfigJSON: api.configJSON,
|
||||
|
@ -181,6 +185,7 @@ func (api *API) status(w http.ResponseWriter, req *http.Request) {
|
|||
"goVersion": version.GoVersion,
|
||||
},
|
||||
Uptime: api.uptime,
|
||||
MeshStatus: getMeshStatus(api),
|
||||
}
|
||||
|
||||
api.mtx.RUnlock()
|
||||
|
@ -188,6 +193,37 @@ func (api *API) status(w http.ResponseWriter, req *http.Request) {
|
|||
respond(w, status)
|
||||
}
|
||||
|
||||
type meshStatus struct {
|
||||
Name string `json:"name"`
|
||||
NickName string `json:"nickName"`
|
||||
Peers []peerStatus `json:"peers"`
|
||||
}
|
||||
|
||||
type peerStatus struct {
|
||||
Name string `json:"name"` // e.g. "00:00:00:00:00:01"
|
||||
NickName string `json:"nickName"` // e.g. "a"
|
||||
UID uint64 `json:"uid"` // e.g. "14015114173033265000"
|
||||
}
|
||||
|
||||
func getMeshStatus(api *API) meshStatus {
|
||||
status := mesh.NewStatus(api.mrouter)
|
||||
strippedStatus := meshStatus{
|
||||
Name: status.Name,
|
||||
NickName: status.NickName,
|
||||
Peers: make([]peerStatus, len(status.Peers)),
|
||||
}
|
||||
|
||||
for i := 0; i < len(status.Peers); i++ {
|
||||
strippedStatus.Peers[i] = peerStatus{
|
||||
Name: status.Peers[i].Name,
|
||||
NickName: status.Peers[i].NickName,
|
||||
UID: uint64(status.Peers[i].UID),
|
||||
}
|
||||
}
|
||||
|
||||
return strippedStatus
|
||||
}
|
||||
|
||||
func (api *API) alertGroups(w http.ResponseWriter, req *http.Request) {
|
||||
respond(w, api.groups())
|
||||
}
|
||||
|
|
|
@ -180,7 +180,7 @@ func main() {
|
|||
|
||||
apiv := api.New(alerts, silences, func() dispatch.AlertOverview {
|
||||
return disp.Groups()
|
||||
})
|
||||
}, mrouter)
|
||||
|
||||
amURL, err := extURL(*listenAddress, *externalURL)
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in New Issue