2023-10-09 11:35:04 10阅读
instance
"113.125.219.21" - if eq .EnvMap.POD_IP
tags
province"福建省|吉林省"
"113.125.219.22" - else if eq .EnvMap.POD_IP
tags
province"江苏省"
hash0
hash_modulus2
"113.125.219.23" - else if eq .EnvMap.POD_IP
tags
province"江苏省"
hash1
hash_modulus2
- end
exclude_labels
hash
hash_modulus
通过上面的语法定义好实例信息,其中:
EnvMap
是环境变量集合,引用环境变量可通过 .EnvMap.xxx
。比如通过k8s向sidecar设置了环境变量POD_IP,则在模板中引用方法为 .EnvMap.POD_IP
实例信息格式说明
instance
# 标签信息
tags
# 在这里自定义标签
# tags中的标签将被作为标识 __identify_${tag中值} (如:__identify_province)传递给query
# 查询是可以添加类似 __identify_province="福建省" 标签来为query定向指定后端,避免全局扫描
# 格式:key: value 如需作为query标识则不支持嵌套
exclude_labels
# 数组,这里指定哪些标签不传递给query
# 如上面的例子:最终只有 __identify_province 会传递到query
注意:如果在
tags
中定义了很多标签,那么不需要传递给query的一定要在exclude_labels
设置下,避免影响query性能
scrape_configs
"") - if and (.Instance.Tags.province) (ne .Instance.Tags.province
job_name'nginx-vtx-exporter'
metrics_path /vod_vts
relabel_configs
source_labels __meta_consul_service_metadata_province
regex Instance.Tags.province
action keep
- if and (.Instance.Tags.hash) (.Instance.Tags.hash_modulus)
source_labels __meta_consul_service_metadata_node
modulus .Instance.Tags.hash_modulus
target_label __tmp_hash
action hashmod
source_labels __tmp_hash
regex ^ .Instance.Tags.hash $
action keep
- end
....
job_name''
....
- end
groups
name nginx_bandwidth_all_thanos_record_record
interval 60s
rules
# 如果做拆分了,就不在这里做省份粒度的预计算
- if or (not .Instance.Tags.hash) (not .Instance.Tags.hash_modulus)
record record_Rate5mDomainIspProvinceBW
expr sum(record_Rate5mInstanceBW node_module=~".*直播.*" )by(province,isp)
- end
rule模板命名一定要用
.tpl
后缀才会生效
综上所述,最后为sidecar指定命令参数:
--reloader.identify-config-file=/xxx/sidecar_instance.yml # 指定sidecar实例信息文件
--reloader.config-file=/xxx/prometheus.yaml # 指定prometheus配置模板文件,这个参数不变,里面的内容要变
--reloader.rule-dir=/xxx/rule # 指定规则目录,参数不变
/xxx/rule 目录中的内容说明:.tpl 后缀的就是模板文件,会生成对应的 .yml文件;.yml文件不经过模板化处理
同一个目录下.tpl后缀的文件和.yml后缀的文件,出去后缀后的名称不要相同,否则会互相覆盖
这部分与sidecar实例信息模板定义
一样
instance
"thanos-rule-0" - if eq .EnvMap.POD_NAME
tags
provinces
'福建省'
'江苏省'
"thanos-rule-1" - else if eq .EnvMap.POD_NAME
tags
provinces
'辽宁省'
'广东省'
- end
exclude_labels
provinces
groups
# 如果有定义 provinces 则说明需要进行省粒度预计算
- if and (.Instance.Tags.provinces) (gt (len .Instance.Tags.provinces) 0)
name nginx_bandwidth_all_thanos_record_record
interval 60s
rules
- range $index $province := .Instance.Tags.provinces
record record_Rate5mDomainIspProvinceBW
expr sum(record_Rate5mInstanceBW node_module=~".*直 播.*" __identify_province=~"{{$province}}" )by(host_group_level)
- end
- end
综上所述,thanos-rule需要新增参数
--rule-template=/xxx/rule_instance.yml
-rule-file=/xxx/rule/*.yml指定规则目录,其中,rule模板仍然是以.tpl
2023-10-09 11:35:04 10阅读
instance
"113.125.219.21" - if eq .EnvMap.POD_IP
tags
province"福建省|吉林省"
"113.125.219.22" - else if eq .EnvMap.POD_IP
tags
province"江苏省"
hash0
hash_modulus2
"113.125.219.23" - else if eq .EnvMap.POD_IP
tags
province"江苏省"
hash1
hash_modulus2
- end
exclude_labels
hash
hash_modulus
通过上面的语法定义好实例信息,其中:
EnvMap
是环境变量集合,引用环境变量可通过 .EnvMap.xxx
。比如通过k8s向sidecar设置了环境变量POD_IP,则在模板中引用方法为 .EnvMap.POD_IP
实例信息格式说明
instance
# 标签信息
tags
# 在这里自定义标签
# tags中的标签将被作为标识 __identify_${tag中值} (如:__identify_province)传递给query
# 查询是可以添加类似 __identify_province="福建省" 标签来为query定向指定后端,避免全局扫描
# 格式:key: value 如需作为query标识则不支持嵌套
exclude_labels
# 数组,这里指定哪些标签不传递给query
# 如上面的例子:最终只有 __identify_province 会传递到query
注意:如果在
tags
中定义了很多标签,那么不需要传递给query的一定要在exclude_labels
设置下,避免影响query性能
scrape_configs
"") - if and (.Instance.Tags.province) (ne .Instance.Tags.province
job_name'nginx-vtx-exporter'
metrics_path /vod_vts
relabel_configs
source_labels __meta_consul_service_metadata_province
regex Instance.Tags.province
action keep
- if and (.Instance.Tags.hash) (.Instance.Tags.hash_modulus)
source_labels __meta_consul_service_metadata_node
modulus .Instance.Tags.hash_modulus
target_label __tmp_hash
action hashmod
source_labels __tmp_hash
regex ^ .Instance.Tags.hash $
action keep
- end
....
job_name''
....
- end
groups
name nginx_bandwidth_all_thanos_record_record
interval 60s
rules
# 如果做拆分了,就不在这里做省份粒度的预计算
- if or (not .Instance.Tags.hash) (not .Instance.Tags.hash_modulus)
record record_Rate5mDomainIspProvinceBW
expr sum(record_Rate5mInstanceBW node_module=~".*直播.*" )by(province,isp)
- end
rule模板命名一定要用
.tpl
后缀才会生效
综上所述,最后为sidecar指定命令参数:
--reloader.identify-config-file=/xxx/sidecar_instance.yml # 指定sidecar实例信息文件
--reloader.config-file=/xxx/prometheus.yaml # 指定prometheus配置模板文件,这个参数不变,里面的内容要变
--reloader.rule-dir=/xxx/rule # 指定规则目录,参数不变
/xxx/rule 目录中的内容说明:.tpl 后缀的就是模板文件,会生成对应的 .yml文件;.yml文件不经过模板化处理
同一个目录下.tpl后缀的文件和.yml后缀的文件,出去后缀后的名称不要相同,否则会互相覆盖
这部分与sidecar实例信息模板定义
一样
instance
"thanos-rule-0" - if eq .EnvMap.POD_NAME
tags
provinces
'福建省'
'江苏省'
"thanos-rule-1" - else if eq .EnvMap.POD_NAME
tags
provinces
'辽宁省'
'广东省'
- end
exclude_labels
provinces
groups
# 如果有定义 provinces 则说明需要进行省粒度预计算
- if and (.Instance.Tags.provinces) (gt (len .Instance.Tags.provinces) 0)
name nginx_bandwidth_all_thanos_record_record
interval 60s
rules
- range $index $province := .Instance.Tags.provinces
record record_Rate5mDomainIspProvinceBW
expr sum(record_Rate5mInstanceBW node_module=~".*直 播.*" __identify_province=~"{{$province}}" )by(host_group_level)
- end
- end
综上所述,thanos-rule需要新增参数
--rule-template=/xxx/rule_instance.yml
-rule-file=/xxx/rule/*.yml指定规则目录,其中,rule模板仍然是以.tpl