使用 Prometheus 的可观察性
您可以从Metabase以Prometheus格式导出指标。
在本地运行Metabase和Prometheus
为了给您一个关于Metabase和Prometheus如何在您的生产环境中工作的概念,我们将通过如何设置本地Metabase和Prometheus进行说明。
使用MB_PROMETHEUS_SERVER_PORT
启动Metabase
下载最新的Metabase JAR,并使用环境变量运行Metabase以指定Prometheus服务器端口
MB_PROMETHEUS_SERVER_PORT=9191 java -jar metabase.jar
MB_PROMETHEUS_SERVER_PORT=9191
指定Metabase将用于向Prometheus发送数据的端口号(9191
)。为了澄清将涉及到的端口
- 端口
3000
是Metabase用于提供Metabase应用程序的端口号。您可以使用MB_JETTY_PORT
设置另一个端口号(例如,MB_JETTY_PORT=3001
)。 - 端口号
9191
(或您使用环境变量MB_PROMETHEUS_SERVER_PORT
指定的任何端口)是 Prometheus 从 Metabase 抓取指标所使用的端口。 - 端口号
9090
是 Prometheus 用来服务 Prometheus 应用程序的端口。
当您启动 Metabase 时,Metabase 的日志会显示 Metabase 正在启动 prometheus metrics collector
和 prometheus metrics web-server
。
(truncated logs)
2022-09-01 17:47:38,808 INFO metabase.util :: Database setup took 3.4 s
2022-09-01 17:47:38,826 INFO metabase.core :: Setting up prometheus metrics
2022-09-01 17:47:38,827 INFO metabase.prometheus :: Starting prometheus metrics collector
2022-09-01 17:47:38,839 INFO metabase.prometheus :: Starting prometheus metrics web-server on port 9,191
(truncated logs)
您可以在 https://127.0.0.1:3000
查看您本地上运行的 Metabase。
下载并配置 Prometheus
下载 Prometheus,并解压缩文件。
切换到 Prometheus 目录,添加以下 YAML 文件来配置您的 Prometheus
Prometheus 配置文件示例
global:
scrape_interval: 15s # By default, scrape targets every 15 seconds.
# Attach these labels to any time series or alerts when communicating with
# external systems (federation, remote storage, Alertmanager).
external_labels:
monitor: "codelab-monitor"
# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
- job_name: "prometheus"
# Override the global default and scrape targets from this job every 5 seconds.
scrape_interval: 5s
# use whatever port here that you set for MB_PROMETHEUS_SERVER_PORT
static_configs:
- targets: ["localhost:9191"]
您需要将“target”更改为 Metabase 所在的位置,在这个特定的例子中,Metabase 和 Prometheus 在同一台主机上运行(“localhost”)。
本地运行 Prometheus
在 Prometheus 目录的新终端进程中运行
./prometheus --config.file=prometheus.yml
然后检查 https://127.0.0.1:9090
。您应该能看到 Prometheus 应用程序,并能搜索 Metabase 发出的各种指标。
样本指标输出
以下是从 Metabase 得到的样本输出
'# HELP jvm_threads_current Current thread count of a JVM
'# TYPE jvm_threads_current gauge
jvm_threads_current 81.0
'# HELP jvm_threads_daemon Daemon thread count of a JVM
'# TYPE jvm_threads_daemon gauge
jvm_threads_daemon 36.0
'# HELP jvm_threads_peak Peak thread count of a JVM
'# TYPE jvm_threads_peak gauge
jvm_threads_peak 81.0
'# HELP jvm_threads_started_total Started thread count of a JVM
'# TYPE jvm_threads_started_total counter
jvm_threads_started_total 104.0
'# HELP jvm_threads_deadlocked Cycles of JVM-threads that are in deadlock waiting to acquire object monitors or ownable synchronizers
'# TYPE jvm_threads_deadlocked gauge
jvm_threads_deadlocked 0.0
导出指标
Metabase 导出的指标包括
c3p0_max_pool_size
c3p0_min_pool_size
c3p0_num_busy_connections
c3p0_num_connections
c3p0_num_idle_connections
c3p0_num_threads_awaiting_checkout_default_user
jetty_async_dispatches_total
jetty_async_requests_total
jetty_async_requests_waiting
jetty_async_requests_waiting_max
jetty_dispatched_active
jetty_dispatched_active_max
jetty_dispatched_time_max
jetty_dispatched_time_seconds_total
jetty_dispatched_total
jetty_expires_total
jetty_request_time_max_seconds
jetty_request_time_seconds_total
jetty_requests_active
jetty_requests_active_max
jetty_requests_total
jetty_responses_bytes_total
jetty_responses_total
jetty_stats_seconds
jvm_gc_collection_seconds_count
jvm_gc_collection_seconds_sum
jvm_memory_bytes_committed
jvm_memory_bytes_init
jvm_memory_bytes_max
jvm_memory_bytes_used
jvm_memory_objects_pending_finalization
jvm_memory_pool_bytes_committed
jvm_memory_pool_bytes_init
jvm_memory_pool_bytes_max
jvm_memory_pool_bytes_used
jvm_memory_pool_collection_committed_bytes
jvm_memory_pool_collection_init_bytes
jvm_memory_pool_collection_max_bytes
jvm_memory_pool_collection_used_bytes
jvm_threads_current
jvm_threads_daemon
jvm_threads_deadlocked
jvm_threads_deadlocked_monitor
jvm_threads_peak
jvm_threads_started_total
jvm_threads_state
process_cpu_seconds_total
process_max_fds
process_open_fds
process_start_time_seconds
process_virtual_memory_bytes
metabase_email_messages_total
metabase_email_messages_created
metabase_email_message_errors_total
metabase_email_message_errors_created
进一步阅读
阅读有关其他 Metabase 版本的文档。