Docs
uk8s
Cluster Monitoring
Prometheus monitoring solution
Start Monitoring Center

Add Monitoring Target

A monitoring target can be understood as a Target or Job in Prometheus. Prometheus natively supports both static configuration of monitoring targets and dynamic service discovery.

Because the Pods in Kubernetes are set as non-persistent resources, in order to correctly capture the monitoring data of the Pods corresponding to each application, Prometheus Operator introduces the Service Monitor mechanism, which realizes data collection by monitoring the Endpoints (which can be regarded as healthy Pods) behind the Service.

So, in order to capture the monitoring data of a group of Pods, we must create a corresponding Service for this group of Pods and expose the corresponding Metrics port.

! It needs to be emphasized here that the Service must expose the Metrics port instead of the business port. Like if we have an application with an application port of 80 and a Metrics port of 9200, the Service port for Prometheus to capture data must be 9200. If set to 80, no monitoring data can be captured.

Operation Instructions

1. Deploy Application

In the following example, we have deployed a sample application, which is a web application. Its container exposes two ports to the outside, one is the business port 80, and the other is the Metrics port 8080. And we also created a Service with exposed ports consistent with the container ports.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: example-app
spec:
  replicas: 2
  selector:
    matchLabels:
      app: example-app
  template:
    metadata:
      labels:
        app: example-app
    spec:
      containers:
      - name: example-app
        image: uhub.ucloud-global.com/uk8s_public/instrumented_app:latest
        ports:
        - name: metrics
          containerPort: 8080
        - name: web
          containerPort: 80
---
kind: Service
apiVersion: v1
metadata:
  name: example-app
  labels:
    app: example-app
spec:
  selector:
    app: example-app
  ports:
  - name: metrics
    port: 8080
  - name: web
    port: 80

2. Add Monitoring Target

In the Monitoring Center of UK8S —> Monitoring Target page, we directly select this Service, choose “metrics” for the port name, usually the default path is “/metrics”. If the path of monitoring indicators is customized, please consult the business side.

  • Namespace: The name of the namespace where the server is deployed on the Kubernetes cluster
  • Service Name: The name of the service on the kubenetes cluster to get the metric
  • Port Name: The name of the port on the service to get the metric
  • Path: The access path to get the metric from the service

3. View Monitoring Target

After adding, we can open the Prometheus Console to check whether the monitoring target has been added successfully.