[英]Configure basic_auth for Prometheus Target
One of the targets in static_configs
in my prometheus.yml config file is secured with basic authentication.我的 prometheus.yml 配置文件中
static_configs
中的目标之一通过基本身份验证进行保护。 As a result, an error of description "Connection refused" is always displayed against that target in the Prometheus Targets' page.因此,在 Prometheus 目标页面中始终针对该目标显示描述为“连接被拒绝”的错误。
I have researched how to setup prometheus to provide the security credentials when trying to scrape that particular target but couldn't find any solution.我研究了如何设置 prometheus 以在尝试抓取该特定目标时提供安全凭据,但找不到任何解决方案。 What I found was how to set it up on the
scrape_config
section in the docs.我发现的是如何在文档的
scrape_config
部分进行设置。 This won't work for me because I have other targets that are not protected with basic_auth
.这对我不起作用,因为我还有其他不受
basic_auth
保护的目标。 Please help me out with this challenge.请帮我解决这个挑战。
Here is part of my .yml
config as regards my challenge.关于我的挑战,这是我的
.yml
配置的一部分。
scrape_configs:
# The job name is added as a label `job=<job_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
scrape_timeout: 5s
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
- targets: ['localhost:5000']
labels:
service: 'Auth'
- targets: ['localhost:5090']
labels:
service: 'Approval'
- targets: ['localhost:6211']
labels:
service: 'Credit Assessment'
- targets: ['localhost:6090']
labels:
service: 'Sweep'
- targets: ['localhost:6500']
labels:
I would like to add more details to the @PatientZro answer.我想在@PatientZro 答案中添加更多详细信息。
In my case, I need to create another job (as specified), but basic_auth needs to be at the same level of indentation as job_name.就我而言,我需要创建另一个作业(如指定的那样),但 basic_auth 需要与 job_name 的缩进级别相同。 See example here .
请参阅此处的示例。
As well, my basic_auth cases require a path as they are not displayed at the root of my domain.同样,我的 basic_auth 案例需要一个路径,因为它们没有显示在我的域的根目录中。
Here is an example with an API endpoint specified:下面是一个指定了 API 端点的示例:
- job_name: 'myapp_health_checks'
scrape_interval: 5m
scrape_timeout: 30s
static_configs:
- targets: ['mywebsite.org']
metrics_path: "/api/health"
basic_auth:
username: 'email@username.me'
password: 'cfgqvzjbhnwcomplicatedpasswordwjnqmd'
Best,最好的事物,
Create another job for the one that needs auth.为需要身份验证的人创建另一份工作。
So just under what you've posted, do another所以就在你发布的内容下面,再做一个
- job_name: 'prometheus-basic_auth'
scrape_interval: 5s
scrape_timeout: 5s
static_configs:
- targets: ['localhost:5000']
labels:
service: 'Auth'
basic_auth:
username: foo
password: bar
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.