summaryrefslogtreecommitdiffstats
path: root/src/go/collectors/go.d.plugin/modules/fluentd/collect.go
blob: 14ee6df686600547f18e03c49335d4cb501a2f78 (plain)
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
// SPDX-License-Identifier: GPL-3.0-or-later

package fluentd

import "fmt"

func (f *Fluentd) collect() (map[string]int64, error) {
	info, err := f.apiClient.getPluginsInfo()
	if err != nil {
		return nil, err
	}

	mx := make(map[string]int64)

	for _, p := range info.Payload {
		// TODO: if p.Category == "input" ?
		if !p.hasCategory() && !p.hasBufferQueueLength() && !p.hasBufferTotalQueuedSize() {
			continue
		}

		if f.permitPlugin != nil && !f.permitPlugin.MatchString(p.ID) {
			f.Debugf("plugin id: '%s', type: '%s', category: '%s' denied", p.ID, p.Type, p.Category)
			continue
		}

		id := fmt.Sprintf("%s_%s_%s", p.ID, p.Type, p.Category)

		if p.hasCategory() {
			mx[id+"_retry_count"] = *p.RetryCount
		}
		if p.hasBufferQueueLength() {
			mx[id+"_buffer_queue_length"] = *p.BufferQueueLength
		}
		if p.hasBufferTotalQueuedSize() {
			mx[id+"_buffer_total_queued_size"] = *p.BufferTotalQueuedSize
		}

		if !f.activePlugins[id] {
			f.activePlugins[id] = true
			f.addPluginToCharts(p)
		}

	}

	return mx, nil
}

func (f *Fluentd) addPluginToCharts(p pluginData) {
	id := fmt.Sprintf("%s_%s_%s", p.ID, p.Type, p.Category)

	if p.hasCategory() {
		chart := f.charts.Get("retry_count")
		_ = chart.AddDim(&Dim{ID: id + "_retry_count", Name: p.ID})
		chart.MarkNotCreated()
	}
	if p.hasBufferQueueLength() {
		chart := f.charts.Get("buffer_queue_length")
		_ = chart.AddDim(&Dim{ID: id + "_buffer_queue_length", Name: p.ID})
		chart.MarkNotCreated()
	}
	if p.hasBufferTotalQueuedSize() {
		chart := f.charts.Get("buffer_total_queued_size")
		_ = chart.AddDim(&Dim{ID: id + "_buffer_total_queued_size", Name: p.ID})
		chart.MarkNotCreated()
	}
}