来自PushGateway的官方文档:
- 要使用分组键
job="directory_cleaner"
, path="/var/tmp"
,以下路径将不起作用:
/metrics/job/directory_cleaner/path//var/tmp
相反,对标签值使用 base64 URL 安全编码,并通过在标签名称后面加上 来标记它@base64
:
/metrics/job/directory_cleaner/path@base64/L3Zhci90bXA
url
这是从存储在中的多个键值对生成的示例Map<String, String> groupingKey
:
String url = gatewayBaseURL;
if (job.contains("/")) {
url += "job@base64/" + base64url(job);
} else {
url += "job/" + URLEncoder.encode(job, "UTF-8");
}
if (groupingKey != null) {
for (Map.Entry<String, String> entry: groupingKey.entrySet()) {
if (entry.getValue().contains("/")) {
url += "/" + entry.getKey() + "@base64/" + base64url(entry.getValue());
} else {
url += "/" + entry.getKey() + "/" + URLEncoder.encode(entry.getValue(), "UTF-8");
}
}
}
HttpURLConnection connection = connectionFactory.create(url);
Github 链接