指标(Metric)是用来衡量系统和应用程序性能及运行情况的度量值,例如 CPU 利用率、内存使用率、访问吞吐量、响应耗时和响应成功率等。指标一般会定时产生,每一个时刻都会有一个值,随着时间变化形成一个序列,这个序列一般被称为时间序列(time series),简称时序。
日志服务(Cloud Log Service,CLS)兼容 Prometheus 指标数据模型,将相同指标名称(metric name)、相同维度(labels)的包含时间戳的指标数据保存为时间序列(time series)。在时间序列中每个数据点称为样本(sample),样本则由时间戳及样本值构成。
示例
例如系统在2020/12/30 15:35:23.123时某一接口的请求总量就是一个样本,其数据如下:
requests_total{method="POST", handler="/messages"} 217
其由如下几部分构成:
指标名称:requests_total
维度:{method="POST", handler="/messages"} ,即接口名称为 messages,请求方式为 POST
时间戳:2020/12/30 15:35.123
样本值:217
被监控系统实际上往往同时有多个指标,其在某一时刻具备大量不同的指标名称和维度,例如 Nginx 监控指标如下:
# HELP nginx_http_requests_total The total number of HTTP requests# TYPE nginx_http_requests_total counternginx_http_requests_total 10234# HELP nginx_http_requests_duration_seconds The HTTP request duration in seconds# TYPE nginx_http_requests_duration_seconds histogramnginx_http_requests_duration_seconds_bucket{le="0.005"} 2405nginx_http_requests_duration_seconds_bucket{le="0.01"} 5643nginx_http_requests_duration_seconds_bucket{le="0.025"} 7890nginx_http_requests_duration_seconds_bucket{le="0.05"} 9234nginx_http_requests_duration_seconds_bucket{le="0.1"} 10021nginx_http_requests_duration_seconds_bucket{le="0.25"} 10234nginx_http_requests_duration_seconds_bucket{le="0.5"} 10234nginx_http_requests_duration_seconds_bucket{le="1"} 10234nginx_http_requests_duration_seconds_bucket{le="2.5"} 10234nginx_http_requests_duration_seconds_bucket{le="5"} 10234nginx_http_requests_duration_seconds_bucket{le="10"} 10234nginx_http_requests_duration_seconds_bucket{le="+Inf"} 10234nginx_http_requests_duration_seconds_sum 243.56nginx_http_requests_duration_seconds_count 10234# HELP nginx_http_connections Number of HTTP connections# TYPE nginx_http_connections gaugenginx_http_connections{state="active"} 23nginx_http_connections{state="reading"} 5nginx_http_connections{state="writing"} 7nginx_http_connections{state="waiting"} 11# HELP nginx_http_response_count_total The total number of HTTP responses sent# TYPE nginx_http_response_count_total counternginx_http_response_count_total{status="1xx"} 123nginx_http_response_count_total{status="2xx"} 9123nginx_http_response_count_total{status="3xx"} 456nginx_http_response_count_total{status="4xx"} 567nginx_http_response_count_total{status="5xx"} 65# HELP nginx_up Is the Nginx server up# TYPE nginx_up gaugenginx_up 1
其中指标含义如下:
nginx_http_requests_total:Nginx 处理的 HTTP 请求总数。
nginx_http_requests_duration_seconds:HTTP 请求的持续时间,使用 Histogram 类型提供不同区间的请求数量。
nginx_http_connections:当前 Nginx 的 HTTP 连接数,分为 active、reading、writing 和 waiting 状态。
nginx_http_response_count_total:Nginx 返回的 HTTP 响应总数,按状态码分类。
nginx_up:Nginx 服务器的运行状态,1表示运行中,0表示未运行。