metrics

package
v1.3.191 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2022 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Overview

Package metrics implements a Prometheus-lite client for service discovery, scraping metrics into a WAL, and remote_write. Clients are broken into a set of instances, each of which contain their own set of configs.

Index

Constants

View Source
const (
	DefaultCleanupAge    = 12 * time.Hour
	DefaultCleanupPeriod = 30 * time.Minute
)

Default settings for the WAL cleaner.

Variables

View Source
var DefaultConfig = Config{
	Global:                 instance.DefaultGlobalConfig,
	InstanceRestartBackoff: instance.DefaultBasicManagerConfig.InstanceRestartBackoff,
	WALCleanupAge:          DefaultCleanupAge,
	WALCleanupPeriod:       DefaultCleanupPeriod,
	ServiceConfig:          cluster.DefaultConfig,
	ServiceClientConfig:    client.DefaultConfig,
	InstanceMode:           instance.DefaultMode,
}

DefaultConfig is the default settings for the Prometheus-lite client.

Functions

func ListTargetsHandler added in v0.22.0

func ListTargetsHandler(targets map[string]TargetSet) http.Handler

ListTargetsHandler renders a mapping of instance to target set.

Types

type Agent

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

Agent is an agent for collecting Prometheus metrics. It acts as a Prometheus-lite; only running the service discovery, remote_write, and WAL components of Prometheus. It is broken down into a series of Instances, each of which perform metric collection.

func New

func New(reg prometheus.Registerer, cfg Config, logger log.Logger) (*Agent, error)

New creates and starts a new Agent.

func (*Agent) ApplyConfig

func (a *Agent) ApplyConfig(cfg Config) error

ApplyConfig applies config changes to the Agent.

func (*Agent) Config

func (a *Agent) Config() Config

Config returns the configuration of this Agent.

func (*Agent) InstanceManager

func (a *Agent) InstanceManager() instance.Manager

InstanceManager returns the instance manager used by this Agent.

func (*Agent) ListInstancesHandler

func (a *Agent) ListInstancesHandler(w http.ResponseWriter, _ *http.Request)

ListInstancesHandler writes the set of currently running instances to the http.ResponseWriter.

func (*Agent) ListTargetsHandler

func (a *Agent) ListTargetsHandler(w http.ResponseWriter, r *http.Request)

ListTargetsHandler retrieves the full set of targets across all instances and shows information on them.

func (*Agent) Ready added in v0.22.9

func (a *Agent) Ready() bool

Ready returns true if both the agent and all instances spawned by a Manager have completed startup.

func (*Agent) Stop

func (a *Agent) Stop()

Stop stops the agent and all its instances.

func (*Agent) Validate

func (a *Agent) Validate(c *instance.Config) error

Validate will validate the incoming Config and mutate it to apply defaults.

func (*Agent) WireAPI

func (a *Agent) WireAPI(r *mux.Router)

WireAPI adds API routes to the provided mux router.

func (*Agent) WireGRPC

func (a *Agent) WireGRPC(s *grpc.Server)

WireGRPC wires gRPC services into the provided server.

type Config

type Config struct {
	Global                 instance.GlobalConfig `yaml:"global,omitempty"`
	WALDir                 string                `yaml:"wal_directory,omitempty"`
	WALCleanupAge          time.Duration         `yaml:"wal_cleanup_age,omitempty"`
	WALCleanupPeriod       time.Duration         `yaml:"wal_cleanup_period,omitempty"`
	ServiceConfig          cluster.Config        `yaml:"scraping_service,omitempty"`
	ServiceClientConfig    client.Config         `yaml:"scraping_service_client,omitempty"`
	Configs                []instance.Config     `yaml:"configs,omitempty,omitempty"`
	InstanceRestartBackoff time.Duration         `yaml:"instance_restart_backoff,omitempty"`
	InstanceMode           instance.Mode         `yaml:"instance_mode,omitempty"`

	// Unmarshaled is true when the Config was unmarshaled from YAML.
	Unmarshaled bool `yaml:"-"`
}

Config defines the configuration for the entire set of Prometheus client instances, along with a global configuration.

func (*Config) ApplyDefaults

func (c *Config) ApplyDefaults() error

ApplyDefaults applies default values to the Config and validates it.

func (*Config) RegisterFlags

func (c *Config) RegisterFlags(f *flag.FlagSet)

RegisterFlags defines flags corresponding to the Config.

func (*Config) RegisterFlagsWithPrefix

func (c *Config) RegisterFlagsWithPrefix(prefix string, f *flag.FlagSet)

RegisterFlagsWithPrefix defines flags with the provided prefix.

func (*Config) UnmarshalYAML

func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML implements yaml.Unmarshaler.

type ListTargetsResponse

type ListTargetsResponse []TargetInfo

ListTargetsResponse is returned by the ListTargetsHandler.

type TargetInfo

type TargetInfo struct {
	InstanceName string `json:"instance"`
	TargetGroup  string `json:"target_group"`

	Endpoint         string        `json:"endpoint"`
	State            string        `json:"state"`
	Labels           labels.Labels `json:"labels"`
	DiscoveredLabels labels.Labels `json:"discovered_labels"`
	LastScrape       time.Time     `json:"last_scrape"`
	ScrapeDuration   int64         `json:"scrape_duration_ms"`
	ScrapeError      string        `json:"scrape_error"`
}

TargetInfo describes a specific target.

type TargetSet added in v0.22.0

type TargetSet map[string][]*scrape.Target

TargetSet is a set of targets for an individual scraper.

type WALCleaner

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

WALCleaner periodically checks for Write Ahead Logs (WALs) that are not associated with any active instance.ManagedInstance and have not been written to in some configured amount of time and deletes them.

func NewWALCleaner

func NewWALCleaner(logger log.Logger, manager instance.Manager, walDirectory string, minAge time.Duration, period time.Duration) *WALCleaner

NewWALCleaner creates a new cleaner that looks for abandoned WALs in the given directory and removes them if they haven't been modified in over minAge. Starts a goroutine to periodically run the cleanup method in a loop

func (*WALCleaner) Stop

func (c *WALCleaner) Stop()

Stop the cleaner and any background tasks running

Directories

Path Synopsis
Package instance provides a mini Prometheus scraper and remote_writer.
Package instance provides a mini Prometheus scraper and remote_writer.
configstore
Package configstore abstracts the concepts of where instance files get retrieved.
Package configstore abstracts the concepts of where instance files get retrieved.

Jump to

Keyboard shortcuts

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