使用插件指标 - reporter-prometheus来监控Gerrit内部与Prometheus

时间:2018-05-06 14:02:43

标签: gerrit monitor prometheus

我想用Gerrit监视Prometheus守护程序。

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

免责声明:此导出程序主要公开从Dropwizard metric生成的Gerrit守护程序内部指标。 未报告项目计数,待审核

注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

1 个答案:

答案 0 :(得分:0)

回答自己...

它是如何工作的:普罗米修斯会刮掉

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网络界面中以管理员身份进行连接,获取插件>已安装以验证是否列出并启用了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网络界面,转到项目>列表>所有项目
  • 点击“访问”标签
  • 点击按钮[编辑]
  • 在区块Global Capabilities中,点击Add Permission(通常是第4个下拉菜单)
    • 在下拉列表中选择权限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

重要您可能必须使用/a/ 为Gerrit URL加前缀以强制进行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享受: - )