MCPcopy
hub / github.com/netdata/netdata / convertMetrics

Method convertMetrics

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

convertMetrics converts framework metrics to go.d format

()

Source from the content-addressed store, hash-verified

124
125// convertMetrics converts framework metrics to go.d format
126func (c *Collector) convertMetrics() map[string]int64 {
127 mx := make(map[string]int64)
128
129 // Track seen instances for dynamic chart creation
130 seenInstances := make(map[string]bool)
131
132 // Convert instance metrics
133 for _, metric := range c.State.GetMetrics() {
134 // Track this instance
135 instanceKey := metric.Instance.key
136 seenInstances[instanceKey] = true
137
138 // Check if we need to create charts for this instance
139 if !c.hasChartsForInstance(instanceKey) {
140 // Find the context this instance belongs to
141 for _, ctx := range c.registeredContexts {
142 contextMeta := extractContextMetadata(ctx)
143 if contextMeta != nil && contextMeta.Name == metric.Instance.contextName {
144 // Get the current instance from state (not the copy in metric)
145 currentInstance := c.State.instances[instanceKey]
146 if currentInstance == nil {
147 // Fallback to metric instance if not found (shouldn't happen)
148 currentInstance = &metric.Instance
149 }
150 // Create charts for this new instance
151 chart := c.createChartFromContext(ctx, instanceKey, currentInstance)
152 if chart != nil {
153 c.Debugf("Creating dynamic chart for instance: %s", instanceKey)
154 // Add labels from the instance
155 for k, v := range metric.Instance.labels {
156 chart.Labels = append(chart.Labels, collectorapi.Label{
157 Key: k,
158 Value: v,
159 })
160 }
161 if c.charts.Has(chart.ID) {
162 c.markInstanceChartsPresent(instanceKey)
163 continue
164 }
165 if err := c.charts.Add(chart); err != nil {
166 c.Errorf("failed adding chart for %s: %v", instanceKey, err)
167 } else {
168 c.markInstanceChartsPresent(instanceKey)
169 }
170 }
171 break
172 }
173 }
174 }
175
176 // Generate go.d metric key
177 key := c.generateMetricKey(metric)
178 mx[key] = metric.Value
179 }
180
181 // Add protocol observability metrics (if any protocols are registered)
182 // This will be added when protocol observability charts are created
183 // for name, pm := range c.State.protocols {

Callers 1

CollectMethod · 0.95

Calls 10

hasChartsForInstanceMethod · 0.95
generateMetricKeyMethod · 0.95
extractContextMetadataFunction · 0.85
GetMetricsMethod · 0.80
HasMethod · 0.80
DebugfMethod · 0.65
AddMethod · 0.65
ErrorfMethod · 0.65

Tested by

no test coverage detected