Application Real-Time Monitoring Service (ARMS) Managed Service for Prometheus allows you to use a Grafana dashboard to display monitoring data. You can create a custom Grafana dashboard or import a Grafana dashboard from the official website of Grafana. This topic describes how to create a custom Grafana dashboard to display monitoring data. In this example, Container Service for Kubernetes (ACK) and Container Registry are used.
Prerequisites
- An ACK cluster is monitored by Managed Service for Prometheus. For more information, see Create a Prometheus instance to monitor an ACK cluster.
- An image repository is created in Container Registry. For more information, see Step 2: Create an image repository.
Procedure
The following figure shows how to create a Grafana dashboard by using Managed Service for Prometheus.
Step 1: Upload an application
To build an image for an application and upload the image to an image repository of Container Registry, perform the following steps:
- Run the following command to recompile a module:
mvn clean install -DskipTests
- Run the following command to build an image:
docker build -t <Name of the local temporary Docker image>:<Version number of the local temporary Docker image> . --no-cache
Example:docker build -t promethues-demo:v0 . --no-cache
- Run the following command to tag the image:
sudo docker tag <Name of the local temporary Docker image>:<Version number of the local temporary Docker image> <Domain name of the image repository>/<Namespace>/<Image name>:<Image version number>
Example:sudo docker tag promethues-demo:v0 registry.cn-hangzhou.aliyuncs.com/testnamespace/promethues-demo:v0
- Run the following command to upload the image to the image repository:
sudo docker push <Domain name of the image repository>/<Namespace>/<Image name>:<Image version number>
Example:sudo docker push registry.cn-hangzhou.aliyuncs.com/testnamespace/promethues-demo:v0
You can view the information about the uploaded application image on the Tags page of the Container Registry console.
Step 2: Deploy the application
To deploy the application to an ACK cluster, perform the following steps:
- Log on to the ACK console.
- In the left-side navigation pane, click Clusters.
- On the Clusters page, find the cluster to which you want to deploy the application and click Applications in the Actions column.
- Create a container group. The newly created container group is displayed on the Deployments page.
- Create a Service. The newly created Service is displayed on the Services page.
Step 3: Configure data collection rules
By default, Managed Service for Prometheus monitors the data about the CPU, memory, and network. If you want Managed Service for Prometheus to monitor other data such as order information, you must configure data collection rules for Managed Service for Prometheus to monitor the application.
- Log on to the ARMS console.
- In the left-side navigation pane, choose .
- Click the name of the Prometheus instance that you want to manage.
- 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:
- In the left-side navigation pane, click Service Discovery. Then, click the Configure tab.
- On the Configure tab, click the ServiceMonitor tab. Then, click Add ServiceMonitor.
- 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.
- To monitor business data outside the ACK cluster, such as the number of Redis connections, perform the following steps:
- In the left-side navigation pane, click Settings. On the Settings page, click Edit Prometheus.yaml.
- 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']
- To monitor the business data of the application that is deployed to the ACK cluster, such as order information, perform the following steps:
Step 4: Configure a Grafana dashboard
To configure a Grafana dashboard to display data, perform the following steps:
- Go to the Grafana dashboard homepage.
- In the left-side navigation pane, choose .
- On the New dashboard page, click Add new panel.
- On the New dashboard / Edit Panel page, select your ACK cluster from the drop-down list on the Query tab. In the A collapsible section, select a metric from the Metrics drop-down list. Example: go_gc_duration_seconds.
- On the right-side Panel tab, enter a panel name, select the visualization type of the dashboard, such as a chart, table, or heatmap, and then set other parameters as required.
- Click Save in the upper-right corner. In the Save dashboard as... dialog box, enter a dashboard name, select your ACK cluster, and then click Save.
You can create multiple dashboards and charts as required.
The following figure shows the configured Grafana dashboard.
Step 5: Monitor complex metrics
To monitor metrics that involve complex operations, you must debug the corresponding PromQL statement in Managed Service for Prometheus.
- Go to the homepage of Grafana dashboards.
- In the left-side navigation pane, click Explore.
- In the upper part of the Explore page, select your ACK cluster from the drop-down list. Enter a PromQL statement in the Metrics field and click Run Query in the upper-right corner for debugging.
- After the debugging is successful, you can repeat the preceding steps to create more dashboards or charts. For more information, see Step 4: Configure a Grafana dashboard.
Step 6: Create an alert rule
To create an alert rule to monitor a metric, perform the following steps:
- Log on to the ARMS console.
- In the left-side navigation pane, click Prometheus Monitoring.
- In the top navigation bar of the Prometheus Monitoring page, select the region where the monitored Kubernetes cluster resides. Then, click the name of the Kubernetes cluster.
- In the left-side navigation pane, click Alarm configuration.
- On the Alarm configuration page, click Create Alert in the upper-right corner.
- In the Create Alert panel, set the parameters.After you create the alert rule, the Alarm configuration page displays the rule, as shown in the following figure.