target

package
v1.2.15 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2023 License: LGPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Mapper

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

Mapper manages the http.Handler we create for each BMC being scraped. Given a target addr, it returns a promhttp-created handler that, when invoked, will retrieve and yield metrics for that BMC.

func NewMapper

func NewMapper(p Provider) *Mapper

NewMapper creates a Mapper struct ready for mapping targets to handlers.

func (*Mapper) Close

func (m *Mapper) Close()

func (*Mapper) Handler

func (m *Mapper) Handler(addr string) http.Handler

Handler returns a http.Handler that returns metrics collected from the BMC at the provided address. If the address has been requested before, this will return the original handler, otherwise it will create a new one. It is effectively a synchronised, lazy map access.

type Provider

type Provider interface {

	// TargetFor returns a target struct for the provided address.
	TargetFor(addr string) *Target
}

Provider creates target structs. This exists to shield the mapper from the relative complexity of creating collectors and targets from them.

type ProviderFunc

type ProviderFunc func(addr string) *Target

ProviderFunc allows creating a Provider implementation from a function.

func (ProviderFunc) TargetFor

func (f ProviderFunc) TargetFor(addr string) *Target

TargetFor implements Provider.

type Target

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

Target is the outermost wrapper around a BMC being scraped. It encapsulates the Collector implementation, implementing an event loop around it. This serialises access to a BMC, freeing us from locking.

func New

func New(c *collector.Collector) *Target

New constructs and starts a new BMC target. Be sure to call Close() when finished with it to terminate the event loop and underlying BMC connection.

func (*Target) Close

func (t *Target) Close()

Close cleanly terminates the connection and resources associated with the BMC. This method must only be called once, otherwise it will panic.

func (*Target) LastCollection

func (t *Target) LastCollection() int64

func (*Target) ServeHTTP

func (t *Target) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP satisfies http.Handler, allowing this BMC to respond to scrape requests.

Jump to

Keyboard shortcuts

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