instance

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: May 20, 2020 License: Apache-2.0 Imports: 30 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

View Source
var (
	DefaultRemoteWriteConfig = RemoteWriteConfig{
		RemoteTimeout:  model.Duration(30 * time.Second),
		QueueConfig:    config.DefaultQueueConfig,
		MetadataConfig: config.DefaultMetadataConfig,
	}
)
View Source
var (
	ErrInstanceStoppedNormally = errors.New("instance shutdown normally")
)

Functions

func MarshalConfig

func MarshalConfig(c *Config, sanitize bool) (string, error)

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

Types

type BasicAuth

type BasicAuth struct {
	Username     string `yaml:"username"`
	Password     string `yaml:"password,omitempty"`
	PasswordFile string `yaml:"password_file,omitempty"`
}

func (*BasicAuth) UnmarshalYAML

func (a *BasicAuth) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML implements the yaml.Unmarshaler interface.

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   []*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)

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

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. This should only be called after ApplyDefaults.

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 HTTPClientConfig

type HTTPClientConfig struct {
	// The HTTP basic authentication credentials for the targets.
	BasicAuth *BasicAuth `yaml:"basic_auth,omitempty"`
	// The bearer token for the targets.
	BearerToken string `yaml:"bearer_token,omitempty"`
	// The bearer token file for the targets.
	BearerTokenFile string `yaml:"bearer_token_file,omitempty"`
	// HTTP proxy server to use to connect to the targets.
	ProxyURL config_util.URL `yaml:"proxy_url,omitempty"`
	// TLSConfig to use to connect to the targets.
	TLSConfig config_util.TLSConfig `yaml:"tls_config,omitempty"`
}

HTTPClientConfig configures an HTTP client.

func (*HTTPClientConfig) PrometheusConfig

func (c *HTTPClientConfig) PrometheusConfig() config_util.HTTPClientConfig

PrometheusConfig returns the Prometheus-config equivalent of HTTPClientConfig.

func (*HTTPClientConfig) UnmarshalYAML

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

UnmarshalYAML implements the yaml.Unmarshaler interface

func (*HTTPClientConfig) Validate

func (c *HTTPClientConfig) Validate() error

Validate validates the HTTPClientConfig to check only one of BearerToken, BasicAuth and BearerTokenFile is configured.

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 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() Config

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 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.

type RemoteWriteConfig

type RemoteWriteConfig struct {
	URL                 *config_util.URL  `yaml:"url"`
	RemoteTimeout       model.Duration    `yaml:"remote_timeout,omitempty"`
	WriteRelabelConfigs []*relabel.Config `yaml:"write_relabel_configs,omitempty"`
	Name                string            `yaml:"name,omitempty"`

	// We cannot do proper Go type embedding below as the parser will then parse
	// values arbitrarily into the overflow maps of further-down types.
	HTTPClientConfig HTTPClientConfig      `yaml:",inline"`
	QueueConfig      config.QueueConfig    `yaml:"queue_config,omitempty"`
	MetadataConfig   config.MetadataConfig `yaml:"metadata_config,omitempty"`
}

RemoteWriteConfig holds configuration for remote_write. It is duplicated from the Prometheus RemoteWriteConfig to allow for marshaling secrets to YAML.

func (*RemoteWriteConfig) PrometheusConfig

func (c *RemoteWriteConfig) PrometheusConfig() *config.RemoteWriteConfig

PrometheusConfig returns the Prometheus-config equivalent of RemoteWriteConfig.

func (*RemoteWriteConfig) Sanitize

func (c *RemoteWriteConfig) Sanitize()

Sanitize finds all secrets in the RemoteWriteConfig and replaces their values with <secret>.

func (*RemoteWriteConfig) UnmarshalYAML

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

UnmarshalYAML implements the yaml.Unmarshaler interface.

Jump to

Keyboard shortcuts

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