From cdb49fa60b12a07c6e68f7d9f2fb0ad8f3230dc2 Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Mon, 17 Oct 2016 11:11:43 +0100 Subject: [PATCH] Add command type as a label --- .../matrix-org/go-neb/metrics/metrics.go | 34 +++++++++---------- .../matrix-org/go-neb/plugin/plugin.go | 6 ++-- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/github.com/matrix-org/go-neb/metrics/metrics.go b/src/github.com/matrix-org/go-neb/metrics/metrics.go index 0711635..f9f80c4 100644 --- a/src/github.com/matrix-org/go-neb/metrics/metrics.go +++ b/src/github.com/matrix-org/go-neb/metrics/metrics.go @@ -9,35 +9,35 @@ type CommandStatus int // The command status values const ( - Pending CommandStatus = iota - Success - Failure + StatusPending CommandStatus = iota + StatusSuccess + StatusFailure ) var ( - numIncomingCmds = prometheus.NewCounter(prometheus.CounterOpts{ + numIncomingCmds = prometheus.NewCounterVec(prometheus.CounterOpts{ Name: "num_incoming_commands_total", Help: "The number of incoming commands from matrix clients", - }) - numSuccessCmds = prometheus.NewCounter(prometheus.CounterOpts{ + }, []string{"cmd"}) + numSuccessCmds = prometheus.NewCounterVec(prometheus.CounterOpts{ Name: "num_success_commands_total", Help: "The number of incoming commands from matrix clients which were successful", - }) - numErrorCmds = prometheus.NewCounter(prometheus.CounterOpts{ + }, []string{"cmd"}) + numErrorCmds = prometheus.NewCounterVec(prometheus.CounterOpts{ Name: "num_error_commands_total", Help: "The number of incoming commands from matrix clients which failed", - }) + }, []string{"cmd"}) ) -// IncrementCommand increments the incoming command counter (TODO: cmd type) -func IncrementCommand(st CommandStatus) { +// IncrementCommand increments the incoming command counter +func IncrementCommand(cmdName string, st CommandStatus) { switch st { - case Pending: - numIncomingCmds.Inc() - case Success: - numSuccessCmds.Inc() - case Failure: - numErrorCmds.Inc() + case StatusPending: + numIncomingCmds.With(prometheus.Labels{"cmd": cmdName}).Inc() + case StatusSuccess: + numSuccessCmds.With(prometheus.Labels{"cmd": cmdName}).Inc() + case StatusFailure: + numErrorCmds.With(prometheus.Labels{"cmd": cmdName}).Inc() } } diff --git a/src/github.com/matrix-org/go-neb/plugin/plugin.go b/src/github.com/matrix-org/go-neb/plugin/plugin.go index a55afaf..0f170c0 100644 --- a/src/github.com/matrix-org/go-neb/plugin/plugin.go +++ b/src/github.com/matrix-org/go-neb/plugin/plugin.go @@ -72,7 +72,7 @@ func runCommandForPlugin(plugin Plugin, event *matrix.Event, arguments []string) "user_id": event.Sender, "command": bestMatch.Path, }).Info("Executing command") - metrics.IncrementCommand(metrics.Pending) + metrics.IncrementCommand(bestMatch.Path[0], metrics.StatusPending) content, err := bestMatch.Command(event.RoomID, event.Sender, cmdArgs) if err != nil { if content != nil { @@ -84,10 +84,10 @@ func runCommandForPlugin(plugin Plugin, event *matrix.Event, arguments []string) "args": cmdArgs, }).Warn("Command returned both error and content.") } - metrics.IncrementCommand(metrics.Failure) + metrics.IncrementCommand(bestMatch.Path[0], metrics.StatusFailure) content = matrix.TextMessage{"m.notice", err.Error()} } else { - metrics.IncrementCommand(metrics.Success) + metrics.IncrementCommand(bestMatch.Path[0], metrics.StatusSuccess) } return content