ARTICLE DETAIL

资讯详情

深耕编程入门与网站建设的一线实战洞察。

Metabase 如何接入 Prometheus 导出系统指标?

Metabase 如何接入 Prometheus 导出系统指标? Metabase 如何接入 Prometheus 导出系统指标【免费下载链接】metabaseThe easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:项目地址: https://gitcode.com/GitHub_Trending/me/metabaseMetabase 可以把自身的运行指标以 Prometheus 格式导出启动时通过MB_PROMETHEUS_SERVER_PORT环境变量指定一个端口Metabase 就会在该端口上提供指标端点再把这个端点加入 Prometheus 的抓取配置就能在 Prometheus 中查询和绘制 JVM 线程、内存、Jetty 请求、数据库连接池等指标。本文按官方文档 Observability with Prometheus 走一遍完整接入流程覆盖「以 JAR 方式运行 Metabase 本机部署 Prometheus」这一场景。准备工作接入前需要准备可运行的 Metabase JAR 文件下载入口见官方文档开头部分Prometheus 安装包解压后得到./prometheus可执行文件后续会把配置文件放在这个目录Java 运行环境Metabase 通过java -jar启动一个空闲端口用于导出指标本文沿用文档示例的9191。第一步用 MB_PROMETHEUS_SERVER_PORT 启动 Metabase在 Metabase JAR 所在目录带环境变量启动MB_PROMETHEUS_SERVER_PORT9191 java --add-opens java.base/java.nioALL-UNNAMED -jar metabase.jarMB_PROMETHEUS_SERVER_PORT在环境变量文档中的定义为 integer 类型默认值为null只有设置它之后Prometheus collectors 才会注册并从localhost:port/metrics提供指标。这次接入涉及三个端口注意区分端口用途3000Metabase 应用自身的 Web 端口可用MB_JETTY_PORT改为其他值例如MB_JETTY_PORT30019191MB_PROMETHEUS_SERVER_PORT指定的端口Prometheus 从这里抓取 Metabase 指标9090Prometheus 应用自身的 Web 端口启动后可以确认两件事Metabase 日志中出现指标收集器和指标 Web 服务的启动记录以下为文档给出的日志示例(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)http://localhost:3000可以打开本地运行的 Metabase。第二步配置 Prometheus 抓取 Metabase在 Prometheus 目录中放入配置文件prometheus.yml内容为官方文档给出的示例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 its Prometheus itself. scrape_configs: # The job name is added as a label jobjob_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]其中targets里的9191必须与MB_PROMETHEUS_SERVER_PORT一致target需要指向 Metabase 所在的位置。文档示例中 Metabase 与 Prometheus 在同一台主机上因此写localhost如果你的 Metabase 运行在别处需要把它改为 Metabase 实际所在的地址。第三步启动 Prometheus 并验证指标在 Prometheus 目录另开一个终端运行./prometheus --config.fileprometheus.yml然后打开http://localhost:9090应能看到 Prometheus 界面并可以搜索到 Metabase 导出的各项指标。如果想绕过 Prometheus 直接核对指标内容可以访问指标端点http://localhost:9191/metrics端口换成你实际设置的值返回内容为 Prometheus 文本格式。文档给出的一段示例输出如下其中的数值仅为示例不代表固定预期# 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.0Metabase 导出的指标范围官方文档列出的导出指标包括以下几类c3p0_*数据库连接池状态如c3p0_num_busy_connections、c3p0_num_idle_connections、c3p0_max_pool_sizejetty_*Jetty 请求处理统计如jetty_requests_total、jetty_request_time_seconds_total、jetty_responses_totaljvm_*JVM 垃圾回收、内存、内存池与线程指标如jvm_gc_collection_seconds_count、jvm_memory_bytes_used、jvm_threads_stateprocess_*进程级指标如process_cpu_seconds_total、process_open_fds、process_start_time_secondsmetabase_email_messages_total、metabase_email_message_errors_total等邮件发送指标metabase_security_center_last_sync_timestamp_seconds、metabase_security_center_vulnerable_advisories等 Security Center 指标。完整清单见 observability-with-prometheus.md 的 “Exported metrics” 一节。接入时的限制指标服务只有在设置了MB_PROMETHEUS_SERVER_PORT后才存在未设置时默认null不会注册和提供 Prometheus 指标文档给出的抓取示例基于 Prometheus 与 Metabase 同机部署target写localhost。跨机抓取时按文档说明把target改为 Metabase 所在位置即可文档中的日志和指标输出均为示例实际数值随运行状态变化不要按示例值做固定判断。下一步官方文档在 “Further reading” 中指向了 Running Metabase 与 Profiling your Metabase在接入指标后遇到启动或性能问题时可以参考MB_PROMETHEUS_SERVER_PORT的完整定义见 环境变量文档。【免费下载链接】metabaseThe easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:项目地址: https://gitcode.com/GitHub_Trending/me/metabase创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考
返回列表