Monitor Sample Web

This section walks you through monitoring a sample web application. The application is instrumented with Prometheus Golang client in its code. Therefore, it can expose metrics directly without the help of exporters.

Prerequisites

  • Please make sure you enable the OpenPitrix system.

  • You need to create a workspace, a project, and a user account for this tutorial. For more information, see Create Workspace, Project, Account and Role. The account needs to be a platform regular user and to be invited as the workspace self provisioner with the self-provisioner role. Namely, create an account workspace-self-provisioner of the self-provisioner role, and use this account to create a project (e.g. test). In this tutorial, you log in as workspace-self-provisioner and work in the project test in the workspace demo-workspace.

  • Knowledge of Helm Chart and PromQL.

Hands-on Lab

Step 1: Prepare Sample Web Application Image

First, prepare the sample web application image. The sample web application exposes a user-defined metric called myapp_processed_ops_total. It is a counter type metric that counts the number of operations that have been processed by far. The counter increases automatically by one every 2 seconds.

This sample application exposes application-specific metrics via the endpoint http://localhost:2112/metrics.

In this tutorial, you use the made-ready image kubespheredev/promethues-example-app. The source code can be found in kubesphere/prometheus-example-app. You can also follow Instrument A Go Application For Prometheus in the official documentation of Prometheus.

Step 2: Pack the Application into a Helm Chart

Pack the Deployment, Service, and ServiceMonitor YAML template into a helm chat for reuse. In the Deployment and Service template, you define sample web container and the port for the metrics endpoint. ServiceMonitor is a custom resource defined and used by Prometheus Operator. It connects your application and KubeSphere monitoring engine (Prometheus) so that the engine knows where and how to scrape metrics. In future releases, KubeSphere will provide a graphical user interface for easy operation.

Find the source code in the folder helm in kubesphere/prometheus-example-app. The helm chart package is made ready and is named as prometheus-example-app-0.1.0.tgz. Please download the .tgz file and you will use it in the next step.

Step 3: Upload the Helm Chart

  1. Go to the workspace Overview page of demo-workspace and navigate to App Templates.

app-template-create

  1. Click Create and upload prometheus-example-app-0.1.0.tgz as images below.

click-create-app-template

click-upload-app-template

click-upload-app-template-2

click-upload-app-template-4

click-upload-app-template-5

click-upload-app-template-6

Step 4: Deploy Sample Web Application

You need to deploy the sample web application into demo. For demonstration purposes, you can simply run a test deployment.

  1. Click prometheus-example-app.

deploy-sample-web-1

  1. Expand the menu and click Test Deploy.

deploy-sample-web-2

deploy-sample-web-3

  1. Make sure you deploy the sample web application in test and click Next.

deploy-sample-web-4

  1. Make sure serviceMonitor.enabled is set to true and click Deploy.

deploy-sample-web-5

deploy-sample-web-6

  1. In Workloads of the project test, wait until the sample web application is up and running.

create-dashboard-1

Step 5: Create Dashboard

This section guides you on how to create a dashboard from scratch. You will create a text chart showing the total number of processed operations and a line chart for displaying the operation rate.

  1. Navigate to Custom Monitoring and click Create.

create-dashboard-2

  1. Set a name (e.g. sample-web) and click Create.

create-dashboard-3

  1. Enter a title in the top left corner (e.g. Sample Web Overview).

create-dashboard-4

  1. Click the plus icon on the left column to create a text chart.

create-dashboard-5

  1. Type the PromQL expression myapp_processed_ops_total in the field Monitoring Metrics and give a chart name (e.g. Operation Count). Click in the bottom right corner to continue.

create-dashboard-6

  1. Click Add Monitoring Item to create a line chart.

create-dashboard-7

create-dashboard-8

  1. Type the PromQL expression irate(myapp_processed_ops_total[3m]) for Monitoring Metrics and name the chart Operation Rate. To improve the appearance, you can set Metric Name to {{service}}. It will name each line with the value of the metric label service. Next, set Decimal Places to 2 so that the result will be truncated to two decimal places.

create-dashboard-9

  1. Click Save Template to save it.

create-dashboard-10