使用 jenkins prometheus 插件
Working with jenkins prometheus plugin
我在 https://jenkins.example.com
中有 Jenkins。
与 2 env 一起工作的插件。变量:
PROMETHEUS_ENDPOINT Configures rest endpoint. Defaults to "prometheus"
PROMETHEUS_NAMESPACE Configure prometheus metric namespace. Defaults to "default"
我需要将指标发送至 https://jenkins.example.com/metrics
什么 PROMETHEUS_ENDPOINT
和 PROMETHEUS_NAMESPACE
值?
http://jenkins.example.com/metrics
更改
http://jenkins.example.com/prometheus
通过使用 prometheus.yml
更改prometheus.yml文件
job_name: Jenkins
scrape_interval: 5s
metrics_path: '/prometheus'
scheme: http.
tls_config:
insecure_skip_verify: true
static_configs:
- targets: ['jenkins.example.com:8080']
PROMETHEUS_ENDPOINT
- 配置路径。默认为 prometheus
,因此您的指标可以通过 URI /prometheus/
.
访问
你想要的是将PROMETHEUS_ENDPOINT
配置为metrics
。您仍然需要将变量 metrics_path
添加到 prometheux.xml
并将其设置为 /metrics/
PROMETHEUS_NAMESPACE
- 为每个指标添加前缀。
很快:您实际上不需要编辑此值。如果你愿意,你可以配置它们:
Jenkins -> Manage Jenkins -> Configure System -> Promethues (section)
简而言之PROMETHEUS_ENDPOINT
使用 GET Http 请求获取 jenkins 指标的索引页 - https://<your-jenkins-path>/prometheus
使用 jenkins prometheus 插件的有用/黄金提示:
将参数 Enable authentication for prometheus end-point
设置为 true
,您将能够获取有关内部流程和作业的信息 运行 在你的詹金斯端点上。
在 jenkins 上创建专用于 prometheus 监控的用户帐户,创建用于身份验证的令牌。
为该用户设置查看 jenkins 指标的屏幕权限:
启用指标权限:
Managing jenkins -> Manage and assign roles -> Manage Roles -> Metrics
(set view and health-check to true).
将此权限分配给特定用户:(您的 prometheus 用户)-
Managing jenkins -> Manage and assign roles -> Assign Roles -> find
your user and add screen permission.
- 在您的 prometheus 堆栈中的 prometheus.yml 上配置此凭据。我附上了这个例子,这个模式对我有用:
- 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'
- 为了测试这是否是实际工作,使用 curl 执行 http 请求插件 api 和 jenkins 集成。
curl -u user:token jenkinsURL:port/prometheus/
例如:
curl -u JohnDoe@gmail.com:abc123 company.jenkins.com:8080/prometheus/
- 要测试您与 prometheus 的集成,请转到您的
http://yourPrometheusURL.com:9090/targets
并确保您的端点已启动。您应该获得指标并开始使用它。祝你好运。
对我来说,它在下面的 prometheus.xml 文件中有效
job_name: 'jenkins'
metrics_path: '/jenkins/prometheus'
方案:http
static_configs:
- 目标:['domainname:port']
basic_auth:
用户名:'xxxxxx'
密码:'xxxxxxxxxxxxxxxxxxxx'
我在 https://jenkins.example.com
中有 Jenkins。
与 2 env 一起工作的插件。变量:
PROMETHEUS_ENDPOINT Configures rest endpoint. Defaults to "prometheus"
PROMETHEUS_NAMESPACE Configure prometheus metric namespace. Defaults to "default"
我需要将指标发送至 https://jenkins.example.com/metrics
什么 PROMETHEUS_ENDPOINT
和 PROMETHEUS_NAMESPACE
值?
http://jenkins.example.com/metrics 更改 http://jenkins.example.com/prometheus
通过使用 prometheus.yml
更改prometheus.yml文件
job_name: Jenkins scrape_interval: 5s metrics_path: '/prometheus' scheme: http. tls_config:
insecure_skip_verify: true static_configs: - targets: ['jenkins.example.com:8080']
PROMETHEUS_ENDPOINT
- 配置路径。默认为 prometheus
,因此您的指标可以通过 URI /prometheus/
.
你想要的是将PROMETHEUS_ENDPOINT
配置为metrics
。您仍然需要将变量 metrics_path
添加到 prometheux.xml
并将其设置为 /metrics/
PROMETHEUS_NAMESPACE
- 为每个指标添加前缀。
很快:您实际上不需要编辑此值。如果你愿意,你可以配置它们:
Jenkins -> Manage Jenkins -> Configure System -> Promethues (section)
简而言之PROMETHEUS_ENDPOINT
使用 GET Http 请求获取 jenkins 指标的索引页 - https://<your-jenkins-path>/prometheus
使用 jenkins prometheus 插件的有用/黄金提示:
将参数
Enable authentication for prometheus end-point
设置为true
,您将能够获取有关内部流程和作业的信息 运行 在你的詹金斯端点上。在 jenkins 上创建专用于 prometheus 监控的用户帐户,创建用于身份验证的令牌。
为该用户设置查看 jenkins 指标的屏幕权限:
启用指标权限:
Managing jenkins -> Manage and assign roles -> Manage Roles -> Metrics (set view and health-check to true).
将此权限分配给特定用户:(您的 prometheus 用户)-
Managing jenkins -> Manage and assign roles -> Assign Roles -> find your user and add screen permission.
- 在您的 prometheus 堆栈中的 prometheus.yml 上配置此凭据。我附上了这个例子,这个模式对我有用:
- 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'
- 为了测试这是否是实际工作,使用 curl 执行 http 请求插件 api 和 jenkins 集成。
curl -u user:token jenkinsURL:port/prometheus/
例如:
curl -u JohnDoe@gmail.com:abc123 company.jenkins.com:8080/prometheus/
- 要测试您与 prometheus 的集成,请转到您的
http://yourPrometheusURL.com:9090/targets
并确保您的端点已启动。您应该获得指标并开始使用它。祝你好运。
对我来说,它在下面的 prometheus.xml 文件中有效
job_name: 'jenkins'
metrics_path: '/jenkins/prometheus'
方案:http
static_configs:
- 目标:['domainname:port']
basic_auth:
用户名:'xxxxxx'
密码:'xxxxxxxxxxxxxxxxxxxx'