From 152b1b739148473ec47748eff80c34261a0cd8a2 Mon Sep 17 00:00:00 2001
From: Frederic Branczyk <fbranczyk@gmail.com>
Date: Wed, 4 Oct 2017 12:41:41 +0200
Subject: [PATCH] add metric of alertmanager position in mesh

---
 cmd/alertmanager/main.go | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/cmd/alertmanager/main.go b/cmd/alertmanager/main.go
index 639d6827ab..2026370c4d 100644
--- a/cmd/alertmanager/main.go
+++ b/cmd/alertmanager/main.go
@@ -51,6 +51,10 @@ import (
 )
 
 var (
+	peerPosition = prometheus.NewGauge(prometheus.GaugeOpts{
+		Name: "alertmanager_peer_position",
+		Help: "Position the Alertmanager instance believes it's in. The position determines a peer's behavior in the cluster.",
+	})
 	configHash = prometheus.NewGauge(prometheus.GaugeOpts{
 		Name: "alertmanager_config_hash",
 		Help: "Hash of the currently loaded alertmanager configuration.",
@@ -66,6 +70,7 @@ var (
 )
 
 func init() {
+	prometheus.MustRegister(peerPosition)
 	prometheus.MustRegister(configSuccess)
 	prometheus.MustRegister(configSuccessTime)
 	prometheus.MustRegister(configHash)
@@ -359,7 +364,7 @@ func meshWait(r *mesh.Router, timeout time.Duration) func() time.Duration {
 			}
 			k++
 		}
-		// TODO(fabxc): add metric exposing the "position" from AM's own view.
+		peerPosition.Set(float64(k))
 		return time.Duration(k) * timeout
 	}
 }