Documentation
¶
Overview ¶
Package instance provides a mini Prometheus scraper and remote_writer.
Index ¶
Constants ¶
This section is empty.
Variables ¶
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
var ( DefaultRemoteWriteConfig = RemoteWriteConfig{ RemoteTimeout: model.Duration(30 * time.Second), QueueConfig: config.DefaultQueueConfig, MetadataConfig: config.DefaultMetadataConfig, } )
var (
ErrInstanceStoppedNormally = errors.New("instance shutdown normally")
)
Functions ¶
Types ¶
type BasicAuth ¶
type BasicAuth struct {
Username string `yaml:"username"`
Password string `yaml:"password,omitempty"`
PasswordFile string `yaml:"password_file,omitempty"`
}
func (*BasicAuth) UnmarshalYAML ¶
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 ¶
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 ¶
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:
__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.
__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.
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.
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.