Browse Source

Add command type as a label

pull/91/head
Kegan Dougal 8 years ago
parent
commit
cdb49fa60b
  1. 34
      src/github.com/matrix-org/go-neb/metrics/metrics.go
  2. 6
      src/github.com/matrix-org/go-neb/plugin/plugin.go

34
src/github.com/matrix-org/go-neb/metrics/metrics.go

@ -9,35 +9,35 @@ type CommandStatus int
// The command status values // The command status values
const ( const (
Pending CommandStatus = iota
Success
Failure
StatusPending CommandStatus = iota
StatusSuccess
StatusFailure
) )
var ( var (
numIncomingCmds = prometheus.NewCounter(prometheus.CounterOpts{
numIncomingCmds = prometheus.NewCounterVec(prometheus.CounterOpts{
Name: "num_incoming_commands_total", Name: "num_incoming_commands_total",
Help: "The number of incoming commands from matrix clients", 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", Name: "num_success_commands_total",
Help: "The number of incoming commands from matrix clients which were successful", 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", Name: "num_error_commands_total",
Help: "The number of incoming commands from matrix clients which failed", 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 { 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()
} }
} }

6
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, "user_id": event.Sender,
"command": bestMatch.Path, "command": bestMatch.Path,
}).Info("Executing command") }).Info("Executing command")
metrics.IncrementCommand(metrics.Pending)
metrics.IncrementCommand(bestMatch.Path[0], metrics.StatusPending)
content, err := bestMatch.Command(event.RoomID, event.Sender, cmdArgs) content, err := bestMatch.Command(event.RoomID, event.Sender, cmdArgs)
if err != nil { if err != nil {
if content != nil { if content != nil {
@ -84,10 +84,10 @@ func runCommandForPlugin(plugin Plugin, event *matrix.Event, arguments []string)
"args": cmdArgs, "args": cmdArgs,
}).Warn("Command returned both error and content.") }).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()} content = matrix.TextMessage{"m.notice", err.Error()}
} else { } else {
metrics.IncrementCommand(metrics.Success)
metrics.IncrementCommand(bestMatch.Path[0], metrics.StatusSuccess)
} }
return content return content

Loading…
Cancel
Save