prometheus

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2020 License: Apache-2.0 Imports: 30 Imported by: 0

Documentation

Overview

Package prometheus 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

This section is empty.

Variables

View Source
var (
	// DefaultRelabelConfigs defines a list of relabel_configs that will
	// be automatically appended to the end of all Prometheus
	// configurations.
	DefaultRelabelConfigs = []*relabel.Config{

		{
			SourceLabels: model.LabelNames{"__meta_kubernetes_pod_node_name"},
			TargetLabel:  "__host__",
			Action:       relabel.Replace,
			Separator:    ";",
			Regex:        relabel.MustNewRegexp("(.*)"),
			Replacement:  "$1",
		},
	}

	DefaultInstanceConfig = InstanceConfig{
		HostFilter:           false,
		WALTruncateFrequency: 1 * time.Minute,
		RemoteFlushDeadline:  1 * time.Minute,
		WriteStaleOnShutdown: true,
	}
)

Default configuration values

View Source
var (
	DefaultConfig = Config{
		Global:                 config.DefaultGlobalConfig,
		InstanceRestartBackoff: 5 * time.Second,
	}
)

Functions

This section is empty.

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(cfg Config, logger log.Logger) (*Agent, error)

New creates and starts a new Agent.

func (*Agent) Stop

func (a *Agent) Stop()

Stop stops the agent and all its instances.

type Config

type Config struct {
	Global                 config.GlobalConfig `yaml:"global"`
	WALDir                 string              `yaml:"wal_directory"`
	Configs                []InstanceConfig    `yaml:"configs,omitempty"`
	InstanceRestartBackoff time.Duration       `yaml:"instance_restart_backoff,omitempty"`
}

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

func (*Config) RegisterFlags

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

RegisterFlags defines flags corresponding to the Config.

func (*Config) UnmarshalYAML

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

func (*Config) Validate

func (c *Config) Validate() error

Validate checks if the Config has all required fields filled out.

type DiscoveredGroups

type DiscoveredGroups = map[string][]*targetgroup.Group

DiscoveredGroups is a set of groups found via service discovery.

func FilterGroups

func FilterGroups(in DiscoveredGroups, host string) DiscoveredGroups

FilterGroups takes a set of DiscoveredGroups as input and filters out any Target that is not running on the host machine provided by host.

This is done by looking at two labels:

  1. __meta_kubernetes_pod_node_name is used first to represent the host machine of networked containers. Primarily useful for Kubernetes. This label is automatically added when using Kubernetes service discovery.

  2. __address__ is used next to represent the address of the service to scrape. In a containerized envirment, __address__ will be the address of the container.

If the discovered address is localhost or 127.0.0.1, the group is never filtered out.

type GroupChannel

type GroupChannel = <-chan DiscoveredGroups

GroupChannel is a channel that provides discovered target groups.

type HostFilter

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

HostFilter acts as a MITM between the discovery manager and the scrape manager, filtering out discovered targets that are not running on the same node as the agent itself.

func NewHostFilter

func NewHostFilter(host string) *HostFilter

NewHostFilter creates a new HostFilter

func (*HostFilter) Run

func (f *HostFilter) Run(syncCh GroupChannel)

func (*HostFilter) Stop

func (f *HostFilter) Stop()

Stop stops the host filter from processing more target updates.

func (*HostFilter) SyncCh

func (f *HostFilter) SyncCh() GroupChannel

SyncCh returns a read only channel used by all the clients to receive target updates.

type Instance

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

Instance is an individual metrics collector and remote_writer.

func NewInstance

func NewInstance(globalCfg config.GlobalConfig, cfg InstanceConfig, walDir string, logger log.Logger) (*Instance, error)

NewInstance creates and starts a new Instance. NewInstance creates a WAL in a folder with the same name as the instance's name in a subdirectory of the walDir parameter.

func (*Instance) Config

func (i *Instance) Config() InstanceConfig

Config returns the instance's config.

func (*Instance) Err

func (i *Instance) Err() error

Err returns the error generated by instance when shut down. If the shutdown was intentional (i.e., the user called stop), then Err returns errInstanceStoppedNormally.

func (*Instance) Stop

func (i *Instance) Stop()

Stop stops the instance.

func (*Instance) Wait

func (i *Instance) Wait() error

Wait blocks until the instance exits, returning its error, if any.

type InstanceConfig

type InstanceConfig struct {
	Name          string                      `yaml:"name"`
	HostFilter    bool                        `yaml:"host_filter"`
	ScrapeConfigs []*config.ScrapeConfig      `yaml:"scrape_configs,omitempty"`
	RemoteWrite   []*config.RemoteWriteConfig `yaml:"remote_write,omitempty"`

	// How frequently the WAL should be truncated.
	WALTruncateFrequency time.Duration `yaml:"wal_truncate_frequency,omitempty"`

	RemoteFlushDeadline  time.Duration `yaml:"remote_flush_deadline,omitempty"`
	WriteStaleOnShutdown bool          `yaml:"write_stale_on_shutdown,omitempty"`
}

InstanceConfig is a specific agent that runs within the overall Prometheus agent. It has its own set of scrape_configs and remote_write rules.

func (*InstanceConfig) ApplyDefaults

func (c *InstanceConfig) ApplyDefaults(global *config.GlobalConfig)

ApplyDefaults applies default configurations to the configuration to all values that have not been changed to their non-zero value.

func (*InstanceConfig) UnmarshalYAML

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

func (*InstanceConfig) Validate

func (c *InstanceConfig) Validate() error

Validate checks if the InstanceConfig has all required fields filled out. This should only be called after ApplyDefaults.

type MetricValueCollector

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

MetricValueCollector wraps around a Gatherer and provides utilities for pulling metric values from a given metric name and label matchers.

This is used by the agent instances to find the most recent timestamp successfully remote_written to for pruposes of safely truncating the WAL.

MetricValueCollector is only intended for use with Gauges and Counters.

func NewMetricValueCollector

func NewMetricValueCollector(g prometheus.Gatherer, match string) *MetricValueCollector

NewMetricValueCollector creates a new MetricValueCollector.

func (*MetricValueCollector) GetValues

func (vc *MetricValueCollector) GetValues(label string, labelValues ...string) ([]float64, error)

GetValues looks through all the tracked metrics and returns all values for metrics that match some key value pair.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳