Documentation ¶
Overview ¶
Package instance provides a mini Prometheus scraper and remote_writer.
Index ¶
- Variables
- func Hostname() (string, error)
- func MarshalConfig(c *Config, scrubSecrets bool) ([]byte, error)
- func MarshalConfigToWriter(c *Config, w io.Writer, scrubSecrets bool) error
- type BasicManager
- func (m *BasicManager) ApplyConfig(c Config) error
- func (m *BasicManager) DeleteConfig(name string) error
- func (m *BasicManager) GetInstance(name string) (ManagedInstance, error)
- func (m *BasicManager) ListConfigs() map[string]Config
- func (m *BasicManager) ListInstances() map[string]ManagedInstance
- func (m *BasicManager) Stop()
- func (m *BasicManager) UpdateManagerConfig(c BasicManagerConfig)
- type BasicManagerConfig
- type Config
- type DiscoveredGroups
- type ErrInvalidUpdate
- type Factory
- type GlobalConfig
- type GroupChannel
- type GroupManager
- func (m *GroupManager) ApplyConfig(c Config) error
- func (m *GroupManager) DeleteConfig(name string) error
- func (m *GroupManager) GetInstance(name string) (ManagedInstance, error)
- func (m *GroupManager) ListConfigs() map[string]Config
- func (m *GroupManager) ListInstances() map[string]ManagedInstance
- func (m *GroupManager) Stop()
- type HostFilter
- type Instance
- func (i *Instance) Appender(ctx context.Context) storage.Appender
- func (i *Instance) Ready() bool
- func (i *Instance) Run(ctx context.Context) error
- func (i *Instance) StorageDirectory() string
- func (i *Instance) TargetsActive() map[string][]*scrape.Target
- func (i *Instance) Update(c Config) (err error)
- func (i *Instance) WriteHandler() http.Handler
- type ManagedInstance
- type Manager
- type MockManager
- func (m MockManager) ApplyConfig(c Config) error
- func (m MockManager) DeleteConfig(name string) error
- func (m MockManager) GetInstance(name string) (ManagedInstance, error)
- func (m MockManager) ListConfigs() map[string]Config
- func (m MockManager) ListInstances() map[string]ManagedInstance
- func (m MockManager) Stop()
- type ModalManager
- func (m *ModalManager) ApplyConfig(c Config) error
- func (m *ModalManager) DeleteConfig(name string) error
- func (m *ModalManager) GetInstance(name string) (ManagedInstance, error)
- func (m *ModalManager) ListConfigs() map[string]Config
- func (m *ModalManager) ListInstances() map[string]ManagedInstance
- func (m *ModalManager) SetMode(newMode Mode) error
- func (m *ModalManager) Stop()
- type Mode
- type NoOpInstance
- func (NoOpInstance) Appender(_ context.Context) storage.Appender
- func (NoOpInstance) Ready() bool
- func (NoOpInstance) Run(ctx context.Context) error
- func (NoOpInstance) StorageDirectory() string
- func (NoOpInstance) TargetsActive() map[string][]*scrape.Target
- func (NoOpInstance) Update(_ Config) error
- func (NoOpInstance) WriteHandler() http.Handler
Constants ¶
This section is empty.
Variables ¶
var ( // DefaultBasicManagerConfig is the default config for the BasicManager. DefaultBasicManagerConfig = BasicManagerConfig{ InstanceRestartBackoff: 5 * time.Second, } )
var ( DefaultConfig = Config{ HostFilter: false, WALTruncateFrequency: 60 * time.Minute, MinWALTime: 5 * time.Minute, MaxWALTime: 4 * time.Hour, RemoteFlushDeadline: 1 * time.Minute, WriteStaleOnShutdown: false, // contains filtered or unexported fields } )
Default configuration values
var DefaultGlobalConfig = GlobalConfig{ Prometheus: config.DefaultGlobalConfig, }
DefaultGlobalConfig holds default global settings to be used across all instances.
var ErrNotReady = errors.New("Scrape manager not ready")
ErrNotReady is returned when the scrape manager is used but has not been initialized yet.
var HostFilterLabelMatchers = []string{
"__meta_consul_node",
"__meta_dockerswarm_node_id",
"__meta_dockerswarm_node_hostname",
"__meta_dockerswarm_node_address",
"__meta_kubernetes_pod_node_name",
"__meta_kubernetes_node_name",
"__host__",
}
HostFilterLabelMatchers are the set of labels that will be used to match against an incoming target.
Functions ¶
func Hostname ¶
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 ¶
MarshalConfig marshals an instance config based on a provided content type.
Types ¶
type BasicManager ¶
type BasicManager struct {
// contains filtered or unexported fields
}
BasicManager creates a new BasicManager, implementing the Manager interface. BasicManager will directly launch instances and perform no extra processing.
Other implementations of Manager usually wrap a BasicManager.
func NewBasicManager ¶
func NewBasicManager(cfg BasicManagerConfig, logger log.Logger, launch Factory) *BasicManager
NewBasicManager creates a new BasicManager. The launch function will be invoked any time a new Config is applied.
The lifecycle of any ManagedInstance returned by the launch function will be handled by the BasicManager. Instances will be automatically restarted if stopped, updated if the config changes, or removed when the Config is deleted.
func (*BasicManager) ApplyConfig ¶
func (m *BasicManager) ApplyConfig(c Config) error
ApplyConfig takes a Config and either starts a new managed instance or updates an existing managed instance. The value for Name in c is used to uniquely identify the Config and determine whether the Config has an existing associated managed instance.
func (*BasicManager) DeleteConfig ¶
func (m *BasicManager) DeleteConfig(name string) error
DeleteConfig removes a managed instance by its config name. Returns an error if there is no such managed instance with the given name.
func (*BasicManager) GetInstance ¶
func (m *BasicManager) GetInstance(name string) (ManagedInstance, error)
GetInstance returns the given instance by name.
func (*BasicManager) ListConfigs ¶
func (m *BasicManager) ListConfigs() map[string]Config
ListConfigs lists the current active configs managed by BasicManager.
func (*BasicManager) ListInstances ¶
func (m *BasicManager) ListInstances() map[string]ManagedInstance
ListInstances returns the current active instances managed by BasicManager.
func (*BasicManager) Stop ¶
func (m *BasicManager) Stop()
Stop stops the BasicManager and stops all active processes for configs.
func (*BasicManager) UpdateManagerConfig ¶
func (m *BasicManager) UpdateManagerConfig(c BasicManagerConfig)
UpdateManagerConfig updates the BasicManagerConfig.
type BasicManagerConfig ¶
BasicManagerConfig controls the operations of a BasicManager.
type Config ¶
type Config struct { Name string `yaml:"name,omitempty"` HostFilter bool `yaml:"host_filter,omitempty"` HostFilterRelabelConfigs []*relabel.Config `yaml:"host_filter_relabel_configs,omitempty"` 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"` // Minimum and maximum time series should exist in the WAL for. MinWALTime time.Duration `yaml:"min_wal_time,omitempty"` MaxWALTime time.Duration `yaml:"max_wal_time,omitempty"` RemoteFlushDeadline time.Duration `yaml:"remote_flush_deadline,omitempty"` WriteStaleOnShutdown bool `yaml:"write_stale_on_shutdown,omitempty"` // contains filtered or unexported fields }
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 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.
The value for global will be saved.
func (Config) MarshalYAML ¶
MarshalYAML implements yaml.Marshaler.
func (*Config) UnmarshalYAML ¶
UnmarshalYAML implements yaml.Unmarshaler.
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, configs []*relabel.Config) 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 HostFilterLabelMatchers and __address__.
If the discovered address is localhost or 127.0.0.1, the group is never filtered out.
type ErrInvalidUpdate ¶
type ErrInvalidUpdate struct {
Inner error
}
ErrInvalidUpdate is returned whenever Update is called against an instance but an invalid field is changed between configs. If ErrInvalidUpdate is returned, the instance must be fully stopped and replaced with a new one with the new config.
func (ErrInvalidUpdate) As ¶
func (e ErrInvalidUpdate) As(err interface{}) bool
As will set the err object to ErrInvalidUpdate provided err is a pointer to ErrInvalidUpdate.
func (ErrInvalidUpdate) Error ¶
func (e ErrInvalidUpdate) Error() string
Error implements the error interface.
func (ErrInvalidUpdate) Is ¶
func (e ErrInvalidUpdate) Is(err error) bool
Is returns true if err is an ErrInvalidUpdate.
type Factory ¶
type Factory func(c Config) (ManagedInstance, error)
Factory should return an unstarted instance given some config.
type GlobalConfig ¶
type GlobalConfig struct { Prometheus config.GlobalConfig `yaml:",inline"` RemoteWrite []*config.RemoteWriteConfig `yaml:"remote_write,omitempty"` ExtraMetrics bool `yaml:"-"` DisableKeepAlives bool `yaml:"-"` IdleConnTimeout time.Duration `yaml:"-"` }
GlobalConfig holds global settings that apply to all instances by default.
func (GlobalConfig) IsZero ¶ added in v0.31.0
func (c GlobalConfig) IsZero() bool
func (*GlobalConfig) UnmarshalYAML ¶
func (c *GlobalConfig) UnmarshalYAML(unmarshal func(interface{}) error) error
UnmarshalYAML implements yaml.Unmarshaler.
type GroupChannel ¶
type GroupChannel = <-chan DiscoveredGroups
GroupChannel is a channel that provides discovered target groups.
type GroupManager ¶
type GroupManager struct {
// contains filtered or unexported fields
}
A GroupManager wraps around another Manager and groups all incoming Configs into a smaller set of configs, causing less managed instances to be spawned.
Configs are grouped by all settings for a Config *except* scrape configs. Any difference found in any flag will cause a Config to be placed in another group. One exception to this rule is that remote_writes are compared unordered, but the sets of remote_writes should otherwise be identical.
GroupManagers drastically improve the performance of the Agent when a significant number of instances are spawned, as the overhead of each instance having its own service discovery, WAL, and remote_write can be significant.
The config names of instances within the group will be represented by that group's hash of settings.
func NewGroupManager ¶
func NewGroupManager(inner Manager) *GroupManager
NewGroupManager creates a new GroupManager for combining instances of the same "group."
func (*GroupManager) ApplyConfig ¶
func (m *GroupManager) ApplyConfig(c Config) error
ApplyConfig will determine the group of the Config before applying it to the group. If no group exists, one will be created. If a group already exists, the group will have its settings merged with the Config and will be updated.
func (*GroupManager) DeleteConfig ¶
func (m *GroupManager) DeleteConfig(name string) error
DeleteConfig will remove a Config from its associated group. If there are no more Configs within that group after this Config is deleted, the managed instance will be stopped. Otherwise, the managed instance will be updated with the new grouped Config that doesn't include the removed one.
func (*GroupManager) GetInstance ¶
func (m *GroupManager) GetInstance(name string) (ManagedInstance, error)
GetInstance gets the underlying grouped instance for a given name.
func (*GroupManager) ListConfigs ¶
func (m *GroupManager) ListConfigs() map[string]Config
ListConfigs returns the UNGROUPED instance configs with their original settings. To see the grouped instances, call ListInstances instead.
func (*GroupManager) ListInstances ¶
func (m *GroupManager) ListInstances() map[string]ManagedInstance
ListInstances returns all currently grouped managed instances. The key will be the group's hash of shared settings.
func (*GroupManager) Stop ¶
func (m *GroupManager) Stop()
Stop stops the Manager and all of its managed instances.
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, relabels []*relabel.Config) *HostFilter
NewHostFilter creates a new HostFilter.
func (*HostFilter) PatchSD ¶
func (f *HostFilter) PatchSD(scrapes []*config.ScrapeConfig)
PatchSD patches services discoveries to optimize performance for host filtering. The discovered targets will be pruned to as close to the set that HostFilter will output as possible.
func (*HostFilter) Run ¶
func (f *HostFilter) Run(syncCh GroupChannel)
Run starts the HostFilter. It only exits when the HostFilter is stopped. Run will continually read from syncCh and filter groups discovered down to targets that are colocated on the same node as the one the HostFilter is running in.
func (*HostFilter) SetRelabels ¶
func (f *HostFilter) SetRelabels(relabels []*relabel.Config)
SetRelabels updates the relabeling rules used by the HostFilter.
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(reg prometheus.Registerer, 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) Ready ¶ added in v0.22.9
Ready returns true if the Instance has been initialized and is ready to start scraping and delivering metrics.
func (*Instance) Run ¶
Run starts the instance, initializing Prometheus components, and will continue to run until an error happens during execution or the provided context is cancelled.
Run may be re-called after exiting, as components will be reinitialized each time Run is called.
func (*Instance) StorageDirectory ¶
StorageDirectory returns the directory where this Instance is writing series and samples to for the WAL.
func (*Instance) TargetsActive ¶
TargetsActive returns the set of active targets from the scrape manager. Returns nil if the scrape manager is not ready yet.
func (*Instance) Update ¶
Update accepts a new Config for the Instance and will dynamically update any running Prometheus components with the new values from Config. Update will return an ErrInvalidUpdate if the Update could not be applied.
func (*Instance) WriteHandler ¶ added in v0.40.0
WriteHandler returns an HTTP handler for pushing metrics directly into the instance's WAL.
type ManagedInstance ¶
type ManagedInstance interface { Run(ctx context.Context) error Ready() bool Update(c Config) error TargetsActive() map[string][]*scrape.Target StorageDirectory() string Appender(ctx context.Context) storage.Appender WriteHandler() http.Handler }
ManagedInstance is implemented by Instance. It is defined as an interface for the sake of testing from Manager implementations.
type Manager ¶
type Manager interface { // GetInstance retrieves a ManagedInstance by name. GetInstance(name string) (ManagedInstance, error) // ListInstances returns all currently managed instances running // within the Manager. The key will be the instance name from their config. ListInstances() map[string]ManagedInstance // ListConfigs returns the config objects associated with a managed // instance. The key will be the Name field from Config. ListConfigs() map[string]Config // ApplyConfig creates a new Config or updates an existing Config if // one with Config.Name already exists. ApplyConfig(Config) error // DeleteConfig deletes a given managed instance based on its Config.Name. DeleteConfig(name string) error // Stop stops the Manager and all managed instances. Stop() }
Manager represents a set of methods for manipulating running instances at runtime.
type MockManager ¶
type MockManager struct { GetInstanceFunc func(name string) (ManagedInstance, error) ListInstancesFunc func() map[string]ManagedInstance ListConfigsFunc func() map[string]Config ApplyConfigFunc func(Config) error DeleteConfigFunc func(name string) error StopFunc func() }
MockManager exposes methods of the Manager interface as struct fields. Useful for tests.
func (MockManager) ApplyConfig ¶
func (m MockManager) ApplyConfig(c Config) error
ApplyConfig implements Manager.
func (MockManager) DeleteConfig ¶
func (m MockManager) DeleteConfig(name string) error
DeleteConfig implements Manager.
func (MockManager) GetInstance ¶
func (m MockManager) GetInstance(name string) (ManagedInstance, error)
GetInstance implements Manager.
func (MockManager) ListConfigs ¶
func (m MockManager) ListConfigs() map[string]Config
ListConfigs implements Manager.
func (MockManager) ListInstances ¶
func (m MockManager) ListInstances() map[string]ManagedInstance
ListInstances implements Manager.
type ModalManager ¶
type ModalManager struct {
// contains filtered or unexported fields
}
ModalManager runs instances by either grouping them or running them fully separately.
func NewModalManager ¶
func NewModalManager(reg prometheus.Registerer, l log.Logger, next Manager, mode Mode) (*ModalManager, error)
NewModalManager creates a new ModalManager.
func (*ModalManager) ApplyConfig ¶
func (m *ModalManager) ApplyConfig(c Config) error
ApplyConfig implements Manager.
func (*ModalManager) DeleteConfig ¶
func (m *ModalManager) DeleteConfig(name string) error
DeleteConfig implements Manager.
func (*ModalManager) GetInstance ¶
func (m *ModalManager) GetInstance(name string) (ManagedInstance, error)
GetInstance implements Manager.
func (*ModalManager) ListConfigs ¶
func (m *ModalManager) ListConfigs() map[string]Config
ListConfigs implements Manager.
func (*ModalManager) ListInstances ¶
func (m *ModalManager) ListInstances() map[string]ManagedInstance
ListInstances implements Manager.
func (*ModalManager) SetMode ¶
func (m *ModalManager) SetMode(newMode Mode) error
SetMode updates the mode ModalManager is running in. Changing the mode is an expensive operation; all underlying configs must be stopped and then reapplied.
type Mode ¶
type Mode string
Mode controls how instances are created.
var ( ModeDistinct Mode = "distinct" DefaultMode = ModeShared )
Types of instance modes
func (*Mode) UnmarshalYAML ¶
UnmarshalYAML unmarshals a string to a Mode. Fails if the string is unrecognized.
type NoOpInstance ¶
type NoOpInstance struct{}
NoOpInstance implements the Instance interface in pkg/prom but does not do anything. Useful for tests.
func (NoOpInstance) Appender ¶
func (NoOpInstance) Appender(_ context.Context) storage.Appender
Appender implements Instance
func (NoOpInstance) Ready ¶ added in v0.22.9
func (NoOpInstance) Ready() bool
Ready implements Instance.
func (NoOpInstance) Run ¶
func (NoOpInstance) Run(ctx context.Context) error
Run implements Instance.
func (NoOpInstance) StorageDirectory ¶
func (NoOpInstance) StorageDirectory() string
StorageDirectory implements Instance.
func (NoOpInstance) TargetsActive ¶
func (NoOpInstance) TargetsActive() map[string][]*scrape.Target
TargetsActive implements Instance.
func (NoOpInstance) WriteHandler ¶ added in v0.40.0
func (NoOpInstance) WriteHandler() http.Handler
WriteHandler implements Instance.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package configstore abstracts the concepts of where instance files get retrieved.
|
Package configstore abstracts the concepts of where instance files get retrieved. |