From c8a1f74390078399e45c0952154164b8ec41ff2c Mon Sep 17 00:00:00 2001 From: Valery Piashchynski Date: Wed, 26 Jan 2022 15:29:16 +0300 Subject: [PATCH 1/2] add more metrics Signed-off-by: Valery Piashchynski --- metrics.go | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/metrics.go b/metrics.go index 4f61094..957bbec 100644 --- a/metrics.go +++ b/metrics.go @@ -1,6 +1,8 @@ package http import ( + "strconv" + "github.com/prometheus/client_golang/prometheus" "github.com/roadrunner-server/api/v2/plugins/informer" ) @@ -10,20 +12,29 @@ func (p *Plugin) MetricsCollector() []prometheus.Collector { } type statsExporter struct { - desc *prometheus.Desc - workers informer.Informer + totalMemoryDesc *prometheus.Desc + stateDesc *prometheus.Desc + workerMemoryDesc *prometheus.Desc + totalWorkersDesc *prometheus.Desc + workers informer.Informer } func newWorkersExporter(stats informer.Informer) *statsExporter { return &statsExporter{ - desc: prometheus.NewDesc("rr_http_workers_memory_bytes", "Memory usage by HTTP workers.", nil, nil), - workers: stats, + totalWorkersDesc: prometheus.NewDesc("rr_http_total_workers", "Total number of workers used by the HTTP plugin", nil, nil), + totalMemoryDesc: prometheus.NewDesc("rr_http_workers_memory_bytes", "Memory usage by HTTP workers.", nil, nil), + stateDesc: prometheus.NewDesc("rr_http_worker_state", "Worker current state", []string{"state", "pid"}, nil), + workerMemoryDesc: prometheus.NewDesc("rr_http_worker_memory_bytes", "Worker current memory usage", []string{"pid"}, nil), + workers: stats, } } func (s *statsExporter) Describe(d chan<- *prometheus.Desc) { // send description - d <- s.desc + d <- s.totalWorkersDesc + d <- s.totalMemoryDesc + d <- s.stateDesc + d <- s.workerMemoryDesc } func (s *statsExporter) Collect(ch chan<- prometheus.Metric) { @@ -36,8 +47,12 @@ func (s *statsExporter) Collect(ch chan<- prometheus.Metric) { // collect the memory for i := 0; i < len(workers); i++ { cum += workers[i].MemoryUsage + + ch <- prometheus.MustNewConstMetric(s.stateDesc, prometheus.GaugeValue, 0, workers[i].Status, strconv.Itoa(workers[i].Pid)) + ch <- prometheus.MustNewConstMetric(s.workerMemoryDesc, prometheus.GaugeValue, float64(workers[i].MemoryUsage), strconv.Itoa(workers[i].Pid)) } // send the values to the prometheus - ch <- prometheus.MustNewConstMetric(s.desc, prometheus.GaugeValue, float64(cum)) + ch <- prometheus.MustNewConstMetric(s.totalWorkersDesc, prometheus.GaugeValue, float64(len(workers))) + ch <- prometheus.MustNewConstMetric(s.totalMemoryDesc, prometheus.GaugeValue, float64(cum)) } From 10b2f88278bbd3db4740e4536d89f1a18d387c33 Mon Sep 17 00:00:00 2001 From: Valery Piashchynski Date: Wed, 26 Jan 2022 15:34:17 +0300 Subject: [PATCH 2/2] add pr template Signed-off-by: Valery Piashchynski --- .github/pull_request_template.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 .github/pull_request_template.md diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md new file mode 100644 index 0000000..c346785 --- /dev/null +++ b/.github/pull_request_template.md @@ -0,0 +1,24 @@ +# Reason for This PR + +`[Author TODO: add issue # or explain reasoning.]` + +## Description of Changes + +`[Author TODO: add description of changes.]` + +## License Acceptance + +By submitting this pull request, I confirm that my contribution is made under +the terms of the MIT license. + +## PR Checklist + +`[Author TODO: Meet these criteria.]` +`[Reviewer TODO: Verify that these criteria are met. Request changes if not]` + +- [ ] All commits in this PR are signed (`git commit -s`). +- [ ] The reason for this PR is clearly provided (issue no. or explanation). +- [ ] The description of changes is clear and encompassing. +- [ ] Any required documentation changes (code and docs) are included in this PR. +- [ ] Any user-facing changes are mentioned in `CHANGELOG.md`. +- [ ] All added/changed functionality is tested.