日志服务 指标

指标(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表示未运行。

日志(Log)和指标(Metric)都是系统和应用程序中收集和记录数据的方法,但它们在数据的类型和用途上有所不同,在 CLS 中区别主要如下:

数据类型 日志(Log) 指标(Metric)
数据格式 无严格限制,普通文本及采用 json 格式记录的结构化数据均可作为日志上报 需符合 Prometheus 指标数据模型
数据采集 支持使用 LogListener, API 和 SDK 采集日志 需通过定时 SQL 分析将原始日志转换为指标,详见 日志转指标
数据存储 支持 标准存储、低频存储 及 日志沉降,不同存储类型功能、性能及价格不同 不区分存储类型
索引配置 需 配置索引,包括字段名称、类型、分词符等 不需要配置索引
数据查询 使用 检索条件 过滤原始日志,使用 SQL 对原始日志进行统计分析 使用 PromQL 查询指标
赞 (0)
上一篇 4天前
下一篇 4天前