MCPcopy
hub / github.com/prometheus/client_golang / NewGoCollector

Function NewGoCollector

prometheus/go_collector_latest.go:167–288  ·  view source on GitHub ↗

NewGoCollector is the obsolete version of collectors.NewGoCollector. See there for documentation. Deprecated: Use collectors.NewGoCollector instead.

(opts ...func(o *internal.GoCollectorOptions))

Source from the content-addressed store, hash-verified

165//
166// Deprecated: Use collectors.NewGoCollector instead.
167func NewGoCollector(opts ...func(o *internal.GoCollectorOptions)) Collector {
168 opt := defaultGoCollectorOptions()
169 for _, o := range opts {
170 o(&opt)
171 }
172
173 exposedDescriptions := matchRuntimeMetricsRules(opt.RuntimeMetricRules)
174
175 // Collect all histogram samples so that we can get their buckets.
176 // The API guarantees that the buckets are always fixed for the lifetime
177 // of the process.
178 var histograms []metrics.Sample
179 for _, d := range exposedDescriptions {
180 if d.Kind == metrics.KindFloat64Histogram {
181 histograms = append(histograms, metrics.Sample{Name: d.Name})
182 }
183 }
184
185 if len(histograms) > 0 {
186 metrics.Read(histograms)
187 }
188
189 bucketsMap := make(map[string][]float64)
190 for i := range histograms {
191 bucketsMap[histograms[i].Name] = histograms[i].Value.Float64Histogram().Buckets
192 }
193
194 // Generate a collector for each exposed runtime/metrics metric.
195 metricSet := make([]collectorMetric, 0, len(exposedDescriptions))
196 // SampleBuf is used for reading from runtime/metrics.
197 // We are assuming the largest case to have stable pointers for sampleMap purposes.
198 sampleBuf := make([]metrics.Sample, 0, len(exposedDescriptions)+len(opt.RuntimeMetricSumForHist)+len(rmNamesForMemStatsMetrics))
199 sampleMap := make(map[string]*metrics.Sample, len(exposedDescriptions))
200 for _, d := range exposedDescriptions {
201 namespace, subsystem, name, ok := internal.RuntimeMetricsToProm(&d.Description)
202 if !ok {
203 // Just ignore this metric; we can't do anything with it here.
204 // If a user decides to use the latest version of Go, we don't want
205 // to fail here. This condition is tested in TestExpectedRuntimeMetrics.
206 continue
207 }
208 help := attachOriginalName(d.Description.Description, d.Name)
209
210 sampleBuf = append(sampleBuf, metrics.Sample{Name: d.Name})
211 sampleMap[d.Name] = &sampleBuf[len(sampleBuf)-1]
212
213 var m collectorMetric
214 if d.Kind == metrics.KindFloat64Histogram {
215 _, hasSum := opt.RuntimeMetricSumForHist[d.Name]
216 unit := d.Name[strings.IndexRune(d.Name, ':')+1:]
217 m = newBatchHistogram(
218 NewDesc(
219 BuildFQName(namespace, subsystem, name),
220 help,
221 nil,
222 nil,
223 ),
224 internal.RuntimeMetricsBucketsForUnit(bucketsMap[d.Name], unit),

Callers 4

ExampleCollectorFunction · 0.92
NewGoCollectorFunction · 0.92
NewGoCollectorFunction · 0.92

Calls 13

RuntimeMetricsToPromFunction · 0.92
matchRuntimeMetricsRulesFunction · 0.85
attachOriginalNameFunction · 0.85
newBatchHistogramFunction · 0.85
NewDescFunction · 0.85
BuildFQNameFunction · 0.85
goRuntimeMemStatsFunction · 0.85
bestEffortLookupRMFunction · 0.85
newBaseGoCollectorFunction · 0.85
NewCounterFunction · 0.70

Tested by 2

ExampleCollectorFunction · 0.74