
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),僅供參考