Our container auto-discovery feature allows you to configure an integration to automatically monitor services that run in multiple containers. In an integration's configuration file, you can set containers' matching criteria, and the agent executes the integration for each local container matching the criteria.
An integration will be executed as many times as it finds discovery elements. If discovery doesn't find any containers, the integration won't be executed.
ヒント
Currently, the infrastructure agent can discover local Docker containers.
Add placeholders to your configuration
In your integration configuration, you must create ${discovery.<property>}
placeholders. These will then be automatically replaced by specific container information.
These examples (for Docker-only environments and for Kubernetes) show how to configure an NGINX integration to monitor all local containers that have an image name containing nginx
, and that are labeled as env=production
. Each service will be available through different IPs and ports, so they must be variables.
Add discovery properties
To configure discovery, set up a discovery
entry in your integration configuration YAML using the following properties. A container will be matched when all the properties match the defined values.
ヒント
Properties values will be matched with an exact string, unless the value to match is set between /.../
. The contents within the slashes will be matched as regular expressions.
Discovery key name | Description |
---|---|
Type: String | Time-To-Live of the cached discovery results, used to minimize the number of discovery processes. Define as a number followed by a time unit ( Examples: Default: 1m |
Type: YAML properties | Docker containers matching definition. This consists of a
|
Discovery example
The following example matches all Docker containers whose image starts with httpd:
(provided as a regular expression) and are labeled as scrapable=yes
. The results are cached with a Time-To-Live of 5 minutes.
discovery: ttl: 5m docker: match: image: /^httpd:/ label.scrapable: yes
Available container information
Our discovery feature currently emits the following variables, which can be used to configure your integrations. The infrastructure agent replaces them with the corresponding values of the discovered containers.
重要
Be sure to add the discovery.
prefix.
Variable | Description |
---|---|
| Container public IP address, if any |
| Container private IP address |
| Container public port number |
| Container private port number |
| Image name |
| Container name |
| Any container label, accessible by its name |
Mapping multiple ports
When a container exposes many private or public ports, they can be accessed via discovery.private.ports.
or discovery.ports.
followed by an index starting in 0. The ports are indexed from the lower to higher private port value.
For example, a container that exposes the 80 and 443 private ports via the public ports 2345 and 1111, respectively, would provide the following variables with their respective values:
Variable | Value |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
重要
Notice that the port
word is singular in the non-indexed variables and plural in the indexed variables.
Mapping ports by protocol name
In addition to the indexing from the previous section, ports can be also referred by its protocol name (such as tcp
, udp
, etc.). For example, ${discovery.ports.tcp}
or ${discovery.ports.udp}
.
If multiple ports match to the same protocol, they can also be indexed by the rules in the previous section: ${discovery.ports.tcp.0}
, ${discovery.ports.tcp.1}
, and so on.