Browse Source

Add extremely noddy counter metrics for !commands

Missing the command type currently. Also, not sure how "nice" this is: we could
probably blob the 3 functions into 1 and use an enum but, meh?
kegan/neb-metrics
Kegan Dougal 8 years ago
parent
commit
219da01e08
  1. 1
      src/github.com/matrix-org/go-neb/goneb.go
  2. 41
      src/github.com/matrix-org/go-neb/metrics/metrics.go
  3. 5
      src/github.com/matrix-org/go-neb/plugin/plugin.go

1
src/github.com/matrix-org/go-neb/goneb.go

@ -5,6 +5,7 @@ import (
"github.com/matrix-org/dugong"
"github.com/matrix-org/go-neb/clients"
"github.com/matrix-org/go-neb/database"
_ "github.com/matrix-org/go-neb/metrics"
"github.com/matrix-org/go-neb/polling"
_ "github.com/matrix-org/go-neb/realms/github"
_ "github.com/matrix-org/go-neb/realms/jira"

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

@ -0,0 +1,41 @@
package metrics
import (
"github.com/prometheus/client_golang/prometheus"
)
var (
numIncomingCmds = prometheus.NewCounter(prometheus.CounterOpts{
Name: "num_incoming_commands_total",
Help: "The number of incoming commands from matrix clients",
})
numSuccessCmds = prometheus.NewCounter(prometheus.CounterOpts{
Name: "num_success_commands_total",
Help: "The number of incoming commands from matrix clients which were successful",
})
numErrorCmds = prometheus.NewCounter(prometheus.CounterOpts{
Name: "num_error_commands_total",
Help: "The number of incoming commands from matrix clients which failed",
})
)
// 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()
}
func init() {
prometheus.MustRegister(numIncomingCmds)
prometheus.MustRegister(numSuccessCmds)
prometheus.MustRegister(numErrorCmds)
}

5
src/github.com/matrix-org/go-neb/plugin/plugin.go

@ -3,6 +3,7 @@ package plugin
import (
log "github.com/Sirupsen/logrus"
"github.com/matrix-org/go-neb/matrix"
"github.com/matrix-org/go-neb/metrics"
"github.com/mattn/go-shellwords"
"regexp"
"strings"
@ -71,6 +72,7 @@ func runCommandForPlugin(plugin Plugin, event *matrix.Event, arguments []string)
"user_id": event.Sender,
"command": bestMatch.Path,
}).Info("Executing command")
metrics.IncIncomingCommand()
content, err := bestMatch.Command(event.RoomID, event.Sender, cmdArgs)
if err != nil {
if content != nil {
@ -82,7 +84,10 @@ func runCommandForPlugin(plugin Plugin, event *matrix.Event, arguments []string)
"args": cmdArgs,
}).Warn("Command returned both error and content.")
}
metrics.IncErrorCommand()
content = matrix.TextMessage{"m.notice", err.Error()}
} else {
metrics.IncSuccessCommand()
}
return content

Loading…
Cancel
Save