exporter

package
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 14, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package exporter exposes a gpu.Collector as Prometheus metrics.

The Exporter is a prometheus.Collector (Describe + Collect) that wraps a gpu.Collector built lazily on the first scrape via an injected factory. Per plan R4 it:

  • guards GPU reads with a sync.Mutex so overlapping scrapes never race the inner collector (bounded scrape freshness);
  • holds its OWN *prometheus.Registry created via prometheus.NewRegistry so repeated instances or tests never panic on duplicate registration and the global default registry is never touched;
  • emits gpu_tools_up 0 with NO device series (HTTP 200) when the backend is unavailable (ErrBackendUnavailable / ErrNoBackend);
  • never returns or propagates an error to promhttp: on a read error it logs to the configured logger seam (stderr by default) and emits up 0.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Exporter

type Exporter struct {
	// contains filtered or unexported fields
}

Exporter implements prometheus.Collector over a gpu.Collector.

func New

func New(factory Factory) *Exporter

New builds an Exporter over factory, logging read errors to stderr, and registers it into its own registry.

func NewWithLogger

func NewWithLogger(factory Factory, logger io.Writer) *Exporter

NewWithLogger is the test seam: it lets callers capture the stderr log sink.

func (*Exporter) Collect

func (e *Exporter) Collect(ch chan<- prometheus.Metric)

Collect implements prometheus.Collector. It NEVER propagates an error to promhttp (R4d): on any failure it logs and emits gpu_tools_up 0 with no device series. The whole read is mutex-guarded so overlapping scrapes never race the inner collector (R4a).

func (*Exporter) Describe

func (e *Exporter) Describe(ch chan<- *prometheus.Desc)

Describe implements prometheus.Collector. Sending descriptors here keeps the registry from treating the collector as unchecked.

func (*Exporter) Registry

func (e *Exporter) Registry() *prometheus.Registry

Registry returns the Exporter's own registry (R4b). Serve /metrics via promhttp.HandlerFor(exp.Registry(), ...).

type Factory

type Factory func() (gpu.Collector, error)

Factory builds the underlying gpu.Collector. It matches the shape of gpu.DefaultFactory bound to a resolved config.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL