New 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
4.3.1 生成 Prometheus 配置文件
通过运行容器生成 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 目录输出到宿主机。4.3.2 集成到 Prometheus 部署
将生成的 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" 监控配置变更
4.4.1 核心环境变量
通过环境变量控制配置生成逻辑,常用参数如下:
| 环境变量名 | 用途 | 示例值 | 是否必填 |
|---|---|---|---|
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。 | https://metric-api.newrelic.com/prometheus/v1/write?api_key=${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) |
4.4.2 自定义配置示例(Docker Compose)
通过 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: "https://metric-api.newrelic.com/prometheus/v1/write?api_key=eu01xxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" 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)以获取功能更新和安全补丁。您可以使用以下命令拉取该镜像。请将 <标签> 替换为具体的标签版本。如需查看所有可用标签版本,请访问 标签列表页面。
探索更多轩辕镜像的使用方法,找到最适合您系统的配置方式
通过 Docker 登录认证访问私有仓库
无需登录使用专属域名
Kubernetes 集群配置 Containerd
K3s 轻量级 Kubernetes 镜像加速
VS Code Dev Containers 配置
Podman 容器引擎配置
HPC 科学计算容器配置
ghcr、Quay、nvcr 等镜像仓库
Harbor Proxy Repository 对接专属域名
Portainer Registries 加速拉取
Nexus3 Docker Proxy 内网缓存
需要其他帮助?请查看我们的 常见问题Docker 镜像访问常见问题解答 或 提交工单
docker search 限制
站内搜不到镜像
离线 save/load
插件要用 plugin install
WSL 拉取慢
安全与 digest
新手拉取配置
镜像合规机制
manifest unknown
no matching manifest(架构)
invalid tar header(解压)
TLS 证书失败
DNS 超时
域名连通性排查
410 Gone 排查
402 与流量用尽
401 认证失败
429 限流
D-Bus 凭证提示
413 与超大单层
来自真实用户的反馈,见证轩辕镜像的优质服务