This topic takes the Go language as an example to introduce how to configure custom metric tracking for your business, and report, visualize, and alert custom metrics by using Volcengine Managed Service for Prometheus (VMP).
Business metric tracking
Counter
A metric in the counter type increases monotonically and will be reset after service restart. You can use a counter to monitor the numbers of requests, exceptions, user logins, and orders.
The following example shows how to monitor tickets by using the counter type.
In this case, the creation rate of tickets can be obtained through the rate() function.
Gauge type
A gauge is a current value, which can be increased or decreased at the metric scrape time. You can use a gauge to monitor the current memory usage, CPU usage, current number of threads, and queue size.
The following example shows how to monitor tickets by using a gauge.
In this case, you can view the concurrency saturation of tickets.
Histogram type
Prometheus calculates sample distribution based on the configured Bucket to generate a histogram, which can be processed subsequently and is generally used for duration monitoring. For example, you can use a histogram to calculate the latencies of P99, P95, and P50 and monitor the numbers of processed items. With histograms, you do not need to use counters to count items. In addition, you can use histograms to monitor metrics such as API response time and database access time.
The following example shows how to monitor the duration of a ticket by using a histogram.
In this case, you can view the latencies of P95 for the ticket by using a histogram.
Summary type
A summary is similar to a histogram because it also calculates sample distribution. However, a summary uses more client resources and the data cannot be calculated and processed in an aggregated manner subsequently because the summary calculates the distribution (P99/P95/Sum/Count) on the client. You can also use summaries to monitor metrics such as API response time and database access time.
A summary can be used in a similar way to a histogram, so you can directly refer to the histogram usage.
Expose Prometheus metrics
Use promhttp.Handler() to expose the metric tracking data to the HTTP service.
Deploy business
After you configure custom metric tracking for your business, you can deploy an application in a VKE cluster or an ECS instance to release the application. After the application is released, you can access VMP to obtain metric data.
service discovery
When your business is deployed in different environments, different service discovery types are supported.
- When your business is deployed in a VKE cluster, you can use PodMonitor or ServiceMonitor for service discovery. For more details, refer to Service discovery.
- When your business is deployed in an ECS instance, you can use the integration center for service discovery. For more details, refer to ECS integration.
View monitoring data
You can view metric data by using the Explore feature of VMP. For more details, refer to Querying metrics. You can also use self-built Grafana to read data stored in VMP and create metric dashboards. For more details, refer to the following topics: