summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorWolfy-J <[email protected]>2019-06-26 13:03:39 +0300
committerWolfy-J <[email protected]>2019-06-26 13:03:39 +0300
commit1fe259d1fba89732abe0229ce5b8c133b7a75981 (patch)
treeb1e00e084ccd91514c82b726cf2451d28d3c272d /cmd
parent85fd17edb61162ee1cdfb067c18cef73c54a00c8 (diff)
worker memory usage tracking for http
Diffstat (limited to 'cmd')
-rw-r--r--cmd/rr/http/metrics.go45
1 files changed, 41 insertions, 4 deletions
diff --git a/cmd/rr/http/metrics.go b/cmd/rr/http/metrics.go
index f9d3c079..32e4a6cd 100644
--- a/cmd/rr/http/metrics.go
+++ b/cmd/rr/http/metrics.go
@@ -6,7 +6,9 @@ import (
rr "github.com/spiral/roadrunner/cmd/rr/cmd"
rrhttp "github.com/spiral/roadrunner/service/http"
"github.com/spiral/roadrunner/service/metrics"
+ "github.com/spiral/roadrunner/util"
"strconv"
+ "time"
)
func init() {
@@ -24,9 +26,13 @@ func init() {
// register metrics
mtr.MustRegister(collector.requestCounter)
mtr.MustRegister(collector.requestDuration)
+ mtr.MustRegister(collector.workersMemory)
// collect events
ht.AddListener(collector.listener)
+
+ // update memory usage every 10 seconds
+ go collector.collectMemory(ht, time.Second*10)
}
})
}
@@ -35,25 +41,31 @@ func init() {
type metricCollector struct {
requestCounter *prometheus.CounterVec
requestDuration *prometheus.HistogramVec
+ workersMemory prometheus.Gauge
}
func newCollector() *metricCollector {
return &metricCollector{
requestCounter: prometheus.NewCounterVec(
prometheus.CounterOpts{
- Name: "rr_http_total",
+ Name: "rr_http_request_total",
Help: "Total number of handled http requests after server restart.",
},
[]string{"status"},
),
requestDuration: prometheus.NewHistogramVec(
prometheus.HistogramOpts{
- Name: "rr_http_request_duration",
- Help: "HTTP request duration.",
- Buckets: []float64{0.25, 0.5, 1, 10, 20, 60},
+ Name: "rr_http_request_seconds",
+ Help: "HTTP request duration.",
},
[]string{"status"},
),
+ workersMemory: prometheus.NewGauge(
+ prometheus.GaugeOpts{
+ Name: "rr_http_workers_memory_bytes",
+ Help: "Memory usage by HTTP workers.",
+ },
+ ),
}
}
@@ -84,3 +96,28 @@ func (c *metricCollector) listener(event int, ctx interface{}) {
}).Observe(e.Elapsed().Seconds())
}
}
+
+// collect memory usage by server workers
+func (c *metricCollector) collectMemory(service *rrhttp.Service, tick time.Duration) {
+ started := false
+ for {
+ server := service.Server()
+ if server == nil && started {
+ // stopped
+ return
+ }
+
+ started = true
+
+ if workers, err := util.ServerState(server); err == nil {
+ sum := 0.0
+ for _, w := range workers {
+ sum = sum + float64(w.MemoryUsage)
+ }
+
+ c.workersMemory.Set(sum)
+ }
+
+ time.Sleep(tick)
+ }
+}