Receiver Creator
This receiver can instantiate other receivers at runtime based on whether
observed endpoints match a configured rule. To use the receiver creator, you
must first configure one or more
observers that will discover networked
endpoints that you may be interested in. The configured rules will be
evaluated for each endpoint discovered. If the rule evaluates to true then
the receiver for that rule will be started against the matched endpoint.
Configuration
watch_observers
A list of observers previously defined to be run in the extensions
section.
receiver_creator will watch for endpoints generated by these observers.
receivers
A map of receiver names (e.g. redis/1
) to a template for when and how to
instantiate that receiver.
receivers.<receiver_type/id>.rule
Rule expression using expvar
syntax.
Variables available are detailed below in Rule
Expressions.
receivers.<receiver_type/id>.config
This is configuration that will be used when creating the receiver at
runtime.
This option can use static and dynamic configuration values. Static values
are normal YAML values. However the value can also be dynamically constructed
from the discovered endpoint object. Dynamic values are surrounded by
backticks (`). If a literal backtick is needed use \` to escape it. Dynamic
values can be used with static values in which case they are concatenated.
For example:
config:
secure_url: https://`pod.labels["secure_host"]`
The value of secure_url
will be https://
concatenated with the value of
the secure_host
label.
This can also be used when the discovered endpoint needs to be changed
dynamically. For instance, suppose the IP 1.2.3.4
is discovered without a
port but the port needs to be set inside endpoint. You could do:
config:
endpoint: `endpoint`:8080
Rule Expressions
Each rule must start with type.(pod|port) &&
such that the rule matches
only one endpoint type. Depending on the type of endpoint the rule is
targeting it will have different variables available.
Pod
Variable |
Description |
type.pod |
true |
name |
name of the pod |
labels |
map of labels set on the pod |
annotations |
map of annotations set on the pod |
Port
Variable |
Description |
type.port |
true |
name |
container port name |
port |
port number |
pod.name |
name of the owning pod |
pod.labels |
map of labels of the owning pod |
pod.annotations |
map of annotations of the owning pod |
protocol |
TCP or UDP |
Example
extensions:
# Configures the Kubernetes observer to watch for pod start and stop events.
k8s_observer:
host_observer:
receivers:
receiver_creator/1:
# Name of the extensions to watch for endpoints to start and stop.
watch_observers: [k8s_observer]
receivers:
prometheus_simple:
# Configure prometheus scraping if standard prometheus annotations are set on the pod.
rule: type.pod && annotations["prometheus.io/scrape"] == "true"
config:
metrics_path: '`"prometheus.io/path" in annotations ? annotations["prometheus.io/path"] : "/metrics"`'
endpoint: '`endpoint`:`"prometheus.io/port" in annotations ? annotations["prometheus.io/port"] : 9090`'
redis/1:
# If this rule matches an instance of this receiver will be started.
rule: type.port && port == 6379
config:
# Static receiver-specific config.
password: secret
# Dynamic configuration value.
service_name: `pod.labels["service_name"]`
receiver_creator/2:
# Name of the extensions to watch for endpoints to start and stop.
watch_observers: [host_observer]
receivers:
redis/on_host:
# If this rule matches an instance of this receiver will be started.
rule: type.port && port == 6379 && is_ipv6 == true
config:
service_name: redis_on_host
processors:
exampleprocessor:
exporters:
exampleexporter:
service:
pipelines:
metrics:
receivers: [receiver_creator/1, receiver_creator/2]
processors: [exampleprocessor]
exporters: [exampleexporter]
extensions: [k8s_observer, host_observer]
The full list of settings exposed for this receiver are documented here
with detailed sample configurations here.