instance

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2020 License: Apache-2.0 Imports: 33 Imported by: 0

Documentation

Overview

Package instance provides a mini Prometheus scraper and remote_writer.

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",
		},
	}

	DefaultConfig = Config{
		HostFilter:           false,
		WALTruncateFrequency: 1 * time.Minute,
		RemoteFlushDeadline:  1 * time.Minute,
		WriteStaleOnShutdown: false,
	}
)

Default configuration values

Functions

func Hostname added in v0.4.0

func Hostname() (string, error)

Hostname retrieves the hostname identifying the machine the process is running on. It will return the value of $HOSTNAME, if defined, and fall back to Go's os.Hostname.

func MarshalConfig

func MarshalConfig(c *Config, scrubSecrets bool) ([]byte, error)

MarshalConfig marshals an instance config based on a provided content type.

func MarshalConfigToWriter

func MarshalConfigToWriter(c *Config, w io.Writer, scrubSecrets bool) error

MarshalConfigToWriter marshals a config to an io.Writer.

Types

type Config

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

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

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

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

func UnmarshalConfig

func UnmarshalConfig(r io.Reader) (*Config, error)

UnmarshalConfig unmarshals an instance config from a reader based on a provided content type.

func (*Config) ApplyDefaults

func (c *Config) ApplyDefaults(global *config.GlobalConfig) error

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

func (Config) MarshalYAML

func (c Config) MarshalYAML() (interface{}, error)

func (*Config) UnmarshalYAML

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

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 New

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

New creates a new Instance with a directory for storing the WAL. The instance will not start until Run is called on the instance.

func (*Instance) Run

func (i *Instance) Run(ctx context.Context) error

Run starts the instance and will run until an error happens during running or until context was canceled.

Run can be re-called after exiting.

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.

Jump to

Keyboard shortcuts

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