[17.0.0.3 and later]

MicroProfile 指标 REST API

mpMetrics-1.0mpMetrics-1.1 功能部件提供了一个 REST API,用于显示指标以供管理员访问。

格式

指标端点提供两种输出格式。用于每个响应的格式取决于相应请求的 HTTP 接受头。
Prometheus 文本格式
这是与 Prometheus 监视工具兼容的指标表示。对于具有 text/plain 接受头的请求,将返回此格式。
JSON 格式
这是指标的 JSON 表示。对于具有 application/json 接受头的请求,将返回此格式。

REST 端点

下表说明可供访问以提供指标的不同端点。
端点 请求类型 支持的格式 描述
/metrics GET JSON 和 Prometheus 返回所有已注册的指标。
/metrics/<scope> GET JSON 和 Prometheus 返回已针对各自的作用域注册的指标。
/metrics/<scope>/<metric name> GET JSON 和 Prometheus 返回与各自作用域的指标名称相匹配的指标。
/metrics OPTIONS JSON 返回所有已注册的指标元数据。
/metrics/<scope> OPTIONS JSON 返回已针对各自作用域注册的指标元数据。
/metrics/<scope>/<metric name> OPTIONS JSON 返回与各自作用域的指标名称相匹配的指标元数据。

连接到数据存储器和监视工具

管理员可以将其应用程序指标连接到其他能够分析和监视指标信息的工具及堆栈。

缺省情况下,/metrics 端点返回与 Prometheus 兼容的格式的数据。要将 Liberty 服务器连接到 Prometheus,请配置 Prometheus 以使用 https://host:https_port/metrics 端点。

JSON 格式可由其他理解 JSON 的指标收集工具使用。例如,可以将 collectd curl_json 插件配置为解释 MicroProfile 指标中的 JSON 格式。collectd 随后可将信息转发到各种不同的工具,例如 Graphite。

Prometheus 格式详细信息

Prometheus 文本格式基于 Prometheus 文档中描述的 0.0.4 说明格式。如果可用,将为每个指标提供元数据。# Help 行包含指标的描述。元数据中存在的任何标记都以 Prometheus 标签的形式提供。对于标尺和直方图,指标单位将追加到指标名称末尾。

标尺由单个值表示。以下示例说明如何显示名为 cost 且单位为 dollars 的标尺:
# TYPE application:cost_dollars gauge
# HELP application:cost_dollars The running cost of the server in dollars.
application:cost_dollars 80        
以下示例显示针对计数器生成的文本格式。输出仅包含计数器的一个值。
# TYPE application:visitors counter
# HELP application:visitors The number of unique visitors
application:visitors 80
计量表由多个值组成。以下示例说明如何显示名为 requests 的计量表。
# TYPE application:requests_count counter 
# HELP application:requests_count Tracks the number of requests to the server 
application:requests_count 29382
# TYPE application:requests_rate_per_second gauge 
application:requests_rate_per_second 12.223
# TYPE application:requests_one_min_rate_per_second gauge 
application:requests_one_min_rate_per_second 12.563
# TYPE application:requests_five_min_rate_per_second gauge 
application:requests_five_min_rate_per_second 12.364
# TYPE application:requests_fifteen_min_rate_per_second gauge 
application:requests_fifteen_min_rate_per_second 12.126
直方图由多个值组成。以下示例说明如何显示名为 file_sizes 且单位设置为 bytes 的直方图。
# TYPE application:file_sizes_mean_bytes gauge
application:file_sizes_mean_bytes 4738.231
# TYPE application:file_sizes_max_bytes gauge
application:file_sizes_max_bytes 31716
# TYPE application:file_sizes_min_bytes gauge
application:file_sizes_min_bytes 180
# TYPE application:file_sizes_stddev_bytes gauge
application:file_sizes_stddev_bytes 1054.7343037063602
# TYPE application:file_sizes_bytes summary
# HELP application:file_sizes_bytes Users file size
application:file_sizes_bytes_count 2037
application:file_sizes_bytes{quantile="0.5"} 4201
application:file_sizes_bytes{quantile="0.75"} 6175
application:file_sizes_bytes{quantile="0.95"} 13560
application:file_sizes_bytes{quantile="0.98"} 29643
application:file_sizes_bytes{quantile="0.99"} 31716
application:file_sizes_bytes{quantile="0.999"} 31716
计时器指标由多个值组成。以下示例说明如何显示名为 response_time 的计时器。
# TYPE application:response_time_rate_per_second gauge 
application:response_time_rate_per_second  0.004292520715985437
# TYPE application:response_time_one_min_rate_per_second gauge 
application:response_time_one_min_rate_per_second  2.794076465421066E-14
# TYPE application:response_time_five_min_rate_per_second  gauge 
application:response_time_five_min_rate_per_second  4.800392614619373E-4
# TYPE application:response_time_fifteen_min_rate_per_second  gauge 
application:response_time_fifteen_min_rate_per_second  0.01063191047532505
# TYPE application:response_time_mean_seconds gauge 
application:response_time_mean_seconds 0.000415041
# TYPE application:response_time_max_seconds gauge 
application:response_time_max_seconds 0.0005608694
# TYPE application:response_time_min_seconds gauge 
application:response_time_min_seconds 0.000169916
# TYPE application:response_time_stddev_seconds gauge 
application:response_time_stddev_seconds 0.000652907
# TYPE application:response_time_seconds summary 
# HELP application:response_time_seconds Server response time for /index.html
application:response_time_seconds_count 80
application:response_time_seconds{quantile="0.5"} 0.0002933240
application:response_time_seconds{quantile="0.75"} 0.000344914
application:response_time_seconds{quantile="0.95"} 0.000543647
application:response_time_seconds{quantile="0.98"} 0.002706543
application:response_time_seconds{quantile="0.99"} 0.005608694
application:response_time_seconds{quantile="0.999"} 0.005608694

JSON 格式详细信息 - GET

JSON 格式返回已格式化为树形结构的数据。每个指标都通过名称以及值(对于标尺和计数器)或映射(对于计量表、直方图和计时器)来引用。

如果请求 /metrics,那么作用域数据将包装在作用域名称中:
{
  "application": {
    "hitCount": 45
  },
  "base": {
     "thread.count" : 33,
     "thread.max.count" : 47
  },
  "vendor": {...}
}
对于标尺和计数器,值是指标的值。以下示例显示调用 /metrics/application 所返回的值。
{
  "hitCount": 45
}
以下示例显示计量表的 JSON 对象:
{
  "requests": {
    "count": 29382,
    "meanRate": 12.223,
    "oneMinRate": 12.563,
    "fiveMinRate": 12.364,
    "fifteenMinRate": 12.126,
  }
}
在此示例中,存在以下键:
count 事件数的计数。
meanRate 自注册指标以来的平均速率(事件数/秒)。
oneMinRate 过去 1 分钟的平均速率(事件数/秒)。
fiveMinRate 过去 5 分钟的平均速率(事件数/秒)。
fifteenMinRate 过去 15 分钟的平均速率(事件数/秒)。
以下示例显示直方图的 JSON 对象:
{ 
"file_sizes": {
    "count":2,
    "min":-1624,
    "max":26,
    "mean":-799.0,
    "stddev":825.0,
    "p50":26.0,
    "p75":26.0,
    "p95":26.0,
    "p98":26.0,
    "p99":26.0,
    "p999":26.0
  }
}
在此示例中,存在以下键:
count 事件数的计数。
min 所记录的最小值。
max 所记录的最大值。
mean 平均值。
stddev 标准差。
p50 第 50 百分位数处的值,与中位数相同。
p75 第 75 百分位数处的值。
p95 第 95 百分位数处的值。
p98 第 98 百分位数处的值。
p99 第 99 百分位数处的值。
p999 第 999 百分位数处的值。
以下示例显示计时器的 JSON 对象:
{
  "responseTime": {
    "count": 29382,
    "meanRate":12.185627192860734,
    "oneMinRate": 12.563,
    "fiveMinRate": 12.364,
    "fifteenMinRate": 12.126,
    "min":169916,
    "max":5608694,
    "mean":415041.00024926325,
    "stddev":652907.9633011606,
    "p50":293324.0,
    "p75":344914.0,
    "p95":543647.0,
    "p98":2706543.0,
    "p99":5608694.0,
    "p999":5608694.0
  }
}
count 事件数的计数。
meanRate 自注册指标以来的平均速率(事件数/秒)。
oneMinRate 过去 1 分钟的平均速率(事件数/秒)。
fiveMinRate 过去 5 分钟的平均速率(事件数/秒)。
fifteenMinRate 过去 15 分钟的平均速率(事件数/秒)。
min 所记录的最小值。
max 所记录的最大值。
mean 平均值。
stddev 标准差。
p50 第 50 百分位数处的值,与中位数相同。
p75 第 75 百分位数处的值。
p95 第 95 百分位数处的值。
p98 第 98 百分位数处的值。
p99 第 99 百分位数处的值。
p999 第 999 百分位数处的值。

JSON 格式详细信息 - OPTIONS

元数据是使用相同的树样式显示的,其中子树表示子资源。指标名称映射至其元数据值。例如,如果 GET /metrics/applications 显示以下多个值:
{
  "fooVal": 12345,
  "barVal": 42
}
那么 OPTIONS /metrics/application 将显示:
{
  "fooVal": {
    "unit": "milliseconds",
    "type": "gauge",
    "description": "The average duration of foo requests during last 5 minutes",
    "displayName": "Duration of foo",
    "tags": "app=webshop"
  },
  "barVal": {
    "unit": "megabytes",
    "type": "gauge",
    "tags": "component=backend,app=webshop"
  }
}

用于指示主题类型的图标 参考主题

文件名:rwlp_mp_metrics_rest_api.html