su.nlq.prometheus.jmx.bean.Labels Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jmx-prometheus-collector Show documentation
Show all versions of jmx-prometheus-collector Show documentation
Pipe for JMX MBeans to Prometheus
package su.nlq.prometheus.jmx.bean;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.List;
import java.util.StringJoiner;
import java.util.stream.IntStream;
public final class Labels {
private final @NotNull List names = new ArrayList<>();
private final @NotNull List values = new ArrayList<>();
public void add(@NotNull String name, @NotNull String value) {
if (!name.isEmpty() && !value.isEmpty()) {
names.add(name);
values.add(value);
}
}
public @NotNull List getNames() {
return names;
}
public @NotNull List getValues() {
return values;
}
@Override
public @NotNull String toString() {
final StringJoiner joiner = new StringJoiner(", ");
IntStream.range(0, Math.min(names.size(), values.size()))
.mapToObj(index -> names.get(index) + ':' + values.get(index))
.forEach(joiner::add);
return joiner.toString();
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy