GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — http/metrics.go at master · roadrunner-server/http Expand file tree/ Copy pathmetrics.goMore file actions 95 lines (75 loc) · 3.04 KB / Copy pathmetrics.goFile metadata and controls95 lines (75 loc) · 3.04 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 package http import ( "strconv" "github.com/prometheus/client_golang/prometheus" "github.com/roadrunner-server/pool/v2/fsm" "github.com/roadrunner-server/pool/v2/state/process" ) type Informer interface { Workers() []*process.State } func (p *Plugin) MetricsCollector() []prometheus.Collector { return []prometheus.Collector{p.statsExporter} } func newWorkersExporter(stats Informer) *StatsExporter { return &StatsExporter{ 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), WorkersReady: prometheus.NewDesc("rr_http_workers_ready", "HTTP workers currently in ready state", nil, nil), WorkersWorking: prometheus.NewDesc("rr_http_workers_working", "HTTP workers currently in working state", nil, nil), WorkersInvalid: prometheus.NewDesc("rr_http_workers_invalid", "HTTP workers currently in invalid,killing,destroyed,errored,inactive states", nil, nil), Workers: stats, } } type StatsExporter struct { TotalMemoryDesc *prometheus.Desc StateDesc *prometheus.Desc WorkerMemoryDesc *prometheus.Desc TotalWorkersDesc *prometheus.Desc WorkersReady *prometheus.Desc WorkersWorking *prometheus.Desc WorkersInvalid *prometheus.Desc Workers Informer } func (s *StatsExporter) Describe(d chan<- *prometheus.Desc) { // send description d <- s.TotalWorkersDesc d <- s.TotalMemoryDesc d <- s.StateDesc d <- s.WorkerMemoryDesc d <- s.WorkersReady d <- s.WorkersWorking d <- s.WorkersInvalid } func (s *StatsExporter) Collect(ch chan<- prometheus.Metric) { // get the copy of the processes workerStates := s.Workers.Workers() // cumulative RSS memory in bytes var cum float64 var ready float64 var working float64 var invalid float64 // collect the memory for _, ws := range workerStates { cum += float64(ws.MemoryUsage) ch <- prometheus.MustNewConstMetric(s.StateDesc, prometheus.GaugeValue, 0, ws.StatusStr, strconv.Itoa(int(ws.Pid))) ch <- prometheus.MustNewConstMetric(s.WorkerMemoryDesc, prometheus.GaugeValue, float64(ws.MemoryUsage), strconv.Itoa(int(ws.Pid))) // sync with sdk/worker/state.go switch ws.Status { case fsm.StateReady: ready++ case fsm.StateWorking: working++ default: invalid++ } } ch <- prometheus.MustNewConstMetric(s.WorkersReady, prometheus.GaugeValue, ready) ch <- prometheus.MustNewConstMetric(s.WorkersWorking, prometheus.GaugeValue, working) ch <- prometheus.MustNewConstMetric(s.WorkersInvalid, prometheus.GaugeValue, invalid) // send the values to the prometheus ch <- prometheus.MustNewConstMetric(s.TotalWorkersDesc, prometheus.GaugeValue, float64(len(workerStates))) ch <- prometheus.MustNewConstMetric(s.TotalMemoryDesc, prometheus.GaugeValue, cum) } |
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |