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 d7e30c0..178a238 100644 --- a/src/github.com/matrix-org/go-neb/metrics/metrics.go +++ b/src/github.com/matrix-org/go-neb/metrics/metrics.go @@ -4,6 +4,14 @@ import ( "github.com/prometheus/client_golang/prometheus" ) +type CommandStatus int + +const ( + Pending CommandStatus = iota + Success + Failure +) + var ( numIncomingCmds = prometheus.NewCounter(prometheus.CounterOpts{ Name: "num_incoming_commands_total", @@ -19,19 +27,16 @@ var ( }) ) -// IncIncomingCommand increments the incoming command counter (TODO: cmd type) -func IncIncomingCommand() { - numIncomingCmds.Inc() -} - -// IncSuccessCommand increments the success command counter (TODO: cmd type) -func IncSuccessCommand() { - numSuccessCmds.Inc() -} - -// IncErrorCommand increments the error command counter (TODO: cmd type) -func IncErrorCommand() { - numErrorCmds.Inc() +// IncrementCommand increments the incoming command counter (TODO: cmd type) +func IncrementCommand(st CommandStatus) { + switch st { + case Pending: + numIncomingCmds.Inc() + case Success: + numSuccessCmds.Inc() + case Failure: + numErrorCmds.Inc() + } } func init() { 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 02b0467..a55afaf 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.IncIncomingCommand() + metrics.IncrementCommand(metrics.Pending) 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.IncErrorCommand() + metrics.IncrementCommand(metrics.Failure) content = matrix.TextMessage{"m.notice", err.Error()} } else { - metrics.IncSuccessCommand() + metrics.IncrementCommand(metrics.Success) } return content