Prometheus Monitoring of Application Real-Time Monitoring Service (ARMS) allows you to monitor the running status of Go applications deployed in Alibaba Cloud Container Service Kubernetes clusters, view various monitoring data on the dashboard, and configure monitoring jobs and alerts. This tutorial describes how to expose data by using instrumentation points in Go applications, capture data by using ARMS Prometheus Monitoring, and display data on the ARMS Prometheus Grafana dashboard, to ultimately monitor Go applications with ARMS Prometheus Monitoring.

Prerequisites

Ensure that you have completed the following operations:

Background information

The following figure shows the workflow.

How it works

Step 1: Expose application data by instrumentation points in Go applications

Use Prometheus Exporter in Go applications to expose application data.

  1. Import the monitoring package to your Go application.
    import (
        "fmt"
        "github.com/prometheus/client_golang/prometheus/promhttp"
        "net/http"
        "strconv"
    )
  2. Bind the monitoring interface to promhttp.Handler().
    http.Handle(path, promhttp.Handler()) //Initializes an HTTP handler.

Step 2: Deploy the application to the Container Service Kubernetes cluster

Deploy the application to the Container Service Kubernetes cluster so that ARMS Prometheus Monitoring can monitor and capture the application data.

  1. Run the following commands in the buildDockerImage.sh file by row:
    mvn clean install -DskipTests
    docker build -t <name of the local temporary Docker image>:<version of the local temporary Docker image> . --no-cache
    sudo docker tag <name of the local temporary Docker image>:<version of the local temporary Docker image> <registry domain name>/<namespace>/<image name>:<image version>
    sudo docker push <registry domain name>/<namespace>/<image name>:<image version>
    Example:
    mvn clean install -DskipTests
    docker build -t promethues-arms-aliyun-go-demo:v0.1 . --no-cache
    sudo docker tag promethues-arms-aliyun-go-demo:v0.1 registry.cn-hangzhou.aliyuncs.com/fuling/prometheus-arms-aliyun-go-demo-amd64:dev-v0.1
    sudo docker push registry.cn-hangzhou.aliyuncs.com/fuling/promethues-demo:v0.1
    In this step, a Docker image named promethues-arms-aliyun-go-demo is created, and the image is pushed to Alibaba Cloud Docker Registry.
  2. In the left-side navigation pane, choose Clusters > Clusters. On the Clusters page, find the target cluster, and click Dashboard in the Actions column.
    Kubernetes cluster console button
  3. In the left-side navigation pane, choose Workloads > Deployments. In the upper-right corner, click CREATE, and enter the following information in the CREATE FROM TEXT INPUT section:
    apiVersion: extensions/v1beta1
    kind: Deployment
    metadata:
      name: promethues-arms-aliyun-go-demo
    spec:
      replicas: 2
      template:
        metadata:
          labels:
            app: promethues-arms-aliyun-go-demo
        spec:
          containers:
          - name: promethues-arms-aliyun-go-demo
            imagePullPolicy: Always
            image: registry.cn-hangzhou.aliyuncs.com/fuling/prometheus-arms-aliyun-go-demo-amd64:dev-v0.1
            ports:
            - containerPort: 8077
              name: arms-go-demo
    In this step, the Docker image created in 1 is deployed to the Container Service Kubernetes cluster.
  4. In the left-side navigation pane, choose Discovery and Load Balancing > Services. In the upper-right corner, click CREATE, and enter the following information in the CREATE FROM TEXT INPUT section:
    apiVersion: v1
    kind: Service
    metadata:
      labels:
        app: promethues-arms-aliyun-go-demo
      name: promethues-arms-aliyun-go-demo
    spec:
      ports:
      - name: arms-go-demo
        port: 8077
        protocol: TCP
        targetPort: 8077
      type: NodePort
      selector:
        app: promethues-arms-aliyun-go-demo

Step 3: Configure ARMS Prometheus Monitoring to capture the data of Go applications

Configure ARMS Prometheus Monitoring in the ARMS console to capture the data of Go applications.

  1. In the left-side navigation pane, click Prometheus Monitoring.
  2. On the top of the Prometheus monitoring page, select the region where the Container Service Kubernetes cluster is located. Find the target cluster, and click Installation in the Actions column.
  3. After the ARMS Prometheus agent is installed, find the target cluster, and click Settings in the Actions column.
  4. On the Details tab, click Add ServiceMonitor. In the Add ServiceMonitor dialog box, enter the following information:
    apiVersion: monitoring.coreos.com/v1
    kind: ServiceMonitor
    metadata:
      # Enter a unique name.
      name: promethues-arms-aliyun-go-demo
      # Enter the target namespace.
      namespace: default
    spec:
      endpoints:
      - interval: 30s
        # Enter the value of the Name field for Port of Prometheus Exporter.
        port: arms-go-demo
        # Enter the value of the Path field for Prometheus Exporter.
        path: /metrics
      namespaceSelector:
        any: true
        # The namespace of the NGINX Demo.
      selector:
        matchLabels:
          app: promethues-arms-aliyun-go-demo

Step 4: Display the data of Go applications on the Grafana dashboard

Import the Grafana dashboard template in the ARMS console and specify the Container Service Kubernetes cluster where the Prometheus data source is located.

  1. Go to Host Dashboard.
  2. In the left-side navigation pane, choose + > Import, enter 6671 in the Grafana.com Dashboard field, and click Load.
    Import Grafana dashboard
  3. On the Import page, set the following information and click Import.
    Import Grafana dashboard with options
    1. Enter a custom dashboard name in the Name field.
    2. Select your Container Service Kubernetes cluster from the Folder drop-down list.
    3. Select your Container Service Kubernetes cluster from the prometheus-apl drop-down list.
    After the configuration is complete, the ARMS Prometheus Grafana Go dashboard appears, as shown in the following figure.ARMS Prometheus Grafana Go

Step 5: Create an alert

What to do next

After the ARMS Prometheus Grafana Go dashboard is configured, you can view Prometheus Monitoring metrics and customize the dashboard. For more information, see the following documents.

View Prometheus Monitoring metrics

Use ARMS Prometheus Monitoring to customize the Grafana dashboard