| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | |
| 3 | package rabbitmq |
| 4 | |
| 5 | import ( |
| 6 | "fmt" |
| 7 | |
| 8 | "github.com/netdata/netdata/go/plugins/pkg/stm" |
| 9 | "github.com/netdata/netdata/go/plugins/pkg/web" |
| 10 | "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/oldmetrix" |
| 11 | ) |
| 12 | |
| 13 | func (c *Collector) collectQueues(mx map[string]int64) error { |
| 14 | req, err := web.NewHTTPRequestWithPath(c.RequestConfig, urlPathAPIQueues) |
| 15 | if err != nil { |
| 16 | return fmt.Errorf("failed to create queues stats request: %w", err) |
| 17 | } |
| 18 | |
| 19 | var resp []apiQueueResp |
| 20 | |
| 21 | if err := c.webClient().RequestJSON(req, &resp); err != nil { |
| 22 | return err |
| 23 | } |
| 24 | |
| 25 | for _, q := range resp { |
| 26 | c.cache.getQueue(q).seen = true |
| 27 | |
| 28 | px := fmt.Sprintf("queue_%s_vhost_%s_node_%s_", q.Name, q.Vhost, q.Node) |
| 29 | |
| 30 | for k, v := range stm.ToMap(q) { |
| 31 | mx[px+k] = v |
| 32 | } |
| 33 | |
| 34 | // https://github.com/rabbitmq/rabbitmq-server/blob/8b554474a65857aa60b72b2dda4b6fa9b78f349b/deps/rabbitmq_management/priv/www/js/formatters.js#L552 |
| 35 | st := q.State |
| 36 | if q.IdleSince != nil { |
| 37 | st = "idle" |
| 38 | } |
| 39 | for _, v := range []string{"running", "idle", "terminated", "down", "crashed", "stopped", "minority"} { |
| 40 | mx[px+"status_"+v] = oldmetrix.Bool(v == st) |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | return nil |
| 45 | } |