Configure service discovery rules¶
Observable Insight supports the way of creating CRD ServiceMonitor through container management
to meet your collection requirements for custom service discovery. Users can use ServiceMonitor to define the scope of the Namespace discovered by the Pod and select the monitored Service through matchLabel
.
Prerequisites¶
The cluster has the Helm application insight-agent
installed and in the running
state.
Steps¶
-
Select
Acquisition Management
on the left navigation bar to view the status of all cluster collection plug-ins. -
Click the list
cluster name
to enter the collection configuration details. -
Click the link to jump to
Container Management
to create a Service Monitor.
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: micrometer-demo
namespace: insight-system
operator.insight.io/managed-by: insight
spec:
endpoints:
- honorLabels: true
interval: 15s
path: /actuator/prometheus
port: http
namespaceSelector:
matchNames:
-insight-system
selector:
matchLabels:
micrometer-prometheus-discovery: "true"
In the above YAML file, the meaning of each field is as follows:
-
name
andnamespace
undermetadata
will specify some key meta information required by ServiceMonitor. -
endpoints
ofspec
is the service endpoint, which represents the address of the collected Metrics required by Prometheus.endpoints
is an array, and multipleendpoints
can be created at the same time. Eachendpoints
contains three fields, and the meaning of each field is as follows: -
interval
: Specifies the period for Prometheus to collect the currentendpoints
. The unit is seconds, set to15s
in this example. path
: Specify the collection path of Prometheus. In this example, it is specified as/actuator/prometheus
.-
port
: Specify the port through which the collected data needs to pass, and the set port is thename
set by the collected Service port. -
namespaceSelector
ofspec
is the scope of the Service that needs to be discovered.namespaceSelector
contains two mutually exclusive fields with the following meanings: -
any
: There is one and only one valuetrue
, when this field is set, it will monitor the changes of all services that meet the filter conditions of the Selector. -
matchNames
: an array value, specifying the range ofnamespace
that needs to be monitored. For example, if you only want to listen to Services in the default and insight-system namespaces, thenmatchNames
is set as follows:```yaml
namespaceSelector: matchNames: - default -insight-system ```
-
The
selector
ofspec
is used to select the Service.