All Products
Search
Document Center

:Configure a data collection rule for Prometheus Monitoring

Last Updated:Mar 04, 2024

You can edit the prometheus.yaml file or add ServiceMonitor to configure a data collection rule. Then, Prometheus Monitoring can use the rule to monitor an application.

Prerequisites

The Prometheus agent is installed for an application. For more information, see Create a Prometheus instance to monitor an ACK cluster.

Procedure

  1. Log on to the Prometheus console.
  2. In the upper-left corner of the Prometheus Monitoring page, select the region where your Container Service for Kubernetes (ACK) clusters reside. Find the cluster that you want to manage and click Settings in the Actions column.
  3. Configure data collection rules for Managed Service for Prometheus to monitor the application in the following scenarios:
    • To monitor the business data of the application that is deployed to the ACK cluster, such as order information, perform the following steps:
      1. In the left-side navigation pane, click Service Discovery. Then, click the Configure tab.
      2. On the Configure tab, click the ServiceMonitor tab. Then, click Add ServiceMonitor.
      3. In the Add ServiceMonitor dialog box, enter the following code and click OK:
        apiVersion: monitoring.coreos.com/v1
        kind: ServiceMonitor
        metadata:
          # Enter a unique name.
          name: tomcat-demo
          # Enter a namespace.
          namespace: default
        spec:
          endpoints:
          - interval: 30s
            #  Enter the value of the Name field of the Port parameter of the Prometheus exporter in the service.yaml file.
            port: tomcat-monitor
            #  Enter the path of the Prometheus exporter.
            path: /metrics
          namespaceSelector:
            any: true
            # The namespace of the demo.
          selector:
            matchLabels:
              # Enter the value of the Label field in the service.yaml file to find the service.yaml file.
              app: tomcat

        The configured service discovery task is displayed on the ServiceMonitor tab.

        Service discovery
    • To monitor business data outside the ACK cluster, such as the number of Redis connections, perform the following steps:
      1. In the left-side navigation pane, click Settings. On the Settings page, click Edit Prometheus.yaml.
      2. In the dialog box that appears, enter the following code and click Save:
        global:
          scrape_interval:     15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
          evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
        scrape_configs:
          - job_name: 'prometheus'
            static_configs:
            - targets: ['localhost:9090']