monitoring - 为 Prometheus Target 配置 basic_auth
问题描述
static_configs
我的 prometheus.yml 配置文件中的目标之一通过基本身份验证进行保护。因此,Prometheus 目标页面中始终针对该目标显示描述“连接被拒绝”的错误。
我研究了如何设置 prometheus 以在尝试抓取该特定目标但找不到任何解决方案时提供安全凭据。我发现如何scrape_config
在文档中的部分进行设置。这对我不起作用,因为我还有其他不受basic_auth
. 请帮我解决这个挑战。
.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:
解决方案
我想在@PatientZro 答案中添加更多详细信息。
就我而言,我需要创建另一个作业(如指定),但 basic_auth 需要与 job_name 处于同一缩进级别。请参见此处的示例。
同样,我的 basic_auth 案例需要路径,因为它们没有显示在我的域的根目录中。
以下是指定 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'
最好的,
推荐阅读
- node.js - 如何使用 find 方法 express js 获取文档数量?
- sql - SQL:防止无效数据插入表的触发器
- mongodb - 如何仅匹配包含另一个数组的条件适用于数组中的所有文档的文档?
- javascript - TinyMCE 表:如何隐藏高级属性?
- ruby-on-rails - Rails Webpacker 在生产环境中编译错误
- sql-server - 有没有办法在 Azure PaaS 数据库中创建第二个登录名(使用用户)?
- ios - ARFoundation 集成在 ios 本机应用程序中,因为库崩溃并出现 EXC_BAD_ACCESS 错误
- c# - 使用持续时间显示天数不减少超过 31
- laravel - 如何将模型的属性附加到对象
- mysql - 如何构造 if exists 查询以产生错误消息