MCPcopy
hub / github.com/netdata/netdata / Collect

Method Collect

src/go/plugin/ibm.d/framework/collector.go:63–96  ·  view source on GitHub ↗

Collect gathers metrics (go.d framework requirement)

(ctx context.Context)

Source from the content-addressed store, hash-verified

61
62// Collect gathers metrics (go.d framework requirement)
63func (c *Collector) Collect(ctx context.Context) map[string]int64 {
64 // Increment global iteration counter
65 c.State.iteration++
66
67 // Clear previous iteration errors
68 c.State.ClearErrors()
69
70 // Run collection (implemented by specific collector)
71 var err error
72 if c.impl != nil {
73 err = c.impl.CollectOnce()
74 } else {
75 err = fmt.Errorf("collector implementation not set")
76 }
77
78 // Handle errors (let the module decide how to handle them)
79 if err != nil {
80 c.Errorf("collection failed: %v", err)
81 // Return whatever metrics we have (partial collection is OK)
82 }
83
84 // Convert collected metrics to go.d format
85 metrics := c.convertMetrics()
86
87 // Advance iteration and handle obsoletion
88 c.State.NextIteration(c.Config.ObsoletionIterations)
89
90 // Handle obsolete instances - mark their charts as obsolete
91 for _, instanceKey := range c.State.GetObsoleteInstances() {
92 c.markChartsObsolete(instanceKey)
93 }
94
95 return metrics
96}
97
98// Cleanup performs cleanup (go.d framework requirement)
99func (c *Collector) Cleanup(ctx context.Context) {

Callers

nothing calls this directly

Calls 7

convertMetricsMethod · 0.95
markChartsObsoleteMethod · 0.95
ClearErrorsMethod · 0.80
NextIterationMethod · 0.80
GetObsoleteInstancesMethod · 0.80
CollectOnceMethod · 0.65
ErrorfMethod · 0.65

Tested by

no test coverage detected