Collect gathers metrics (go.d framework requirement)
(ctx context.Context)
| 61 | |
| 62 | // Collect gathers metrics (go.d framework requirement) |
| 63 | func (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) |
| 99 | func (c *Collector) Cleanup(ctx context.Context) { |
nothing calls this directly
no test coverage detected