master
go 66 lines 1.63 KB
Raw
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 package fluentd
4
5 import "fmt"
6
7 func (c *Collector) collect() (map[string]int64, error) {
8 info, err := c.apiClient.getPluginsInfo()
9 if err != nil {
10 return nil, err
11 }
12
13 mx := make(map[string]int64)
14
15 for _, p := range info.Payload {
16 // TODO: if p.Category == "input" ?
17 if !p.hasCategory() && !p.hasBufferQueueLength() && !p.hasBufferTotalQueuedSize() {
18 continue
19 }
20
21 if c.permitPlugin != nil && !c.permitPlugin.MatchString(p.ID) {
22 c.Debugf("plugin id: '%s', type: '%s', category: '%s' denied", p.ID, p.Type, p.Category)
23 continue
24 }
25
26 id := fmt.Sprintf("%s_%s_%s", p.ID, p.Type, p.Category)
27
28 if p.hasCategory() {
29 mx[id+"_retry_count"] = *p.RetryCount
30 }
31 if p.hasBufferQueueLength() {
32 mx[id+"_buffer_queue_length"] = *p.BufferQueueLength
33 }
34 if p.hasBufferTotalQueuedSize() {
35 mx[id+"_buffer_total_queued_size"] = *p.BufferTotalQueuedSize
36 }
37
38 if !c.activePlugins[id] {
39 c.activePlugins[id] = true
40 c.addPluginToCharts(p)
41 }
42
43 }
44
45 return mx, nil
46 }
47
48 func (c *Collector) addPluginToCharts(p pluginData) {
49 id := fmt.Sprintf("%s_%s_%s", p.ID, p.Type, p.Category)
50
51 if p.hasCategory() {
52 chart := c.charts.Get("retry_count")
53 _ = chart.AddDim(&Dim{ID: id + "_retry_count", Name: p.ID})
54 chart.MarkNotCreated()
55 }
56 if p.hasBufferQueueLength() {
57 chart := c.charts.Get("buffer_queue_length")
58 _ = chart.AddDim(&Dim{ID: id + "_buffer_queue_length", Name: p.ID})
59 chart.MarkNotCreated()
60 }
61 if p.hasBufferTotalQueuedSize() {
62 chart := c.charts.Get("buffer_total_queued_size")
63 _ = chart.AddDim(&Dim{ID: id + "_buffer_total_queued_size", Name: p.ID})
64 chart.MarkNotCreated()
65 }
66 }