// Collect implements prometheus Collector interface.
189506
func (h *StatsHandler) Collect(in chan<- prometheus.Metric) {
	for _, c := range h.handlers {
		c.Collect(in)
	}
}
99234
func (bc *buildCollector) Collect(ch chan<- prometheus.Metric) {
	result, err := bc.lister.List(kselector.Everything())

	if err != nil {
		klog.V(4).Infof("Collect err %v", err)
		return
	}

	// collectBuild will return counts for the build's phase/reason tuple,
	// and counts for these tuples be added to the total amount posted to prometheus
	counts := map[collectKey]int{}
	for _, b := range result {
		k := bc.collectBuild(ch, b)
		counts[k] = counts[k] + 1
	}

	for key, count := range counts {
		addCountGauge(ch, buildCountDesc, key.phase, key.reason, key.strategy, float64(count))
	}
}
951788
func (e *Endpoint) Collect(ctx context.Context, acc telegraf.Accumulator) error {

	// If we never managed to do a discovery, collection will be a no-op. Therefore,
	// we need to check that a connection is available, or the collection will
	// silently fail.
	if _, err := e.clientFactory.GetClient(ctx); err != nil {
		return err
	}

	e.collectMux.RLock()
	defer e.collectMux.RUnlock()

	if ctx.Err() != nil {
		return ctx.Err()
	}

	// If discovery interval is disabled (0), discover on each collection cycle
	if e.Parent.ObjectDiscoveryInterval.Duration == 0 {
		err := e.discover(ctx)
		if err != nil {
			return err
		}
	}
	var wg sync.WaitGroup
	for k, res := range e.resourceKinds {
		if res.enabled {
			wg.Add(1)
			go func(k string) {
				defer wg.Done()
				err := e.collectResource(ctx, k, acc)
				if err != nil {
					acc.AddError(err)
				}
			}(k)
		}
	}
	wg.Wait()

	// Purge old timestamps from the cache
	e.hwMarks.Purge()
	return nil
}
57439
func (c *goCollector) Collect(ch chan<- Metric) {
	ch <- MustNewConstMetric(c.goroutinesDesc, GaugeValue, float64(runtime.NumGoroutine()))
	n, _ := runtime.ThreadCreateProfile(nil)
	ch <- MustNewConstMetric(c.threadsDesc, GaugeValue, float64(n))

	var stats debug.GCStats
	stats.PauseQuantiles = make([]time.Duration, 5)
	debug.ReadGCStats(&stats)

	quantiles := make(map[float64]float64)
	for idx, pq := range stats.PauseQuantiles[1:] {
		quantiles[float64(idx+1)/float64(len(stats.PauseQuantiles)-1)] = pq.Seconds()
	}
	quantiles[0.0] = stats.PauseQuantiles[0].Seconds()
	ch <- MustNewConstSummary(c.gcDesc, uint64(stats.NumGC), stats.PauseTotal.Seconds(), quantiles)

	ch <- MustNewConstMetric(c.goInfoDesc, GaugeValue, 1)

	ms := &runtime.MemStats{}
	runtime.ReadMemStats(ms)
	for _, i := range c.metrics {
		ch <- MustNewConstMetric(i.desc, i.valType, i.eval(ms))
	}
}
873700
func (hc *TopNCollector) Collect(ctx context.Context, searcher search.Searcher, reader index.IndexReader) error {
	startTime := time.Now()
	var err error
	var next *search.DocumentMatch

	// pre-allocate enough space in the DocumentMatchPool
	// unless the size + skip is too large, then cap it
	// everything should still work, just allocates DocumentMatches on demand
	backingSize := hc.size + hc.skip + 1
	if hc.size+hc.skip > PreAllocSizeSkipCap {
		backingSize = PreAllocSizeSkipCap + 1
	}
	searchContext := &search.SearchContext{
		DocumentMatchPool: search.NewDocumentMatchPool(backingSize+searcher.DocumentMatchPoolSize(), len(hc.sort)),
		Collector:         hc,
		IndexReader:       reader,
	}

	hc.dvReader, err = reader.DocValueReader(hc.neededFields)
	if err != nil {
		return err
	}

	hc.updateFieldVisitor = func(field string, term []byte) {
		if hc.facetsBuilder != nil {
			hc.facetsBuilder.UpdateVisitor(field, term)
		}
		hc.sort.UpdateVisitor(field, term)
	}

	dmHandlerMaker := MakeTopNDocumentMatchHandler
	if cv := ctx.Value(search.MakeDocumentMatchHandlerKey); cv != nil {
		dmHandlerMaker = cv.(search.MakeDocumentMatchHandler)
	}
	// use the application given builder for making the custom document match
	// handler and perform callbacks/invocations on the newly made handler.
	dmHandler, loadID, err := dmHandlerMaker(searchContext)
	if err != nil {
		return err
	}

	hc.needDocIds = hc.needDocIds || loadID

	select {
	case <-ctx.Done():
		return ctx.Err()
	default:
		next, err = searcher.Next(searchContext)
	}
	for err == nil && next != nil {
		if hc.total%CheckDoneEvery == 0 {
			select {
			case <-ctx.Done():
				return ctx.Err()
			default:
			}
		}

		err = hc.prepareDocumentMatch(searchContext, reader, next)
		if err != nil {
			break
		}

		err = dmHandler(next)
		if err != nil {
			break
		}

		next, err = searcher.Next(searchContext)
	}

	// help finalize/flush the results in case
	// of custom document match handlers.
	err = dmHandler(nil)
	if err != nil {
		return err
	}

	// compute search duration
	hc.took = time.Since(startTime)
	if err != nil {
		return err
	}
	// finalize actual results
	err = hc.finalizeResults(reader)
	if err != nil {
		return err
	}
	return nil
}
784802
func (c *Client) Collect(ch chan<- prometheus.Metric) {
	stats := c.db.Stats()
	writes := stats.TxStats.Write
	reads := stats.TxN

	ch <- prometheus.MustNewConstMetric(
		boltReadsDesc,
		prometheus.CounterValue,
		float64(reads),
	)

	ch <- prometheus.MustNewConstMetric(
		boltWritesDesc,
		prometheus.CounterValue,
		float64(writes),
	)

	orgs, buckets, users, tokens := 0, 0, 0, 0
	dashboards, scrapers, telegrafs := 0, 0, 0
	_ = c.db.View(func(tx *bolt.Tx) error {
		orgs = tx.Bucket(organizationBucket).Stats().KeyN
		buckets = tx.Bucket(bucketBucket).Stats().KeyN
		users = tx.Bucket(userBucket).Stats().KeyN
		tokens = tx.Bucket(authorizationBucket).Stats().KeyN
		dashboards = tx.Bucket(dashboardBucket).Stats().KeyN
		scrapers = tx.Bucket(scraperBucket).Stats().KeyN
		telegrafs = tx.Bucket(telegrafBucket).Stats().KeyN
		return nil
	})

	ch <- prometheus.MustNewConstMetric(
		orgsDesc,
		prometheus.CounterValue,
		float64(orgs),
	)

	ch <- prometheus.MustNewConstMetric(
		bucketsDesc,
		prometheus.CounterValue,
		float64(buckets),
	)

	ch <- prometheus.MustNewConstMetric(
		usersDesc,
		prometheus.CounterValue,
		float64(users),
	)

	ch <- prometheus.MustNewConstMetric(
		tokensDesc,
		prometheus.CounterValue,
		float64(tokens),
	)

	ch <- prometheus.MustNewConstMetric(
		dashboardsDesc,
		prometheus.CounterValue,
		float64(dashboards),
	)

	ch <- prometheus.MustNewConstMetric(
		scrapersDesc,
		prometheus.CounterValue,
		float64(scrapers),
	)

	ch <- prometheus.MustNewConstMetric(
		telegrafsDesc,
		prometheus.CounterValue,
		float64(telegrafs),
	)
}
630581
func (g *gaugesWithSingleLabelCollector) Collect(ch chan<- prometheus.Metric) {
	for tag, val := range g.gauges.Counts() {
		ch <- prometheus.MustNewConstMetric(
			g.desc,
			g.vt,
			float64(val),
			tag)
	}
}
1281082
func (m *MockGauge) Collect(arg0 chan<- prometheus.Metric) {
	m.ctrl.Call(m, "Collect", arg0)
}
33952
func PrometheusCollectors() []prometheus.Collector {
	mmu.RLock()
	defer mmu.RUnlock()

	var collectors []prometheus.Collector
	if bms != nil {
		collectors = append(collectors, bms.compactionMetrics.PrometheusCollectors()...)
		collectors = append(collectors, bms.fileMetrics.PrometheusCollectors()...)
		collectors = append(collectors, bms.cacheMetrics.PrometheusCollectors()...)
	}
	return collectors
}
682801
func (s *Store) Collect(ch chan<- prometheus.Metric) {
	s.metrics.Collect(ch)
}
810781
func (n NodeCollector) Collect(ch chan<- prometheus.Metric) {
	wg := sync.WaitGroup{}
	wg.Add(len(n.collectors))
	for name, c := range n.collectors {
		go func(name string, c collector.Collector) {
			execute(name, c, ch)
			wg.Done()
		}(name, c)
	}
	wg.Wait()
	scrapeDurations.Collect(ch)
}
280022
func (p *prometheusScraper) Gather(ctx context.Context, target platform.ScraperTarget) (ms []Metrics, err error) {
	resp, err := http.Get(target.URL)
	if err != nil {
		return ms, err
	}
	defer resp.Body.Close()

	return p.parse(resp.Body, resp.Header)
}
1239887
func (g *GoMetrics) Collect() {
	now := time.Now()

	lastTotalAlloc := g.ms.TotalAlloc
	lastLookups := g.ms.Lookups
	lastMallocs := g.ms.Mallocs
	lastFrees := g.ms.Frees
	lastHeapRealeased := g.ms.HeapReleased
	lastNumGC := g.ms.NumGC
	lastNumCgoCall := g.runtime.lastNumCgoCall
	g.runtime.lastNumCgoCall = int(runtime.NumCgoCall())

	g.runtime.numCPU = runtime.NumCPU()
	g.runtime.numGoroutine = runtime.NumGoroutine()
	g.runtime.numCgoCall = g.runtime.lastNumCgoCall - lastNumCgoCall

	pauses := collectMemoryStats(&g.ms, lastNumGC)

	g.memstats.total.alloc = g.ms.Alloc
	g.memstats.total.totalAlloc = g.ms.TotalAlloc - lastTotalAlloc
	g.memstats.total.lookups = g.ms.Lookups - lastLookups
	g.memstats.total.mallocs = g.ms.Mallocs - lastMallocs
	g.memstats.total.frees = g.ms.Frees - lastFrees

	g.memstats.heap.alloc = g.ms.HeapAlloc
	g.memstats.heap.sys = g.ms.HeapSys
	g.memstats.heap.idle = g.ms.HeapIdle
	g.memstats.heap.inuse = g.ms.HeapInuse
	g.memstats.heap.released = g.ms.HeapReleased - lastHeapRealeased
	g.memstats.heap.objects = g.ms.HeapObjects

	g.memstats.stack.inuse = g.ms.StackInuse
	g.memstats.stack.sys = g.ms.StackSys
	g.memstats.mspan.inuse = g.ms.MSpanInuse
	g.memstats.mspan.sys = g.ms.MSpanSys
	g.memstats.mcache.inuse = g.ms.MCacheInuse
	g.memstats.mcache.sys = g.ms.MCacheSys
	g.memstats.buckhash.sys = g.ms.BuckHashSys
	g.memstats.gc.sys = g.ms.GCSys
	g.memstats.other.sys = g.ms.OtherSys

	g.memstats.numGC = g.ms.NumGC - lastNumGC
	g.memstats.nextGC = g.ms.NextGC
	g.memstats.gcCPUFraction = g.ms.GCCPUFraction

	if len(pauses) == 0 {
		g.memstats.gcPauseAvg = 0
		g.memstats.gcPauseMin = 0
		g.memstats.gcPauseMax = 0
	} else {
		g.memstats.gcPauseMin = pauses[0]
		g.memstats.gcPauseMax = pauses[0]
		g.memstats.gcPauseAvg = pauses[0]

		for _, pause := range pauses[1:] {
			g.memstats.gcPauseAvg += pause
			switch {
			case pause < g.memstats.gcPauseMin:
				g.memstats.gcPauseMin = pause
			case pause > g.memstats.gcPauseMax:
				g.memstats.gcPauseMax = pause
			}
		}

		g.memstats.gcPauseAvg /= time.Duration(len(pauses))
	}

	g.engine.ReportAt(now, g)
}
1088761
func (c *minioCollector) Collect(ch chan<- prometheus.Metric) {

	// Always expose network stats

	// Network Sent/Received Bytes
	ch <- prometheus.MustNewConstMetric(
		prometheus.NewDesc(
			prometheus.BuildFQName("minio", "network", "sent_bytes_total"),
			"Total number of bytes sent by current MinIO server instance",
			nil, nil),
		prometheus.CounterValue,
		float64(globalConnStats.getTotalOutputBytes()),
	)
	ch <- prometheus.MustNewConstMetric(
		prometheus.NewDesc(
			prometheus.BuildFQName("minio", "network", "received_bytes_total"),
			"Total number of bytes received by current MinIO server instance",
			nil, nil),
		prometheus.CounterValue,
		float64(globalConnStats.getTotalInputBytes()),
	)

	// Expose cache stats only if available
	cacheObjLayer := newCacheObjectsFn()
	if cacheObjLayer != nil {
		cs := cacheObjLayer.StorageInfo(context.Background())
		ch <- prometheus.MustNewConstMetric(
			prometheus.NewDesc(
				prometheus.BuildFQName("minio", "disk", "cache_storage_bytes"),
				"Total cache capacity on current MinIO server instance",
				nil, nil),
			prometheus.GaugeValue,
			float64(cs.Total),
		)
		ch <- prometheus.MustNewConstMetric(
			prometheus.NewDesc(
				prometheus.BuildFQName("minio", "disk", "cache_storage_free_bytes"),
				"Total cache available on current MinIO server instance",
				nil, nil),
			prometheus.GaugeValue,
			float64(cs.Free),
		)
	}

	// Expose disk stats only if applicable

	// Fetch disk space info
	objLayer := newObjectLayerFn()
	// Service not initialized yet
	if objLayer == nil {
		return
	}

	s := objLayer.StorageInfo(context.Background())

	// Gateways don't provide disk info
	if s.Backend.Type == Unknown {
		return
	}

	var totalDisks, offlineDisks int
	// Setting totalDisks to 1 and offlineDisks to 0 in FS mode
	if s.Backend.Type == BackendFS {
		totalDisks = 1
		offlineDisks = 0
	} else {
		offlineDisks = s.Backend.OfflineDisks
		totalDisks = s.Backend.OfflineDisks + s.Backend.OnlineDisks
	}

	// Total disk usage by current MinIO server instance
	ch <- prometheus.MustNewConstMetric(
		prometheus.NewDesc(
			prometheus.BuildFQName("minio", "disk", "storage_used_bytes"),
			"Total disk storage used by current MinIO server instance",
			nil, nil),
		prometheus.GaugeValue,
		float64(s.Used),
	)

	// Total disk available space seen by MinIO server instance
	ch <- prometheus.MustNewConstMetric(
		prometheus.NewDesc(
			prometheus.BuildFQName("minio", "disk", "storage_available_bytes"),
			"Total disk available space seen by MinIO server instance",
			nil, nil),
		prometheus.GaugeValue,
		float64(s.Available),
	)

	// Total disk space seen by MinIO server instance
	ch <- prometheus.MustNewConstMetric(
		prometheus.NewDesc(
			prometheus.BuildFQName("minio", "disk", "storage_total_bytes"),
			"Total disk space seen by MinIO server instance",
			nil, nil),
		prometheus.GaugeValue,
		float64(s.Total),
	)

	// MinIO Total Disk/Offline Disk
	ch <- prometheus.MustNewConstMetric(
		prometheus.NewDesc(
			prometheus.BuildFQName("minio", "total", "disks"),
			"Total number of disks for current MinIO server instance",
			nil, nil),
		prometheus.GaugeValue,
		float64(totalDisks),
	)
	ch <- prometheus.MustNewConstMetric(
		prometheus.NewDesc(
			prometheus.BuildFQName("minio", "offline", "disks"),
			"Total number of offline disks for current MinIO server instance",
			nil, nil),
		prometheus.GaugeValue,
		float64(offlineDisks),
	)
}
1258078
func (m *MultiError) Collect(err error) {
	if err != nil {
		m.Errors = append(m.Errors, err)
	}
}
1045738
func (c Metrics) Collect(ch chan<- prometheus.Metric) {
	ch <- prometheus.MustNewConstMetric(
		c.TotalPushCount,
		prometheus.GaugeValue,
		float64(StatStorage.GetTotalCount()),
	)
	ch <- prometheus.MustNewConstMetric(
		c.IosSuccess,
		prometheus.GaugeValue,
		float64(StatStorage.GetIosSuccess()),
	)
	ch <- prometheus.MustNewConstMetric(
		c.IosError,
		prometheus.GaugeValue,
		float64(StatStorage.GetIosError()),
	)
	ch <- prometheus.MustNewConstMetric(
		c.AndroidSuccess,
		prometheus.GaugeValue,
		float64(StatStorage.GetAndroidSuccess()),
	)
	ch <- prometheus.MustNewConstMetric(
		c.AndroidError,
		prometheus.GaugeValue,
		float64(StatStorage.GetAndroidError()),
	)
	ch <- prometheus.MustNewConstMetric(
		c.QueueUsage,
		prometheus.GaugeValue,
		float64(len(QueueNotification)),
	)
}
130002
func (collector *volumeStatsCollector) Collect(ch chan<- prometheus.Metric) {
	podStats, err := collector.statsProvider.ListPodStats()
	if err != nil {
		return
	}
	addGauge := func(desc *prometheus.Desc, pvcRef *stats.PVCReference, v float64, lv ...string) {
		lv = append([]string{pvcRef.Namespace, pvcRef.Name}, lv...)
		metric, err := prometheus.NewConstMetric(desc, prometheus.GaugeValue, v, lv...)
		if err != nil {
			klog.Warningf("Failed to generate metric: %v", err)
			return
		}
		ch <- metric
	}
	allPVCs := sets.String{}
	for _, podStat := range podStats {
		if podStat.VolumeStats == nil {
			continue
		}
		for _, volumeStat := range podStat.VolumeStats {
			pvcRef := volumeStat.PVCRef
			if pvcRef == nil {
				// ignore if no PVC reference
				continue
			}
			pvcUniqStr := pvcRef.Namespace + "/" + pvcRef.Name
			if allPVCs.Has(pvcUniqStr) {
				// ignore if already collected
				continue
			}
			addGauge(volumeStatsCapacityBytesDesc, pvcRef, float64(*volumeStat.CapacityBytes))
			addGauge(volumeStatsAvailableBytesDesc, pvcRef, float64(*volumeStat.AvailableBytes))
			addGauge(volumeStatsUsedBytesDesc, pvcRef, float64(*volumeStat.UsedBytes))
			addGauge(volumeStatsInodesDesc, pvcRef, float64(*volumeStat.Inodes))
			addGauge(volumeStatsInodesFreeDesc, pvcRef, float64(*volumeStat.InodesFree))
			addGauge(volumeStatsInodesUsedDesc, pvcRef, float64(*volumeStat.InodesUsed))
			allPVCs.Insert(pvcUniqStr)
		}
	}
}