| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | |
| 3 | package collectorapi |
| 4 | |
| 5 | import ( |
| 6 | "context" |
| 7 | |
| 8 | "github.com/netdata/netdata/go/plugins/logger" |
| 9 | "github.com/netdata/netdata/go/plugins/pkg/metrix" |
| 10 | "github.com/netdata/netdata/go/plugins/plugin/framework/chartengine" |
| 11 | "github.com/netdata/netdata/go/plugins/plugin/framework/vnodes" |
| 12 | ) |
| 13 | |
| 14 | // CollectorV1 is an interface that represents a module. |
| 15 | type CollectorV1 interface { |
| 16 | // Init does initialization. |
| 17 | // If it returns error, the job will be disabled. |
| 18 | Init(context.Context) error |
| 19 | |
| 20 | // Check is called after Init. |
| 21 | // If it returns error, the job will be disabled. |
| 22 | Check(context.Context) error |
| 23 | |
| 24 | // Charts returns the chart definition. |
| 25 | Charts() *Charts |
| 26 | |
| 27 | // Collect collects metrics. |
| 28 | Collect(context.Context) map[string]int64 |
| 29 | |
| 30 | // Cleanup Cleanup |
| 31 | Cleanup(context.Context) |
| 32 | |
| 33 | GetBase() *Base |
| 34 | |
| 35 | Configuration() any |
| 36 | |
| 37 | VirtualNode() *vnodes.VirtualNode |
| 38 | } |
| 39 | |
| 40 | // CollectorV2 is the collector contract for the new metrics+template runtime. |
| 41 | // |
| 42 | // Collectors implementing this interface: |
| 43 | // - write metrics into CollectorStore during Collect(), |
| 44 | // - provide chart template YAML consumed by chartengine. |
| 45 | type CollectorV2 interface { |
| 46 | Init(context.Context) error |
| 47 | Check(context.Context) error |
| 48 | Collect(context.Context) error |
| 49 | Cleanup(context.Context) |
| 50 | |
| 51 | GetBase() *Base |
| 52 | Configuration() any |
| 53 | VirtualNode() *vnodes.VirtualNode |
| 54 | |
| 55 | MetricStore() metrix.CollectorStore |
| 56 | ChartTemplateYAML() string |
| 57 | } |
| 58 | |
| 59 | // CollectorV2EnginePolicy allows a V2 collector to provide chartengine policy |
| 60 | // (series selector + autogen behavior). |
| 61 | type CollectorV2EnginePolicy interface { |
| 62 | EnginePolicy() chartengine.EnginePolicy |
| 63 | } |
| 64 | |
| 65 | // Base is a helper struct. All modules should embed this struct. |
| 66 | type Base struct { |
| 67 | *logger.Logger |
| 68 | } |
| 69 | |
| 70 | func (b *Base) GetBase() *Base { return b } |
| 71 | |
| 72 | func (b *Base) VirtualNode() *vnodes.VirtualNode { return nil } |