代码拉取完成,页面将自动刷新
package main
import (
"errors"
"regexp"
"strings"
"github.com/prometheus/client_golang/prometheus"
)
var (
// resource component positions in a resource ID
resourceGroupPosition = 4
resourceNamePosition = 8
subResourceNamePosition = 10
invalidLabelChars = regexp.MustCompile(`[^a-zA-Z0-9_]+`)
)
// ParseResourceID - Returns resource info from a given resource ID.
func ParseResourceID(resourceID string) (map[string]string, error) {
info := make(map[string]string)
resource := strings.Split(resourceID, "/")
if len(resource) < resourceNamePosition+1 {
return nil, errors.New("Error parsing resource ID, expected pattern is not matched for " + resourceID)
}
info["resource_group"] = resource[resourceGroupPosition]
info["resource_name"] = resource[resourceNamePosition]
if len(resource) > subResourceNamePosition && resource[resourceNamePosition+1] != "providers" {
info["sub_resource_name"] = resource[subResourceNamePosition]
}
return info, nil
}
// CreateAllLabels creates label from Tags map and existing labels map
func CreateAllLabels(tags map[string]*string, resourceType *string, labels map[string]string) map[string]string {
labels["resource_type"] = *resourceType
for k, v := range tags {
k = strings.ToLower(k)
k = "tag_" + k
k = invalidLabelChars.ReplaceAllString(k, "_")
labels[k] = *v
}
return labels
}
// ExportAzureTagInfo exports azure_tag_info metric
func ExportAzureTagInfo(ch chan<- prometheus.Metric, tags map[string]*string, resourceType *string, labels map[string]string) {
allLabels := CreateAllLabels(tags, resourceType, labels)
ch <- prometheus.MustNewConstMetric(
prometheus.NewDesc("azure_tag_info", "Tags of the Azure resource", nil, allLabels),
prometheus.GaugeValue,
1,
)
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。