【问题标题】:using plugin metrics-reporter-prometheus to monitor Gerrit internals with Prometheus使用插件 metrics-reporter-prometheus 通过 Prometheus 监控 Gerrit 内部
【发布时间】:2023-04-03 13:15:01
【问题描述】:

我想用Prometheus 监控Gerrit 守护进程。

如何配置Gerrit的插件metrics-reporter-prometheus和Prometheus进行白盒监控?

免责声明:此导出器主要公开 Gerrit 守护进程内部指标,由 Dropwizard metric 生成。 项目数量、待审核...未报告

注意 2:我对使用通用导出器(JMX 导出器、Javamelody...)不感兴趣

此出口商的典型指标如下所示:

# HELP caches_disk_cached_git_tags Generated from Dropwizard metric import (metric=caches/disk_cached/git_tags, type=com.google.gerrit.metrics.dropwizard.BucketedCallback$ValueGauge)
# TYPE caches_disk_cached_git_tags gauge
caches_disk_cached_git_tags 0.0
# HELP http_server_rest_api_response_bytes_project_ListProjects Generated from Dropwizard metric import (metric=http/server/rest_api/response_bytes/project.ListProjects, type=com.codahale.metrics.Histogram)
# TYPE http_server_rest_api_response_bytes_project_ListProjects summary
http_server_rest_api_response_bytes_project_ListProjects{quantile="0.5",} 216.0
http_server_rest_api_response_bytes_project_ListProjects{quantile="0.75",} 216.0
http_server_rest_api_response_bytes_project_ListProjects{quantile="0.95",} 216.0
http_server_rest_api_response_bytes_project_ListProjects{quantile="0.98",} 216.0
http_server_rest_api_response_bytes_project_ListProjects{quantile="0.99",} 216.0
http_server_rest_api_response_bytes_project_ListProjects{quantile="0.999",} 216.0
http_server_rest_api_response_bytes_project_ListProjects_count 3.0
# HELP http_server_rest_api_response_bytes_query_change_QueryChanges Generated from Dropwizard metric import (metric=http/server/rest_api/response_bytes/query.change.QueryChanges, type=com.codahale.metrics.Histogram)
# TYPE http_server_rest_api_response_bytes_query_change_QueryChanges summary
http_server_rest_api_response_bytes_query_change_QueryChanges{quantile="0.5",} 16.0
http_server_rest_api_response_bytes_query_change_QueryChanges{quantile="0.75",} 16.0
http_server_rest_api_response_bytes_query_change_QueryChanges{quantile="0.95",} 16.0
http_server_rest_api_response_bytes_query_change_QueryChanges{quantile="0.98",} 16.0
http_server_rest_api_response_bytes_query_change_QueryChanges{quantile="0.99",} 16.0
http_server_rest_api_response_bytes_query_change_QueryChanges{quantile="0.999",} 16.0
http_server_rest_api_response_bytes_query_change_QueryChanges_count 17.0
[..]
[..]

还有一些常见的

# HELP proc_jvm_memory_heap_committed Generated from Dropwizard metric import (metric=proc/jvm/memory/heap_committed, type=com.google.gerrit.metrics.dropwizard.CallbackMetricImpl0$1)
# TYPE proc_jvm_memory_heap_committed gauge
proc_jvm_memory_heap_committed 5.77241088E8
# HELP proc_birth_timestamp Generated from Dropwizard metric import (metric=proc/birth_timestamp, type=com.google.gerrit.metrics.dropwizard.CallbackMetricImpl0$1)
# TYPE proc_birth_timestamp gauge
proc_birth_timestamp 1.525600508281E15
# HELP proc_cpu_usage Generated from Dropwizard metric import (metric=proc/cpu/usage, type=com.google.gerrit.metrics.dropwizard.CallbackMetricImpl0$1)
# TYPE proc_cpu_usage gauge
proc_cpu_usage 93.24
# HELP proc_num_open_fds Generated from Dropwizard metric import (metric=proc/num_open_fds, type=com.google.gerrit.metrics.dropwizard.CallbackMetricImpl0$1)
# TYPE proc_num_open_fds gauge

【问题讨论】:

    标签: gerrit monitor prometheus


    【解决方案1】:

    回答自己...

    工作原理:普罗米修斯会刮

    Gerrit 配置

    假设:

    • Gerrit 安装在目录~/gerrit
    • Gerrit 版本 >= 2.14(示例基于 2.14)
    • Gerrit SSH 配置了 SSH 密钥 (doc),此命令有效 ssh -p 29418 admin@gerrit.example.com gerrit version

    安装插件

    安装 Gerrit 导出器插件。更容易的是从 gerritforge 下载 JAR。浏览https://gerrit-ci.gerritforge.com/view/Plugins-stable-2.14/job/pluin-metrics-reporter-prometheus-bazel-stable-2.14/并下载metrics-reporter-prometheus.jar,或执行Unix命令:

    cd ~/gerrit/plugins/
    wget -O metrics-reporter-prometheus.jar 'https://gerrit-ci.gerritforge.com/view/Plugins-stable-2.14/job/plugin-metrics-reporter-prometheus-bazel-stable-2.14/lastSuccessfulBuild/artifact/bazel-genfiles/plugins/metrics-reporter-prometheus/metrics-reporter-prometheus.jar'
    

    然后重启 Gerrit

    在 Gerrit Web 界面中以管理员身份连接,进入 Plugins>Installed 以验证 metrics-reporter-prometheus 是否已列出并启用,或者运行:

    ssh -p 29418 admin@gerrit.example.com gerrit plugin ls
    

    授权帐户和组

    接下来您需要在 Gerrit 中创建一个组和一个帐户,然后授予权限View Metrics

    此过程应适应您在 Gerrit (LDAP...) 中管理用户帐户的方式。对于本地帐户(由 SSH 管理):

    ssh -p 29418 admin@gerrit.example.com 'gerrit create-group "Prometheus Metrics" '
    
    ssh -p 29418 admin@gerrit.example.com 'gerrit create-account prometheus  --full-name "Prometheus Monitoring" --email prometheus@gerrit.example.com '
    
    ssh -p 29418 admin@gerrit.example.com 'gerrit set-members "Prometheus Metrics" --add "prometheus" '
    
    ssh -p 29418 admin@gerrit.example.com 'gerrit set-account prometheus --http-password ChangeThisInsecurePassword '
    

    在 Gerrit 中授予“Prometheus Metrics”权限

    • 使用具有管理员权限的帐户登录 Gerrit Web 界面,转到 Projects>List>All-Projects
    • 点击“访问”标签
    • 点击按钮[编辑]
    • Global Capabilities 块中,单击Add Permission(通常是第四个下拉菜单)
      • 在下拉列表中选择权限View Metrics
      • 选择我们在上面创建的组“Prometheus Metrics”。
      • 点击按钮[添加]
      • 转到页面底部并单击[保存更改]按钮

    测试!

    测试认证和授权,有两种选择: * 使用创建帐户登录 Web 界面(应该会成功!),然后更改 URL 路径(http://gerrit.example.com:8080/a/plugins/metrics-reporter-prometheus/metrics),您应该会获得 Prometheus 指标! * 或使用wget(或curl 或其他):

    wget -O - --user prometheus --password ChangeThisInsecurePassword  http://gerrit.example.com:8080/a/plugins/metrics-reporter-prometheus/metrics
    

    重要您可能需要在 Gerrit URL 前加上 /a/ 以强制 HTTP 身份验证 (read the doc)

    如果您收到错误ERROR 403: Forbidden access.,请仔细检查上述过程(用户存在?组存在?授予权限?)!

    普罗米修斯配置

    编辑文件/etc/prometheus/prometheus.yml,添加作业:

      - job_name: gerrit
        metrics_path: '/a/plugins/metrics-reporter-prometheus/metrics'
        static_configs:
          - targets: ['slxhmhs1:8080']
        basic_auth:
          username: prometheus
          password: ChangeThisInsecurePassword
    

    检查promethsu配置文件:

    promtool  check-config /etc/prometheus/prometheus.yml
    

    让 prometheus 重新加载它的配置,使用以下之一:

    systemctl reload prometheus
    killall -HUP prometheus
    docker exec -ti graphite-exporter killall -HUP prometheus
    

    测试:

    访问 Prometheus 的状态页面 (http://prom.example.com:9090/targets#job-gerrit ),然后检查作业/目标状态。

    使用

    进入 prometheus Expression 浏览器 (http://prom.example.com:9090),然后输入:

    {job="gerrit"}
    

    并在 Grafana 中享受 :-)

    【讨论】: