简体   繁体   English

使用 jenkins prometheus 插件

[英]Working with jenkins prometheus plugin

I have Jenkins in https://jenkins.example.com .我在https://jenkins.example.com有詹金斯。 Plugin working witn 2 env.插件与 2 环境一起工作。 variables:变量:

PROMETHEUS_ENDPOINT Configures rest endpoint. Defaults to "prometheus" PROMETHEUS_NAMESPACE Configure prometheus metric namespace. Defaults to "default"

I need the metrics to be sent to https://jenkins.example.com/metrics我需要将指标发送到https://jenkins.example.com/metrics

What PROMETHEUS_ENDPOINT and PROMETHEUS_NAMESPACE values?什么PROMETHEUS_ENDPOINTPROMETHEUS_NAMESPACE值?

Plugin documentation插件文档

Shortly: You actually don't need to edit this values.简而言之:您实际上不需要编辑这些值。 if you wish so you can configure them on:如果您愿意,您可以将它们配置为:

Jenkins -> Manage Jenkins -> Configure System -> Promethues (section) Jenkins -> 管理 Jenkins -> 配置系统 -> Promethues(部分)

In short PROMETHEUS_ENDPOINT using the GET Http request in order to get the index page of the jenkins metrics - https://<your-jenkins-path>/prometheus简而言之, PROMETHEUS_ENDPOINT使用 GET Http 请求来获取 jenkins 指标的索引页面 - https://<your-jenkins-path>/prometheus

Useful / Golden Tips for using jenkins prometheus plugin:使用 jenkins prometheus 插件的有用/黄金提示:

  1. set parameter Enable authentication for prometheus end-point to true and you'll be able to get information about internal processes and jobs running on your jenkins endpoint.将参数Enable authentication for prometheus end-point设置为true ,您将能够获取有关在 jenkins 端点上运行的内部进程和作业的信息

  2. create User account on jenkins dedicated to prometheus monitoring, create a token for authentication.在 jenkins 上创建专门用于 prometheus 监控的用户帐户,创建用于身份验证的令牌。

  3. set screen privileges permissions for viewing jenkins metrics for this user:设置屏幕权限以查看此用户的 jenkins 指标:

For Enabling Metrics permission:对于启用指标权限:

Managing jenkins -> Manage and assign roles -> Manage Roles -> Metrics (set view and health-check to true).管理 jenkins -> 管理和分配角色 -> 管理角色 -> 指标(将视图和健康检查设置为 true)。

For Assign this permission to specific user: (your prometheus user) -将此权限分配给特定用户:(您的普罗米修斯用户)-

Managing jenkins -> Manage and assign roles -> Assign Roles -> find your user and add screen permission.管理 jenkins -> 管理和分配角色 -> 分配角色 -> 找到您的用户并添加屏幕权限。

  1. Configure this credentials on prometheus.yml in your prometheus stack.在 prometheus 堆栈中的 prometheus.yml 上配置此凭据。 I'm attaching example for this, this pattern works for me :我为此附上了示例,这种模式对我有用
 - job_name: 'jenkins' metrics_path: /prometheus scheme: http tls_config: insecure_skip_verify: true static_configs: - targets: ['company.jenkins.com:8080'] basic_auth: username: 'JohnDoe@gmail.com' password: 'abc123'
  1. In order to test this is actual works use curl for perform http request the plugin api and integration for jenkins.为了测试这是实际工作,使用curl来执行 http 请求,插件 api 和 jenkins 的集成。 curl -u user:token jenkinsURL:port/prometheus/

for example:例如:

curl -u JohnDoe@gmail.com:abc123 company.jenkins.com:8080/prometheus/
  1. For testing your integration with prometheus , go to your http://yourPrometheusURL.com:9090/targets and make sure your endpoint is up.测试您与 prometheus 的集成,请访问您的http://yourPrometheusURL.com:9090/targets并确保您的端点已启动。 you should get the metrics and start using it.您应该获取指标并开始使用它。 Good Luck.祝你好运。

PROMETHEUS_ENDPOINT - Configures the path. PROMETHEUS_ENDPOINT - 配置路径。 Defaults to prometheus thus your metrics will be accessible at the URI /prometheus/ .默认为prometheus因此您的指标可以在 URI /prometheus/

What you want is to configure PROMETHEUS_ENDPOINT to metrics .您想要的是将PROMETHEUS_ENDPOINT配置为metrics You will still have to add to prometheux.xml the variable metrics_path and set it to /metrics/您仍然需要向prometheux.xml添加变量metrics_path并将其设置为/metrics/

PROMETHEUS_NAMESPACE - puts a prefix to each metric. PROMETHEUS_NAMESPACE - 为每个指标添加前缀。

http://jenkins.example.com/metrics change it http://jenkins.example.com/prometheus http://jenkins.example.com/metrics改变它http://jenkins.example.com/prometheus

by using prometheus.yml通过使用 prometheus.yml

change prometheus.yml file更改 prometheus.yml 文件

job_name: Jenkins scrape_interval: 5s metrics_path: '/prometheus' scheme: http. job_name: Jenkins scrape_interval: 5s metrics_path: '/prometheus' 方案:http。 tls_config: tls_config:
insecure_skip_verify: true static_configs: - targets: ['jenkins.example.com:8080'] insecure_skip_verify: true static_configs: - 目标: ['jenkins.example.com:8080']

For me it works belowin prometheus.xml file对我来说,它在 prometheus.xml 文件下面工作

  • job_name: 'jenkins'工作名称:'詹金斯'

    metrics_path: '/jenkins/prometheus'指标路径:'/詹金斯/普罗米修斯'

    scheme: http方案:http

    static_configs:静态配置:

    • targets: ['domainname:port']目标:['域名:端口']

    basic_auth:基本身份验证:

    username: 'xxxxxx'用户名:'xxxxxx'

    password: 'xxxxxxxxxxxxxxxxxxxx'密码:'xxxxxxxxxxxxxxxxxxxxx'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM