This document describes how to integrate CVM with TMP.
Note:The purchased TMP instance must be in the same VPC as the monitored CVM instance for network connectivity.
wget https://github.com/prometheus/node_exporter/releases/download/v1.3.1/node_exporter-1.3.1.linux-amd64.tar.gz && tar -xvf node_exporter-1.3.1.linux-amd64.tar.gz
The file directory is as follows:
2. Run Node Exporter to collect basic monitoring data.
cd node_exporter-1.3.1.linux-amd64
./node_exporter
If the following result is displayed, basic monitoring data has been collected successfully.
2. Run the following command to expose the basic monitoring data to port 9100:
curl 127.0.0.1:9100/metrics
You can see the following metric monitoring data that is exposed after the command is executed.
3. Add a scrape task.
Log in to the TMP console, select Integration Center > CVM, and configure the information in Task Configuration as prompted.
Below is a sample configuration of a scrape task:
job_name: example-job-name
metrics_path: /metrics
cvm_sd_configs:
- region: ap-guangzhou
ports:
- 9100
filters:
- name: tag: Sample tag key
values:
- Sample tag value
relabel_configs:
- source_labels: [__meta_cvm_instance_state]
regex: RUNNING
action: keep
- regex: __meta_cvm_tag_(.*)
replacement: $1
action: labelmap
- source_labels: [__meta_cvm_region]
target_label: region
action: replace
{job="cvm_node_exporter"}
in Explore to see whether there is data, and if so, data is reported successfully.node_exporter
, and select the latest dashboard for download.Prometheus provides four metric types for different monitoring scenarios: Counter, Gauge, Histogram, and Summary. The Prometheus community provides SDKs for multiple programing languages, which are basically similar in usage and mainly differ in the syntax. The following uses Go as an example to describe how to report custom monitoring metrics. For detailed directions of other metric types, see Custom Monitoring.
A metric in Counter type increases monotonically and will be reset after service restart. You can use counters to monitor the numbers of requests, exceptions, user logins, orders, etc.
package order
import (
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
)
// Define the counter object to be monitored
var (
opsProcessed = promauto.NewCounterVec(prometheus.CounterOpts{
Name: "order_service_processed_orders_total",
Help: "The total number of processed orders",
}, []string{"status"}) // Processing status
)
// Process the order
func makeOrder() {
opsProcessed.WithLabelValues("success").Inc() // Success
// opsProcessed.WithLabelValues("fail").Inc() // Failure
// Order placement business logic
}
For example, you can use the rate()
function to get the order increase rate:
rate(order_service_processed_orders_total[5m])
promhttp.Handler()
to expose the metric tracking data to the HTTP service.package main
import (
"net/http"
"github.com/prometheus/client_golang/prometheus/promhttp"
)
func main() {
// Business code
// Expose Prometheus metrics in the HTTP service
http.Handle("/metrics", promhttp.Handler())
// Business code
}
Was this page helpful?