Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

39 Commits

Folders and files

Repository files navigation

CloudWatch Exporter

CloudWatch Exporter 通过 UCloud CloudWatch API 采集云产品监控指标,并以 Prometheus 格式暴露。

安全提示:不要将 Exporter 直接暴露到公网。

功能

  • 支持指定资源或自动获取产品下全部资源。
  • 支持指定指标或自动采集产品全部指标。
  • 支持关联资源采集和 label 重命名。
  • 提供 /metrics、/self/metrics 和 /health 端点。

构建

需要 Go 1.25 及以上版本。

make build

构建产物为 bin/cloudwatch-exporter,默认以 CGO_ENABLED=0 静态编译。

配置

复制示例配置:

cp config/config.example.toml config.toml

最小配置示例:

[server]
listen       = ":9105"
metrics_path = "/metrics"

[data_source]
endpoint    = "https://api.ucloud.cn"
timeout_ms  = 30000
concurrency = 20

[credential]
public_key  = "YOUR_PUBLIC_KEY"
private_key = "YOUR_PRIVATE_KEY"

[[scrape]]
project_id      = "org-xxxxxx"
region          = "cn-bj2"
product_key     = "uhost"
resource_ids    = ["uhost-xxx"]
metrics         = ["uhost_cpu_used"]
all_resource_id = false
all_metrics     = false

凭证也可以通过环境变量传入,优先级高于配置文件:

export PUBLIC_KEY="your_public_key"
export PRIVATE_KEY="your_private_key"

配置项

[server]

字段 默认 说明
listen :9105 HTTP 监听地址
metrics_path /metrics Prometheus 指标路径

[data_source]

字段 默认 说明
endpoint 必填 CloudWatch API 地址
timeout_ms 30000 请求超时时间,单位毫秒,最低 10000
concurrency 20 并发数,最大 20

[credential]

字段 说明
public_key 公钥,可通过 PUBLIC_KEY 覆盖
private_key 私钥,可通过 PRIVATE_KEY 覆盖

[log]

字段 默认 说明
level info 日志级别:debug、info、warn、error
file stdout 日志文件路径;stdout 或留空时输出到标准输出
max_size 10 单个日志文件大小上限,单位 MB
max_backups 7 保留的日志文件数量
max_age 7 日志文件保留天数
compress false 是否压缩历史日志

[poller]

字段 默认 说明
stale_multiplier 3 超过 采集间隔 × multiplier 未更新的指标停止暴露
sync_resources_interval_sec 600 资源、指标和关联关系的同步周期,单位秒

[[scrape]]

字段 必填 说明
project_id 是 项目 ID
region 是 地域,如 cn-bj2
product_key 是 产品标识,如 uhost
resource_ids 条件必填 all_resource_id=false 时必填
all_resource_id 否 为 true 时自动获取产品下全部资源
metrics 条件必填 all_metrics=false 时必填
all_metrics 否 为 true 时采集产品全部指标
tags 否 标签过滤条件,例如 { env = ["prod"] };多个标签按 AND 处理
related_resources 否 关联资源产品标识列表
label_aliases 否 label 重命名映射

[product_types]

用于补充 product_key 到数字资源类型的映射。通常无需配置,接口无法返回类型时可添加:

[product_types]
ulb = 11

关联资源采集

在源产品的 [[scrape]] 中配置:

related_resources = ["ulbvserver", "eip"]

关联资源会采集对应产品的全部指标,并额外输出以下 label:

  • source_resource_id:源资源 ID。
  • source_resource_name:源资源名称;无法获取时省略。

关联资源范围与源 [[scrape]] 的 resource_ids / all_resource_id 一致。

label 别名

label_aliases = { "ucs:general.ParentResourceID" = "parent_resource_id" }
  • 源名称大小写敏感,必须与上游 TagMap 的 key 或内置 label 名一致。
  • 目标名称必须符合 Prometheus label 命名规则,且不能使用内置 label 名或以 __ 开头。
  • 不要直接使用 /metrics 中经过转义的 label 名;例如上游 ucs:general.ParentResourceID 在 /metrics 中可能显示为 ucs:general_ParentResourceID。
  • 源名称未匹配时,别名不会生效,日志会输出 WARN。

内置 label:product_key、resource_id、resource_name、resource_remark、region、project_id。

启动

# 使用默认配置路径 config.toml
./cloudwatch-exporter

# 指定配置文件
./cloudwatch-exporter -c /path/to/config.toml

# 覆盖监听端口
./cloudwatch-exporter -c config.toml -p 9106

# 通过环境变量传入凭证
PUBLIC_KEY=your_public_key PRIVATE_KEY=your_private_key \
  ./cloudwatch-exporter -c config.toml
参数 默认 说明
-c config.toml 配置文件路径
-p 配置文件中的端口 覆盖监听端口

验证

# 业务指标
curl http://localhost:9105/metrics

# 自监控指标
curl http://localhost:9105/self/metrics

# 健康检查
curl http://localhost:9105/health

Prometheus 接入

scrape_configs:
  - job_name: cloudwatch-exporter
    static_configs:
      - targets: ["<exporter-ip>:9105"]

部署

  • 二进制包部署见 INSTALL_GUIDE.md。
  • Prometheus + Grafana 部署配置见 deploy/ 目录。

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages