From the official documentation of PushGateway:
- To use the grouping key
job="directory_cleaner"
,path="/var/tmp"
, the following path will not work:
/metrics/job/directory_cleaner/path//var/tmp
Instead, use the base64 URL-safe encoding for the label value and mark it by suffixing the label name with @base64
:
/metrics/job/directory_cleaner/path@base64/L3Zhci90bXA
Here is an example of generating url
from multiple key-value pair stored in 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 link