summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorAnton Titov <[email protected]>2019-06-25 18:44:26 +0300
committerGitHub <[email protected]>2019-06-25 18:44:26 +0300
commit85fd17edb61162ee1cdfb067c18cef73c54a00c8 (patch)
tree74705a56c0e8fc368f10d37c5a47a13daebfde29 /cmd
parentc8459e1e5933f8bf5bc25635ce13724d492e5ebe (diff)
parentbc99ebe7ec597cd8c137bc36b368e8fa0b4bcdac (diff)
Merge pull request #166 from ovr/limit-metrics
Feature: Add metrics to limit controller for rr_limit_max_execution_t…
Diffstat (limited to 'cmd')
-rw-r--r--cmd/rr/limit/metrics.go63
1 files changed, 63 insertions, 0 deletions
diff --git a/cmd/rr/limit/metrics.go b/cmd/rr/limit/metrics.go
new file mode 100644
index 00000000..947f53fe
--- /dev/null
+++ b/cmd/rr/limit/metrics.go
@@ -0,0 +1,63 @@
+package limit
+
+import (
+ "github.com/prometheus/client_golang/prometheus"
+ "github.com/spf13/cobra"
+ rr "github.com/spiral/roadrunner/cmd/rr/cmd"
+ rrlimit "github.com/spiral/roadrunner/service/limit"
+ "github.com/spiral/roadrunner/service/metrics"
+)
+
+func init() {
+ cobra.OnInitialize(func() {
+ svc, _ := rr.Container.Get(metrics.ID)
+ mtr, ok := svc.(*metrics.Service)
+ if !ok || !mtr.Enabled() {
+ return
+ }
+
+ ht, _ := rr.Container.Get(rrlimit.ID)
+ if ht, ok := ht.(*rrlimit.Service); ok {
+ collector := newCollector()
+
+ // register metrics
+ mtr.MustRegister(collector.maxMemory)
+
+ // collect events
+ ht.AddListener(collector.listener)
+ }
+ })
+}
+
+// listener provide debug callback for system events. With colors!
+type metricCollector struct {
+ maxMemory prometheus.Counter
+ maxExecutionTime prometheus.Counter
+}
+
+func newCollector() *metricCollector {
+ return &metricCollector{
+ maxMemory: prometheus.NewCounter(
+ prometheus.CounterOpts{
+ Name: "rr_limit_max_memory",
+ Help: "Total number of workers that was killed because they reached max memory limit.",
+ },
+ ),
+ maxExecutionTime: prometheus.NewCounter(
+ prometheus.CounterOpts{
+ Name: "rr_limit_max_execution_time",
+ Help: "Total number of workers that was killed because they reached max execution time limit.",
+ },
+ ),
+ }
+}
+
+// listener listens to http events and generates nice looking output.
+func (c *metricCollector) listener(event int, ctx interface{}) {
+ switch event {
+ case rrlimit.EventMaxMemory:
+ c.maxMemory.Inc()
+ case rrlimit.EventExecTTL:
+ c.maxExecutionTime.Inc()
+ }
+}