不确定您是否还有同样的问题,但我尝试通过 blackbox 导出器设置 api 检查(api 是否工作正常),并在安装我在配置下使用的导出器时。
config:
modules:
http_2xx:
prober: http
timeout: 5s
http:
valid_http_versions: ["HTTP/1.1", "HTTP/2"]
no_follow_redirects: false
preferred_ip_protocol: "ip4"
api_checks:
prober: http
timeout: 5s
http:
method: GET
valid_http_versions: ["HTTP/1.1", "HTTP/2"]
no_follow_redirects: false
preferred_ip_protocol: "ip4"
bearer_token_file: /var/secret.file
第一个模块用于检查正常端点是否可达。AND 第二个模块用于使用不记名令牌检查 api。我创建了一个秘密并将其作为卷安装到 /var/secret.file 的 pod 上
apiVersion: v1
kind: Secret
type: Opaque
metadata:
name: bearer-token
data:
secret.file: |
Z2hwX1lvbsyYXVKeTFndlQzRQo=
并将它们添加到部署文件中,如下所示。
spec:
templates:
metadata:
labels:
app: xxxx
spec:
containers:
- name: XXXX
image: "image-name"
volumeMounts:
- name: bearer-token
mountPath: /var/
volumes:
- name: bearer-token
secret:
secretName: bearer-token
之后,我们需要去 prometheus setup 并添加一个scrape config,如下所示
prometheus.yml:
rule_files:
- /etc/config/recording_rules.yml
- /etc/config/alerting_rules.yml
## Below two files are DEPRECATED will be removed from this default values file
- /etc/config/rules
- /etc/config/alerts
scrape_configs:
- job_name: prometheus
static_configs:
- targets:
- localhost:9090
- job_name: Blackbox-check
metrics_path: /probe
static_configs:
- targets:
- www.google.com/
- https://api.github.com/user/repos
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
- source_labels: [__param_target]
target_label: instance
- target_label: __address__
replacement: blackbox-prometheus-blackbox-exporter:9115
- job_name: api_checks
metrics_path: /probe
params:
module: [api_checks]
static_configs:
- targets:
- https://api.github.com/user/repos
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
- source_labels: [__param_target]
target_label: instance
- target_label: __address__
replacement: blackbox-prometheus-blackbox-exporter:9115
它会为你工作。