newrelic/newrelic-prometheus-configuratorNew Relic Prometheus Configurator Image 是由 New Relic 官方提供的容器化工具,旨在简化 Prometheus 与 New Relic 平台的集成配置流程。该镜像通过自动化生成和管理 Prometheus 配置文件(如 prometheus.yml),帮助用户快速实现 Prometheus 指标向 New Relic 的采集与上报,减少手动配置的复杂度和出错风险。
| 功能特性 | 说明 |
|---|---|
| 自动化配置生成 | 基于环境变量或输入参数自动生成 prometheus.yml,无需手动编写配置文件。 |
| New Relic Remote Write 集成 | 预置 New Relic Remote Write 端点配置,支持指标直接上报至 New Relic。 |
| 指标过滤与转换 | 支持通过规则(如正则表达式)筛选需上报的指标,减少无效数据传输。 |
| 密钥安全管理 | 支持通过环境变量注入 New Relic 许可证密钥,避免配置文件硬编码敏感信息。 |
| 轻量级设计 | 基于 Alpine 基础镜像,体积小(<50MB),启动速度快,适合容器化部署。 |
| 多环境适配 | 支持开发、测试、生产等多环境配置参数切换,灵活适配不同场景需求。 |
从 Docker Hub 或 New Relic 官方镜像仓库拉取最新版本镜像:
bashdocker pull newrelic/newrelic-prometheus-configurator:latest
通过运行容器生成 prometheus.yml,并挂载到本地目录以便 Prometheus 使用:
bashdocker run -it --rm \ -e NEW_RELIC_LICENSE_KEY=<YOUR_NEW_RELIC_LICENSE_KEY> \ -v $(pwd)/prometheus-config:/output \ newrelic/newrelic-prometheus-configurator:latest
/output 目录生成 prometheus.yml,并通过本地挂载的 ./prometheus-config 目录输出到宿主机。将生成的 prometheus.yml 挂载到 Prometheus 容器中,示例 Docker Compose 配置:
yaml# docker-compose.yml version: '3' services: prometheus: image: prom/prometheus:latest volumes: - ./prometheus-config/prometheus.yml:/etc/prometheus/prometheus.yml # 挂载生成的配置文件 ports: - "9090:9090" restart: always configurator: image: newrelic/newrelic-prometheus-configurator:latest environment: - NEW_RELIC_LICENSE_KEY=<YOUR_NEW_RELIC_LICENSE_KEY> - PROMETHEUS_CONFIG_OUTPUT_PATH=/output/prometheus.yml volumes: - ./prometheus-config:/output restart: on-failure # 配置生成后可停止,或按需设置为 "always" 监控配置变更
通过环境变量控制配置生成逻辑,常用参数如下:
| 环境变量名 | 用途 | 示例值 | 是否必填 |
|---|---|---|---|
NEW_RELIC_LICENSE_KEY | New Relic 许可证密钥,用于身份验证。 | eu01xxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx(从 New Relic 控制台获取) | 是 |
PROMETHEUS_CONFIG_OUTPUT_PATH | 生成的 prometheus.yml 输出路径。 | /output/prometheus.yml(容器内路径,需通过挂载映射到宿主机) | 否(默认 /etc/prometheus/prometheus.yml) |
REMOTE_WRITE_URL | New Relic Remote Write 端点 URL。 | [***]{NEW_RELIC_LICENSE_KEY} | 否(默认根据密钥自动匹配区域端点) |
METRIC_INCLUDE_PATTERNS | 需上报的指标过滤规则(正则表达式)。 | ^node_cpu_.*,^kube_pod_.*(仅上报节点 CPU 和 Kubernetes Pod 指标) | 否(默认全部指标) |
METRIC_EXCLUDE_PATTERNS | 需排除的指标过滤规则(正则表达式)。 | ^go_.*,^process_.*(排除 Go 运行时和进程指标) | 否(默认无排除规则) |
LOG_LEVEL | 日志级别(debug/info/warn/error)。 | info | 否(默认 info) |
通过 docker-compose.yml 集成 Prometheus 和 Configurator,实现配置自动生成与 Prometheus 联动:
yaml# docker-compose.yml version: '3.8' services: prometheus-configurator: image: newrelic/newrelic-prometheus-configurator:latest environment: - NEW_RELIC_LICENSE_KEY=eu01xxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx # 替换为实际密钥 - METRIC_INCLUDE_PATTERNS=^node_cpu_.*,^node_memory_.*,^kube_pod_.* - METRIC_EXCLUDE_PATTERNS=^node_cpu_guest.* # 排除 guest CPU 指标 - PROMETHEUS_CONFIG_OUTPUT_PATH=/config/prometheus.yml volumes: - prometheus-config:/config # 共享配置目录给 Prometheus restart: on-failure # 配置生成成功后可停止,或按需设置为 "always" prometheus: image: prom/prometheus:v2.45.0 volumes: - prometheus-config:/etc/prometheus # 挂载生成的配置文件 - prometheus-data:/prometheus # 持久化 Prometheus 数据 ports: - "9090:9090" command: - '--config.file=/etc/prometheus/prometheus.yml' # 使用生成的配置 depends_on: - prometheus-configurator # 确保配置生成后启动 Prometheus restart: always volumes: prometheus-config: # 共享配置卷 prometheus-data: # Prometheus 数据卷
启动容器后,检查挂载目录下是否生成 prometheus.yml:
bashcat ./prometheus-config/prometheus.yml
预期输出应包含 remote_write 配置,指向 New Relic 端点:
yamlremote_write: - url: "[***]" write_relabel_configs: - source_labels: [__name__] regex: "(node_cpu_.*|node_memory_.*|kube_pod_.*)" action: keep - source_labels: [__name__] regex: "node_cpu_guest.*" action: drop
访问 Prometheus 控制台(http://localhost:9090),在「Status > Configuration」中确认配置加载成功,且「Remote Write Targets」显示正常连接。
NEW_RELIC_LICENSE_KEY 为敏感信息,建议通过容器平台的密钥管理功能(如 Kubernetes Secrets)注入,避免明文暴露。METRIC_INCLUDE_PATTERNS 和 METRIC_EXCLUDE_PATTERNS 合理过滤指标,避免大量无效数据导致的流量和存储成本增加。newrelic/newrelic-prometheus-configurator:latest)以获取功能更新和安全补丁。manifest unknown 错误
TLS 证书验证失败
DNS 解析超时
410 错误:版本过低
402 错误:流量耗尽
身份认证失败错误
429 限流错误
凭证保存错误
来自真实用户的反馈,见证轩辕镜像的优质服务