Prometheus之gce_sd_config

半兽人 发表于: 2020-10-20   最后更新时间: 2020-10-20 21:27:42  
{{totalSubscript}} 订阅, 1,974 游览

从GCP GCE实例中,GCE SD配置允许检索和获取目标。这个内网IP地址被默认使用,但是在relabeling期间,这个公网IP地址可能会发生变化。

在relabeling期间,下面的meta标签在目标上是可用的:

  • __meta_gce_instance_name: 实例名称
  • __meta_gce_metadata_<name>: 实例每一个metadata项
  • __meta_gce_network: 实例的网络
  • __meta_gce_private_ip: 实例的内网IP
  • __meta_gce_project: 正在运行的GCP项目
  • __meta_gce_public_ip: 如果存在,表示GCP的公网IP地址
  • __meta_gce_subnetwork: 实例的子网
  • __meta_gce_tags: 实例的tag列表
  • __meta_gce_zone: 正在运行的实例的GCE区域

对于GCE discovery,看看下面的配置选项:

# The information to access the GCE API.

# The GCP Project
project: <string>

# The zone of the scrape targets. If you need multiple zones use multiple
# gce_sd_configs.
zone: <string>

# Filter can be used optionally to filter the instance list by other criteria
[ filter: <string> ]

# Refresh interval to re-read the instance list
[ refresh_interval: <duration> | default = 60s ]

# The port to scrape metrics from. If using the public IP address, this must
# instead be specified in the relabeling rule.
[ port: <int> | default = 80 ]

# The tag separator is used to separate the tags on concatenation
[ tag_separator: <string> | default = , ]

Google Cloud SDK默认客户端通过查找一下位置发现凭据,优先选择找到的第一个位置:

  1. 由GOOGLE_APPLICATION_CREENTIALS环境变量指定的JSON文件
  2. 一个JSON文件在大家都熟悉的路径下:$HOME/.config/gclooud/application_default_credentials.json
  3. 从GCE元数据服务器获取

如果Prometheus运行在GCE上,关联这个正在运行的实例的服务账号,应该至少可以从计算资源上有读取数据的权限。如果运行在GCE外面,需要确保创建一个合适的服务账号,并把证书文件放置在指定的某个地方。

更新于 2020-10-20
在线,1小时前登录

查看Prometheus更多相关的文章或提一个关于Prometheus的问题,也可以与我们一起分享文章