add more api wrappers
This commit is contained in:
@ -0,0 +1,21 @@
|
|||||||
|
package com.bdwise.prometheus.client.builder;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
|
||||||
|
public class AlertManagerMetaQueryBuilder implements QueryBuilder {
|
||||||
|
|
||||||
|
private static final String TARGET_URI_PATTERN_SUFFIX = "/api/v1/alertmanagers";
|
||||||
|
|
||||||
|
private String targetUriPattern;
|
||||||
|
|
||||||
|
public AlertManagerMetaQueryBuilder(String serverUrl) {
|
||||||
|
this.targetUriPattern = serverUrl + TARGET_URI_PATTERN_SUFFIX;
|
||||||
|
}
|
||||||
|
public URI build() {
|
||||||
|
return URI.create(targetUriPattern);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean validate() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,33 @@
|
|||||||
|
package com.bdwise.prometheus.client.builder;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class LabelMetaQueryBuilder implements QueryBuilder{
|
||||||
|
|
||||||
|
private static final String TARGET_URI_PATTERN_SUFFIX = "/api/v1/label/#{label}/values";
|
||||||
|
|
||||||
|
private static final String LABEL_STRING = "label";
|
||||||
|
|
||||||
|
private String targetUriPattern;
|
||||||
|
private Map<String, Object> params = new HashMap<String, Object>();
|
||||||
|
|
||||||
|
public LabelMetaQueryBuilder(String serverUrl) {
|
||||||
|
this.targetUriPattern = serverUrl + TARGET_URI_PATTERN_SUFFIX;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LabelMetaQueryBuilder withLabel(String label) {
|
||||||
|
params.put(LABEL_STRING, label);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public URI build() {
|
||||||
|
return URI.create(Utils.namedFormat(targetUriPattern, params));
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean validate() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
@ -19,26 +19,55 @@ public enum QueryBuilderType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
MetadaQuery{
|
SeriesMetadaQuery{
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
public QueryBuilder newInstance(String prometheusUrl) {
|
public QueryBuilder newInstance(String prometheusUrl) {
|
||||||
// TODO Auto-generated method stub
|
return new SeriesMetaQueryBuilder(prometheusUrl);
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
TargetQuery{
|
LabelMetadaQuery{
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
public QueryBuilder newInstance(String prometheusUrl) {
|
public QueryBuilder newInstance(String prometheusUrl) {
|
||||||
// TODO Auto-generated method stub
|
return new LabelMetaQueryBuilder(prometheusUrl);
|
||||||
return null;
|
}
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
TargetMetadaQuery{
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
@Override
|
||||||
|
public QueryBuilder newInstance(String prometheusUrl) {
|
||||||
|
return new TargetMetaQueryBuilder(prometheusUrl);
|
||||||
|
}
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
AlertManagerMetadaQuery{
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
@Override
|
||||||
|
public QueryBuilder newInstance(String prometheusUrl) {
|
||||||
|
return new AlertManagerMetaQueryBuilder(prometheusUrl);
|
||||||
|
}
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
StatusMetadaQuery{
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
@Override
|
||||||
|
public QueryBuilder newInstance(String prometheusUrl) {
|
||||||
|
return new StatusMetaQueryBuilder(prometheusUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
public abstract <T extends QueryBuilder> T newInstance(String prometheusUrl);
|
public abstract <T extends QueryBuilder> T newInstance(String prometheusUrl);
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,50 @@
|
|||||||
|
package com.bdwise.prometheus.client.builder;
|
||||||
|
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
|
import java.net.URI;
|
||||||
|
import java.net.URLEncoder;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class SeriesMetaQueryBuilder implements QueryBuilder{
|
||||||
|
private static final String TARGET_URI="/api/v1/series?";
|
||||||
|
private static final String TARGET_URI_PATTERN_SUFFIX = "#{selector}&start=#{start}&end=#{end}";
|
||||||
|
|
||||||
|
private static final String START_TIME_EPOCH_TIME = "start";
|
||||||
|
private static final String END_TIME_EPOCH_TIME = "end";
|
||||||
|
private static final String QUERY_STRING = "selector";
|
||||||
|
|
||||||
|
private String serverUrl;
|
||||||
|
private Map<String, Object> params = new HashMap<String, Object>();
|
||||||
|
|
||||||
|
public SeriesMetaQueryBuilder(String serverUrl) {
|
||||||
|
this.serverUrl = serverUrl + TARGET_URI;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SeriesMetaQueryBuilder withSelector(String selector) {
|
||||||
|
try {
|
||||||
|
params.put(QUERY_STRING, URLEncoder.encode(selector, "UTF-8").replaceAll("%3D", "=").replaceAll("%26", "&"));
|
||||||
|
} catch (UnsupportedEncodingException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SeriesMetaQueryBuilder withStartEpochTime(long startTime) {
|
||||||
|
params.put(START_TIME_EPOCH_TIME, startTime);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SeriesMetaQueryBuilder withEndEpochTime(long endTime) {
|
||||||
|
params.put(END_TIME_EPOCH_TIME, endTime);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public URI build() {
|
||||||
|
return URI.create(Utils.namedFormat(serverUrl + Utils.namedFormat(TARGET_URI_PATTERN_SUFFIX, params), params));
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean validate() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,21 @@
|
|||||||
|
package com.bdwise.prometheus.client.builder;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
|
||||||
|
public class StatusMetaQueryBuilder implements QueryBuilder {
|
||||||
|
|
||||||
|
private static final String TARGET_URI_PATTERN_SUFFIX = "/api/v1/status/config";
|
||||||
|
|
||||||
|
private String targetUriPattern;
|
||||||
|
|
||||||
|
public StatusMetaQueryBuilder(String serverUrl) {
|
||||||
|
this.targetUriPattern = serverUrl + TARGET_URI_PATTERN_SUFFIX;
|
||||||
|
}
|
||||||
|
public URI build() {
|
||||||
|
return URI.create(targetUriPattern);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean validate() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,22 @@
|
|||||||
|
package com.bdwise.prometheus.client.builder;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
|
||||||
|
public class TargetMetaQueryBuilder implements QueryBuilder {
|
||||||
|
|
||||||
|
private static final String TARGET_URI_PATTERN_SUFFIX = "/api/v1/targets";
|
||||||
|
|
||||||
|
private String targetUriPattern;
|
||||||
|
|
||||||
|
public TargetMetaQueryBuilder(String serverUrl) {
|
||||||
|
this.targetUriPattern = serverUrl + TARGET_URI_PATTERN_SUFFIX;
|
||||||
|
}
|
||||||
|
|
||||||
|
public URI build() {
|
||||||
|
return URI.create(targetUriPattern);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean validate() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
@ -1,9 +1,14 @@
|
|||||||
package com.bdwise.prometheus.client.builder;
|
package com.bdwise.prometheus.client.builder;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
import com.bdwise.prometheus.client.converter.query.QueryDataType;
|
||||||
|
import com.google.gson.stream.JsonReader;
|
||||||
|
|
||||||
public class Utils {
|
public class Utils {
|
||||||
private final static Pattern namedFormatPattern = Pattern.compile("#\\{(?<key>.*?)}");
|
private final static Pattern namedFormatPattern = Pattern.compile("#\\{(?<key>.*?)}");
|
||||||
public static String namedFormat(final String format, Map<String, ? extends Object> kvs) {
|
public static String namedFormat(final String format, Map<String, ? extends Object> kvs) {
|
||||||
|
@ -1,9 +1,19 @@
|
|||||||
package com.bdwise.prometheus.client.converter;
|
package com.bdwise.prometheus.client.converter;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import com.bdwise.prometheus.client.converter.am.AlertManagerResultItem;
|
||||||
|
import com.bdwise.prometheus.client.converter.am.DefaultAlertManagerResult;
|
||||||
|
import com.bdwise.prometheus.client.converter.label.DefaultLabelResult;
|
||||||
import com.bdwise.prometheus.client.converter.query.DefaultQueryResult;
|
import com.bdwise.prometheus.client.converter.query.DefaultQueryResult;
|
||||||
import com.bdwise.prometheus.client.converter.query.QueryDataType;
|
import com.bdwise.prometheus.client.converter.query.QueryDataType;
|
||||||
|
import com.bdwise.prometheus.client.converter.series.DefaultSeriesResult;
|
||||||
|
import com.bdwise.prometheus.client.converter.series.SeriesResultItem;
|
||||||
|
import com.bdwise.prometheus.client.converter.status.DefaultConfigResult;
|
||||||
|
import com.bdwise.prometheus.client.converter.target.DefaultTargetResult;
|
||||||
|
import com.bdwise.prometheus.client.converter.target.TargetResultItem;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.GsonBuilder;
|
import com.google.gson.GsonBuilder;
|
||||||
import com.google.gson.TypeAdapter;
|
import com.google.gson.TypeAdapter;
|
||||||
@ -13,7 +23,6 @@ import com.google.gson.stream.JsonWriter;
|
|||||||
|
|
||||||
public abstract class ConvertUtil {
|
public abstract class ConvertUtil {
|
||||||
|
|
||||||
|
|
||||||
private static QueryDataType searchDataType(String typeString) {
|
private static QueryDataType searchDataType(String typeString) {
|
||||||
for (QueryDataType each : QueryDataType.class.getEnumConstants()) {
|
for (QueryDataType each : QueryDataType.class.getEnumConstants()) {
|
||||||
if (each.name().compareToIgnoreCase(typeString) == 0) {
|
if (each.name().compareToIgnoreCase(typeString) == 0) {
|
||||||
@ -23,6 +32,287 @@ public abstract class ConvertUtil {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static Map<String, String> convertJsonToMap(JsonReader reader) throws IOException {
|
||||||
|
Map<String, String> resultMap = new HashMap<String,String>();
|
||||||
|
reader.beginObject();
|
||||||
|
while(reader.hasNext()) {
|
||||||
|
resultMap.put(reader.nextName(), reader.nextString());
|
||||||
|
}
|
||||||
|
reader.endObject();
|
||||||
|
return resultMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public static DefaultAlertManagerResult convertAlertManagerResultString(String jsonString) {
|
||||||
|
Gson gson = new GsonBuilder().registerTypeAdapter(DefaultAlertManagerResult.class, new TypeAdapter<DefaultAlertManagerResult>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(JsonWriter out, DefaultAlertManagerResult value) throws IOException {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DefaultAlertManagerResult read(JsonReader reader) throws IOException {
|
||||||
|
DefaultAlertManagerResult amResult = new DefaultAlertManagerResult();
|
||||||
|
String status = null;
|
||||||
|
reader.beginObject();
|
||||||
|
while(reader.hasNext()) {
|
||||||
|
String propertyName = reader.nextName();
|
||||||
|
if("status".equals(propertyName)) {
|
||||||
|
status = reader.nextString();
|
||||||
|
} else if("data".equals(propertyName)) {
|
||||||
|
reader.beginObject();
|
||||||
|
while(reader.hasNext()) {
|
||||||
|
String _propertyName = reader.nextName();
|
||||||
|
if("activeAlertmanagers".equals(_propertyName)) {
|
||||||
|
reader.beginArray();
|
||||||
|
while(reader.hasNext()) {
|
||||||
|
AlertManagerResultItem amResultItem = new AlertManagerResultItem();
|
||||||
|
reader.beginObject();
|
||||||
|
while(reader.hasNext()) {
|
||||||
|
String __propertyName = reader.nextName();
|
||||||
|
if("url".equals(__propertyName)) {
|
||||||
|
amResultItem.setUrl(reader.nextString());
|
||||||
|
} else {
|
||||||
|
reader.nextString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
reader.endObject();
|
||||||
|
amResult.addActiveManager(amResultItem);
|
||||||
|
}
|
||||||
|
reader.endArray();
|
||||||
|
|
||||||
|
} else if("droppedAlertmanagers".equals(_propertyName)) {
|
||||||
|
reader.beginArray();
|
||||||
|
while(reader.hasNext()) {
|
||||||
|
AlertManagerResultItem amResultItem = new AlertManagerResultItem();
|
||||||
|
reader.beginObject();
|
||||||
|
while(reader.hasNext()) {
|
||||||
|
String __propertyName = reader.nextName();
|
||||||
|
if("url".equals(__propertyName)) {
|
||||||
|
amResultItem.setUrl(reader.nextString());
|
||||||
|
} else {
|
||||||
|
reader.nextString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
reader.endObject();
|
||||||
|
amResult.addDroppedManager(amResultItem);
|
||||||
|
}
|
||||||
|
reader.endArray();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
reader.endObject();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
reader.endObject();
|
||||||
|
amResult.setStatus(status);
|
||||||
|
return amResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
}).create();
|
||||||
|
return gson.fromJson(jsonString, DefaultAlertManagerResult.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public static DefaultTargetResult convertTargetResultString(String jsonString) {
|
||||||
|
Gson gson = new GsonBuilder().registerTypeAdapter(DefaultTargetResult.class, new TypeAdapter<DefaultTargetResult>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(JsonWriter out, DefaultTargetResult value) throws IOException {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DefaultTargetResult read(JsonReader reader) throws IOException {
|
||||||
|
DefaultTargetResult targetResult = new DefaultTargetResult();
|
||||||
|
String status = null;
|
||||||
|
reader.beginObject();
|
||||||
|
while(reader.hasNext()) {
|
||||||
|
String propertyName = reader.nextName();
|
||||||
|
if("status".equals(propertyName)) {
|
||||||
|
status = reader.nextString();
|
||||||
|
} else if("data".equals(propertyName)) {
|
||||||
|
reader.beginObject();
|
||||||
|
while(reader.hasNext()) {
|
||||||
|
String _propertyName = reader.nextName();
|
||||||
|
if("activeTargets".equals(_propertyName)) {
|
||||||
|
reader.beginArray();
|
||||||
|
while(reader.hasNext()) {
|
||||||
|
TargetResultItem targetResultItem = new TargetResultItem();
|
||||||
|
reader.beginObject();
|
||||||
|
while(reader.hasNext()) {
|
||||||
|
String __propertyName = reader.nextName();
|
||||||
|
if("discoveredLabels".equals(__propertyName)) {
|
||||||
|
targetResultItem.setDiscoveredLabels(convertJsonToMap(reader));
|
||||||
|
} else if("labels".equals(__propertyName)) {
|
||||||
|
targetResultItem.setLabel(convertJsonToMap(reader));
|
||||||
|
} else if("scrapeUrl".equals(__propertyName)) {
|
||||||
|
targetResultItem.setScrapeUrl(reader.nextString());
|
||||||
|
} else if("lastError".equals(__propertyName)) {
|
||||||
|
targetResultItem.setLastError(reader.nextString());
|
||||||
|
} else if("lastScrape".equals(__propertyName)) {
|
||||||
|
targetResultItem.setLastScrape(reader.nextString());
|
||||||
|
} else if("health".equals(__propertyName)) {
|
||||||
|
targetResultItem.setHealth(reader.nextString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
reader.endObject();
|
||||||
|
targetResult.addActiveTarget(targetResultItem);
|
||||||
|
}
|
||||||
|
reader.endArray();
|
||||||
|
|
||||||
|
} else if("droppedTargets".equals(_propertyName)) {
|
||||||
|
reader.beginArray();
|
||||||
|
while(reader.hasNext()) {
|
||||||
|
TargetResultItem targetResultItem = new TargetResultItem();
|
||||||
|
reader.beginObject();
|
||||||
|
while(reader.hasNext()) {
|
||||||
|
String __propertyName = reader.nextName();
|
||||||
|
if("discoveredLabels".equals(__propertyName)) {
|
||||||
|
targetResultItem.setDiscoveredLabels(convertJsonToMap(reader));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
reader.endObject();
|
||||||
|
targetResult.addDroppedTarget(targetResultItem);
|
||||||
|
}
|
||||||
|
reader.endArray();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
reader.endObject();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
reader.endObject();
|
||||||
|
targetResult.setStatus(status);
|
||||||
|
return targetResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
}).create();
|
||||||
|
return gson.fromJson(jsonString, DefaultTargetResult.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public static DefaultConfigResult convertConfigResultString(String jsonString) {
|
||||||
|
Gson gson = new GsonBuilder().registerTypeAdapter(DefaultConfigResult.class, new TypeAdapter<DefaultConfigResult>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(JsonWriter out, DefaultConfigResult value) throws IOException {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DefaultConfigResult read(JsonReader reader) throws IOException {
|
||||||
|
DefaultConfigResult configResult = new DefaultConfigResult();
|
||||||
|
String status = null;
|
||||||
|
reader.beginObject();
|
||||||
|
while(reader.hasNext()) {
|
||||||
|
String propertyName = reader.nextName();
|
||||||
|
if("status".equals(propertyName)) {
|
||||||
|
status = reader.nextString();
|
||||||
|
} else if("data".equals(propertyName)) {
|
||||||
|
reader.beginObject();
|
||||||
|
while(reader.hasNext()) {
|
||||||
|
String _propertyName = reader.nextName();
|
||||||
|
if("yaml".equals(_propertyName)) {
|
||||||
|
configResult.addData(reader.nextString());
|
||||||
|
} else {
|
||||||
|
reader.nextString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
reader.endObject();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
reader.endObject();
|
||||||
|
configResult.setStatus(status);
|
||||||
|
return configResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
}).create();
|
||||||
|
return gson.fromJson(jsonString, DefaultConfigResult.class);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public static DefaultLabelResult convertLabelResultString(String jsonString) {
|
||||||
|
Gson gson = new GsonBuilder().registerTypeAdapter(DefaultLabelResult.class, new TypeAdapter<DefaultLabelResult>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(JsonWriter out, DefaultLabelResult value) throws IOException {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DefaultLabelResult read(JsonReader reader) throws IOException {
|
||||||
|
DefaultLabelResult seriesResult = new DefaultLabelResult();
|
||||||
|
String status = null;
|
||||||
|
reader.beginObject();
|
||||||
|
while(reader.hasNext()) {
|
||||||
|
String propertyName = reader.nextName();
|
||||||
|
if("status".equals(propertyName)) {
|
||||||
|
status = reader.nextString();
|
||||||
|
} else if("data".equals(propertyName)) {
|
||||||
|
reader.beginArray();
|
||||||
|
while(reader.hasNext()) {
|
||||||
|
seriesResult.addData(reader.nextString());
|
||||||
|
}
|
||||||
|
reader.endArray();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
reader.endObject();
|
||||||
|
seriesResult.setStatus(status);
|
||||||
|
return seriesResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
}).create();
|
||||||
|
return gson.fromJson(jsonString, DefaultLabelResult.class);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public static DefaultSeriesResult convertSeriesResultString(String jsonString) {
|
||||||
|
Gson gson = new GsonBuilder().registerTypeAdapter(DefaultSeriesResult.class, new TypeAdapter<DefaultSeriesResult>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(JsonWriter out, DefaultSeriesResult value) throws IOException {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DefaultSeriesResult read(JsonReader reader) throws IOException {
|
||||||
|
DefaultSeriesResult seriesResult = new DefaultSeriesResult();
|
||||||
|
String status = null;
|
||||||
|
reader.beginObject();
|
||||||
|
while(reader.hasNext()) {
|
||||||
|
String propertyName = reader.nextName();
|
||||||
|
if("status".equals(propertyName)) {
|
||||||
|
status = reader.nextString();
|
||||||
|
} else if("data".equals(propertyName)) {
|
||||||
|
reader.beginArray();
|
||||||
|
while(reader.hasNext()) {
|
||||||
|
SeriesResultItem seriesData = new SeriesResultItem();
|
||||||
|
reader.beginObject();
|
||||||
|
while(reader.hasNext()) {
|
||||||
|
seriesData.put(reader.nextName(), reader.nextString());
|
||||||
|
}
|
||||||
|
reader.endObject();
|
||||||
|
seriesResult.addData(seriesData);
|
||||||
|
// System.out.println(seriesData);
|
||||||
|
}
|
||||||
|
reader.endArray();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
reader.endObject();
|
||||||
|
seriesResult.setStatus(status);
|
||||||
|
return seriesResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
}).create();
|
||||||
|
return gson.fromJson(jsonString, DefaultSeriesResult.class);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public static <T extends Data> DefaultQueryResult<T> convertQueryResultString(String jsonString) {
|
public static <T extends Data> DefaultQueryResult<T> convertQueryResultString(String jsonString) {
|
||||||
Gson gson = new GsonBuilder().registerTypeAdapter(DefaultQueryResult.class, new TypeAdapter<DefaultQueryResult<T>>() {
|
Gson gson = new GsonBuilder().registerTypeAdapter(DefaultQueryResult.class, new TypeAdapter<DefaultQueryResult<T>>() {
|
||||||
|
@ -2,7 +2,7 @@ package com.bdwise.prometheus.client.converter;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public abstract class Result<T extends Data>{
|
public abstract class Result<T>{
|
||||||
String status = null;
|
String status = null;
|
||||||
String resultType = null;
|
String resultType = null;
|
||||||
public String getStatus() {
|
public String getStatus() {
|
||||||
|
@ -0,0 +1,22 @@
|
|||||||
|
package com.bdwise.prometheus.client.converter.am;
|
||||||
|
|
||||||
|
|
||||||
|
public class AlertManagerResultItem {
|
||||||
|
|
||||||
|
private String url;
|
||||||
|
|
||||||
|
public String getUrl() {
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUrl(String url) {
|
||||||
|
this.url = url;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "AlertManagerResultItem [url=" + url + "]";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,29 @@
|
|||||||
|
package com.bdwise.prometheus.client.converter.am;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.bdwise.prometheus.client.converter.Result;
|
||||||
|
|
||||||
|
public class DefaultAlertManagerResult extends Result<AlertManagerResultItem>{
|
||||||
|
List<AlertManagerResultItem> activeAlertmanagers = new ArrayList<AlertManagerResultItem>();
|
||||||
|
List<AlertManagerResultItem> droppedAlertmanagers = new ArrayList<AlertManagerResultItem>();
|
||||||
|
public void addActiveManager(AlertManagerResultItem data) {
|
||||||
|
activeAlertmanagers.add(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addDroppedManager(AlertManagerResultItem data) {
|
||||||
|
droppedAlertmanagers.add(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<AlertManagerResultItem> getResult() {
|
||||||
|
return activeAlertmanagers;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "TargetResultItem [activeAM=" + activeAlertmanagers + ",droppedAM="+droppedAlertmanagers+"]";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,24 @@
|
|||||||
|
package com.bdwise.prometheus.client.converter.label;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.bdwise.prometheus.client.converter.Result;
|
||||||
|
|
||||||
|
public class DefaultLabelResult extends Result<String>{
|
||||||
|
List<String> result = new ArrayList<String>();
|
||||||
|
public void addData(String data) {
|
||||||
|
result.add(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> getResult() {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "DefaultLabelResult [result=" + result + "]";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,24 @@
|
|||||||
|
package com.bdwise.prometheus.client.converter.series;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.bdwise.prometheus.client.converter.Result;
|
||||||
|
|
||||||
|
public class DefaultSeriesResult extends Result<SeriesResultItem>{
|
||||||
|
List<SeriesResultItem> result = new ArrayList<SeriesResultItem>();
|
||||||
|
public void addData(SeriesResultItem data) {
|
||||||
|
result.add(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<SeriesResultItem> getResult() {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "SeriesResultItem [result=" + result + "]";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
package com.bdwise.prometheus.client.converter.series;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
import com.bdwise.prometheus.client.converter.Data;
|
||||||
|
|
||||||
|
public class SeriesResultItem extends HashMap<String, String> implements Data {
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,24 @@
|
|||||||
|
package com.bdwise.prometheus.client.converter.status;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.bdwise.prometheus.client.converter.Result;
|
||||||
|
|
||||||
|
public class DefaultConfigResult extends Result<String>{
|
||||||
|
List<String> result = new ArrayList<String>();
|
||||||
|
public void addData(String data) {
|
||||||
|
result.add(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> getResult() {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "DefaultConfigResult [result=" + result + "]";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,29 @@
|
|||||||
|
package com.bdwise.prometheus.client.converter.target;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.bdwise.prometheus.client.converter.Result;
|
||||||
|
|
||||||
|
public class DefaultTargetResult extends Result<TargetResultItem>{
|
||||||
|
List<TargetResultItem> activeTargets = new ArrayList<TargetResultItem>();
|
||||||
|
List<TargetResultItem> droppedTargets = new ArrayList<TargetResultItem>();
|
||||||
|
public void addActiveTarget(TargetResultItem data) {
|
||||||
|
activeTargets.add(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addDroppedTarget(TargetResultItem data) {
|
||||||
|
droppedTargets.add(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<TargetResultItem> getResult() {
|
||||||
|
return activeTargets;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "TargetResultItem [activeTargets=" + activeTargets + ",droppedTargets="+droppedTargets+"]";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,57 @@
|
|||||||
|
package com.bdwise.prometheus.client.converter.target;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class TargetResultItem {
|
||||||
|
private Map<String, String> discoveredLabels = new HashMap<String,String>();
|
||||||
|
private Map<String, String> label = new HashMap<String,String>();
|
||||||
|
private String scrapeUrl;
|
||||||
|
private String lastError="";
|
||||||
|
private String lastScrape;
|
||||||
|
private String health="UNKNOWN";
|
||||||
|
|
||||||
|
public Map<String, String> getDiscoveredLabels() {
|
||||||
|
return discoveredLabels;
|
||||||
|
}
|
||||||
|
public void setDiscoveredLabels(Map<String, String> discoveredLabels) {
|
||||||
|
this.discoveredLabels = discoveredLabels;
|
||||||
|
}
|
||||||
|
public Map<String, String> getLabel() {
|
||||||
|
return label;
|
||||||
|
}
|
||||||
|
public void setLabel(Map<String, String> label) {
|
||||||
|
this.label = label;
|
||||||
|
}
|
||||||
|
public String getScrapeUrl() {
|
||||||
|
return scrapeUrl;
|
||||||
|
}
|
||||||
|
public void setScrapeUrl(String scrapeUrl) {
|
||||||
|
this.scrapeUrl = scrapeUrl;
|
||||||
|
}
|
||||||
|
public String getLastError() {
|
||||||
|
return lastError;
|
||||||
|
}
|
||||||
|
public void setLastError(String lastError) {
|
||||||
|
this.lastError = lastError;
|
||||||
|
}
|
||||||
|
public String getLastScrape() {
|
||||||
|
return lastScrape;
|
||||||
|
}
|
||||||
|
public void setLastScrape(String lastScrape) {
|
||||||
|
this.lastScrape = lastScrape;
|
||||||
|
}
|
||||||
|
public String getHealth() {
|
||||||
|
return health;
|
||||||
|
}
|
||||||
|
public void setHealth(String health) {
|
||||||
|
this.health = health;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "TargetResultItem [discoveredLabels=" + discoveredLabels + ", label=" + label + ", scrapeUrl="
|
||||||
|
+ scrapeUrl + ", lastError=" + lastError + ", lastScrape=" + lastScrape + ", health=" + health + "]";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -24,4 +24,34 @@ public class UriBuilderTest extends TestCase {
|
|||||||
URI targetUri = iqb.withQuery("irate(received_api_call_total[60s])").build();
|
URI targetUri = iqb.withQuery("irate(received_api_call_total[60s])").build();
|
||||||
System.out.println(targetUri.toURL().toString());
|
System.out.println(targetUri.toURL().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testSeriesMetaQueryBuilder() throws MalformedURLException {
|
||||||
|
SeriesMetaQueryBuilder smqb = QueryBuilderType.SeriesMetadaQuery.newInstance("http://52.192.4.59:30900");
|
||||||
|
URI targetUri = smqb.withSelector("match[]=up&match[]=process_start_time_seconds{job=\"prometheus\"}").build();
|
||||||
|
System.out.println(targetUri.toURL().toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testLabelMetaQueryBuilder() throws MalformedURLException {
|
||||||
|
LabelMetaQueryBuilder lmqb = QueryBuilderType.LabelMetadaQuery.newInstance("http://52.192.4.59:30900");
|
||||||
|
URI targetUri = lmqb.withLabel("pod").build();
|
||||||
|
System.out.println(targetUri.toURL().toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testStatusMetaQueryBuilder() throws MalformedURLException {
|
||||||
|
StatusMetaQueryBuilder smqb = QueryBuilderType.StatusMetadaQuery.newInstance("http://52.192.4.59:30900");
|
||||||
|
URI targetUri = smqb.build();
|
||||||
|
System.out.println(targetUri.toURL().toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testTargetsMetaQueryBuilder() throws MalformedURLException {
|
||||||
|
TargetMetaQueryBuilder tmqb = QueryBuilderType.TargetMetadaQuery.newInstance("http://52.192.4.59:30900");
|
||||||
|
URI targetUri = tmqb.build();
|
||||||
|
System.out.println(targetUri.toURL().toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testAlertManagerMetaQueryBuilder() throws MalformedURLException {
|
||||||
|
AlertManagerMetaQueryBuilder ammqb = QueryBuilderType.AlertManagerMetadaQuery.newInstance("http://52.192.4.59:30900");
|
||||||
|
URI targetUri = ammqb.build();
|
||||||
|
System.out.println(targetUri.toURL().toString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,20 @@
|
|||||||
|
package com.bdwise.prometheus.client.comverter.query;
|
||||||
|
|
||||||
|
import com.bdwise.prometheus.client.converter.ConvertUtil;
|
||||||
|
import com.bdwise.prometheus.client.converter.am.AlertManagerResultItem;
|
||||||
|
import com.bdwise.prometheus.client.converter.am.DefaultAlertManagerResult;
|
||||||
|
|
||||||
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
|
public class AlertManagerResultTest extends TestCase {
|
||||||
|
private String testAlertManagerData="{\"status\":\"success\",\"data\":{\"activeAlertmanagers\":[]}}";
|
||||||
|
|
||||||
|
public void testParser() {
|
||||||
|
DefaultAlertManagerResult result = ConvertUtil.convertAlertManagerResultString(testAlertManagerData);
|
||||||
|
System.out.println("-----" +result.getResult().size());
|
||||||
|
|
||||||
|
for(AlertManagerResultItem data : result.getResult()) {
|
||||||
|
System.out.println("=======>\n" + data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,17 @@
|
|||||||
|
package com.bdwise.prometheus.client.comverter.query;
|
||||||
|
|
||||||
|
import com.bdwise.prometheus.client.converter.ConvertUtil;
|
||||||
|
import com.bdwise.prometheus.client.converter.status.DefaultConfigResult;
|
||||||
|
|
||||||
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
|
public class ConfigResultTest extends TestCase {
|
||||||
|
private String testConfigData="{\"status\":\"success\",\"data\":{\"yaml\":\"global:\\n scrape_interval: 30s\\n scrape_timeout: 10s\\n evaluation_interval: 30s\\nscrape_configs:\\n- job_name: default/person-application-1.5-monitor/0\\n scrape_interval: 10s\\n scrape_timeout: 10s\\n metrics_path: /prometheus\\n scheme: http\\n kubernetes_sd_configs:\\n - api_server: null\\n role: endpoints\\n namespaces:\\n names:\\n - default\\n relabel_configs:\\n - source_labels: [__meta_kubernetes_service_label_run]\\n separator: ;\\n regex: person-application-1.5\\n replacement: $1\\n action: keep\\n - source_labels: [__meta_kubernetes_endpoint_port_name]\\n separator: ;\\n regex: http\\n replacement: $1\\n action: keep\\n - source_labels: [__meta_kubernetes_namespace]\\n separator: ;\\n regex: (.*)\\n target_label: namespace\\n replacement: $1\\n action: replace\\n - source_labels: [__meta_kubernetes_pod_name]\\n separator: ;\\n regex: (.*)\\n target_label: pod\\n replacement: $1\\n action: replace\\n - source_labels: [__meta_kubernetes_service_name]\\n separator: ;\\n regex: (.*)\\n target_label: service\\n replacement: $1\\n action: replace\\n - source_labels: [__meta_kubernetes_service_name]\\n separator: ;\\n regex: (.*)\\n target_label: job\\n replacement: ${1}\\n action: replace\\n - separator: ;\\n regex: (.*)\\n target_label: endpoint\\n replacement: http\\n action: replace\\n\"}}";
|
||||||
|
public void testParser() {
|
||||||
|
DefaultConfigResult result = ConvertUtil.convertConfigResultString(testConfigData);
|
||||||
|
System.out.println("-----" +result.getResult().size());
|
||||||
|
for(String data : result.getResult()) {
|
||||||
|
System.out.println("=======>\n" + data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,17 @@
|
|||||||
|
package com.bdwise.prometheus.client.comverter.query;
|
||||||
|
|
||||||
|
import com.bdwise.prometheus.client.converter.ConvertUtil;
|
||||||
|
import com.bdwise.prometheus.client.converter.label.DefaultLabelResult;
|
||||||
|
|
||||||
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
|
public class LabelResultTest extends TestCase {
|
||||||
|
private String testLabelData="{\"status\":\"success\",\"data\":[\"person-application-1.5-5dcc65c754-7ztnz\",\"person-application-1.5-5dcc65c754-8gb82\",\"person-application-1.5-5dcc65c754-8xh22\"]}";
|
||||||
|
public void testParser() {
|
||||||
|
DefaultLabelResult result = ConvertUtil.convertLabelResultString(testLabelData);
|
||||||
|
System.out.println("-----" +result.getResult().size());
|
||||||
|
for(String data : result.getResult()) {
|
||||||
|
System.out.println("=======>" + data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,18 @@
|
|||||||
|
package com.bdwise.prometheus.client.comverter.query;
|
||||||
|
|
||||||
|
import com.bdwise.prometheus.client.converter.ConvertUtil;
|
||||||
|
import com.bdwise.prometheus.client.converter.Data;
|
||||||
|
import com.bdwise.prometheus.client.converter.series.DefaultSeriesResult;
|
||||||
|
|
||||||
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
|
public class SeriesResultTest extends TestCase {
|
||||||
|
private String testSeriesData="{\"status\":\"success\",\"data\":[{\"__name__\":\"up\",\"endpoint\":\"http\",\"instance\":\"10.244.1.4:19000\",\"job\":\"person-application-1-5\",\"namespace\":\"default\",\"pod\":\"person-application-1.5-5dcc65c754-8xh22\",\"service\":\"person-application-1-5\"},{\"__name__\":\"up\",\"endpoint\":\"http\",\"instance\":\"10.244.2.4:19000\",\"job\":\"person-application-1-5\",\"namespace\":\"default\",\"pod\":\"person-application-1.5-5dcc65c754-8gb82\",\"service\":\"person-application-1-5\"},{\"__name__\":\"up\",\"endpoint\":\"http\",\"instance\":\"10.244.4.4:19000\",\"job\":\"person-application-1-5\",\"namespace\":\"default\",\"pod\":\"person-application-1.5-5dcc65c754-7ztnz\",\"service\":\"person-application-1-5\"}]}";
|
||||||
|
public void testParser() {
|
||||||
|
DefaultSeriesResult result = ConvertUtil.convertSeriesResultString(testSeriesData);
|
||||||
|
System.out.println("-----" +result.getResult().size());
|
||||||
|
for(Data data : result.getResult()) {
|
||||||
|
System.out.println("=======>" + data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
package com.bdwise.prometheus.client.comverter.query;
|
||||||
|
|
||||||
|
import com.bdwise.prometheus.client.converter.ConvertUtil;
|
||||||
|
import com.bdwise.prometheus.client.converter.status.DefaultConfigResult;
|
||||||
|
import com.bdwise.prometheus.client.converter.target.DefaultTargetResult;
|
||||||
|
import com.bdwise.prometheus.client.converter.target.TargetResultItem;
|
||||||
|
|
||||||
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
|
public class TargetResultTest extends TestCase {
|
||||||
|
private String testTargetData="{\"status\":\"success\",\"data\":{\"activeTargets\":[{\"discoveredLabels\":{\"__address__\":\"10.244.2.4:19000\",\"__meta_kubernetes_endpoint_port_name\":\"http\",\"__meta_kubernetes_endpoint_port_protocol\":\"TCP\",\"__meta_kubernetes_endpoint_ready\":\"true\",\"__meta_kubernetes_endpoints_name\":\"person-application-1-5\",\"__meta_kubernetes_namespace\":\"default\",\"__meta_kubernetes_pod_container_name\":\"person-application\",\"__meta_kubernetes_pod_container_port_name\":\"http\",\"__meta_kubernetes_pod_container_port_number\":\"19000\",\"__meta_kubernetes_pod_container_port_protocol\":\"TCP\",\"__meta_kubernetes_pod_host_ip\":\"10.0.0.13\",\"__meta_kubernetes_pod_ip\":\"10.244.2.4\",\"__meta_kubernetes_pod_label_pod_template_hash\":\"1877217310\",\"__meta_kubernetes_pod_label_run\":\"person-application-1.5\",\"__meta_kubernetes_pod_name\":\"person-application-1.5-5dcc65c754-8gb82\",\"__meta_kubernetes_pod_node_name\":\"ip-10-0-0-13\",\"__meta_kubernetes_pod_ready\":\"true\",\"__meta_kubernetes_pod_uid\":\"0e01dd3b-b0f7-11e8-9bc7-0e371c97e2e6\",\"__meta_kubernetes_service_label_run\":\"person-application-1.5\",\"__meta_kubernetes_service_name\":\"person-application-1-5\",\"__metrics_path__\":\"/prometheus\",\"__scheme__\":\"http\",\"job\":\"default/person-application-1.5-monitor/0\"},\"labels\":{\"endpoint\":\"http\",\"instance\":\"10.244.2.4:19000\",\"job\":\"person-application-1-5\",\"namespace\":\"default\",\"pod\":\"person-application-1.5-5dcc65c754-8gb82\",\"service\":\"person-application-1-5\"},\"scrapeUrl\":\"http://10.244.2.4:19000/prometheus\",\"lastError\":\"\",\"lastScrape\":\"2018-09-07T07:44:34.004445574Z\",\"health\":\"up\"},{\"discoveredLabels\":{\"__address__\":\"10.244.4.4:19000\",\"__meta_kubernetes_endpoint_port_name\":\"http\",\"__meta_kubernetes_endpoint_port_protocol\":\"TCP\",\"__meta_kubernetes_endpoint_ready\":\"true\",\"__meta_kubernetes_endpoints_name\":\"person-application-1-5\",\"__meta_kubernetes_namespace\":\"default\",\"__meta_kubernetes_pod_container_name\":\"person-application\",\"__meta_kubernetes_pod_container_port_name\":\"http\",\"__meta_kubernetes_pod_container_port_number\":\"19000\",\"__meta_kubernetes_pod_container_port_protocol\":\"TCP\",\"__meta_kubernetes_pod_host_ip\":\"10.0.0.123\",\"__meta_kubernetes_pod_ip\":\"10.244.4.4\",\"__meta_kubernetes_pod_label_pod_template_hash\":\"1877217310\",\"__meta_kubernetes_pod_label_run\":\"person-application-1.5\",\"__meta_kubernetes_pod_name\":\"person-application-1.5-5dcc65c754-7ztnz\",\"__meta_kubernetes_pod_node_name\":\"ip-10-0-0-123\",\"__meta_kubernetes_pod_ready\":\"true\",\"__meta_kubernetes_pod_uid\":\"0e02c3fe-b0f7-11e8-9bc7-0e371c97e2e6\",\"__meta_kubernetes_service_label_run\":\"person-application-1.5\",\"__meta_kubernetes_service_name\":\"person-application-1-5\",\"__metrics_path__\":\"/prometheus\",\"__scheme__\":\"http\",\"job\":\"default/person-application-1.5-monitor/0\"},\"labels\":{\"endpoint\":\"http\",\"instance\":\"10.244.4.4:19000\",\"job\":\"person-application-1-5\",\"namespace\":\"default\",\"pod\":\"person-application-1.5-5dcc65c754-7ztnz\",\"service\":\"person-application-1-5\"},\"scrapeUrl\":\"http://10.244.4.4:19000/prometheus\",\"lastError\":\"\",\"lastScrape\":\"2018-09-07T07:44:34.287821422Z\",\"health\":\"up\"},{\"discoveredLabels\":{\"__address__\":\"10.244.1.4:19000\",\"__meta_kubernetes_endpoint_port_name\":\"http\",\"__meta_kubernetes_endpoint_port_protocol\":\"TCP\",\"__meta_kubernetes_endpoint_ready\":\"true\",\"__meta_kubernetes_endpoints_name\":\"person-application-1-5\",\"__meta_kubernetes_namespace\":\"default\",\"__meta_kubernetes_pod_container_name\":\"person-application\",\"__meta_kubernetes_pod_container_port_name\":\"http\",\"__meta_kubernetes_pod_container_port_number\":\"19000\",\"__meta_kubernetes_pod_container_port_protocol\":\"TCP\",\"__meta_kubernetes_pod_host_ip\":\"10.0.0.70\",\"__meta_kubernetes_pod_ip\":\"10.244.1.4\",\"__meta_kubernetes_pod_label_pod_template_hash\":\"1877217310\",\"__meta_kubernetes_pod_label_run\":\"person-application-1.5\",\"__meta_kubernetes_pod_name\":\"person-application-1.5-5dcc65c754-8xh22\",\"__meta_kubernetes_pod_node_name\":\"ip-10-0-0-70\",\"__meta_kubernetes_pod_ready\":\"true\",\"__meta_kubernetes_pod_uid\":\"0e02af44-b0f7-11e8-9bc7-0e371c97e2e6\",\"__meta_kubernetes_service_label_run\":\"person-application-1.5\",\"__meta_kubernetes_service_name\":\"person-application-1-5\",\"__metrics_path__\":\"/prometheus\",\"__scheme__\":\"http\",\"job\":\"default/person-application-1.5-monitor/0\"},\"labels\":{\"endpoint\":\"http\",\"instance\":\"10.244.1.4:19000\",\"job\":\"person-application-1-5\",\"namespace\":\"default\",\"pod\":\"person-application-1.5-5dcc65c754-8xh22\",\"service\":\"person-application-1-5\"},\"scrapeUrl\":\"http://10.244.1.4:19000/prometheus\",\"lastError\":\"\",\"lastScrape\":\"2018-09-07T07:44:36.886727015Z\",\"health\":\"up\"}]}}";
|
||||||
|
public void testParser() {
|
||||||
|
DefaultTargetResult result = ConvertUtil.convertTargetResultString(testTargetData);
|
||||||
|
System.out.println("-----" +result.getResult().size());
|
||||||
|
for(TargetResultItem data : result.getResult()) {
|
||||||
|
System.out.println("=======>\n" + data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Binary file not shown.
Binary file not shown.
@ -8,13 +8,21 @@ import org.apache.http.impl.client.HttpClientBuilder;
|
|||||||
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
|
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
|
||||||
import org.springframework.web.client.RestTemplate;
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
|
||||||
|
import com.bdwise.prometheus.client.builder.AlertManagerMetaQueryBuilder;
|
||||||
import com.bdwise.prometheus.client.builder.InstantQueryBuilder;
|
import com.bdwise.prometheus.client.builder.InstantQueryBuilder;
|
||||||
|
import com.bdwise.prometheus.client.builder.LabelMetaQueryBuilder;
|
||||||
import com.bdwise.prometheus.client.builder.QueryBuilderType;
|
import com.bdwise.prometheus.client.builder.QueryBuilderType;
|
||||||
import com.bdwise.prometheus.client.builder.RangeQueryBuilder;
|
import com.bdwise.prometheus.client.builder.RangeQueryBuilder;
|
||||||
|
import com.bdwise.prometheus.client.builder.StatusMetaQueryBuilder;
|
||||||
|
import com.bdwise.prometheus.client.builder.TargetMetaQueryBuilder;
|
||||||
import com.bdwise.prometheus.client.converter.ConvertUtil;
|
import com.bdwise.prometheus.client.converter.ConvertUtil;
|
||||||
|
import com.bdwise.prometheus.client.converter.am.DefaultAlertManagerResult;
|
||||||
|
import com.bdwise.prometheus.client.converter.label.DefaultLabelResult;
|
||||||
import com.bdwise.prometheus.client.converter.query.DefaultQueryResult;
|
import com.bdwise.prometheus.client.converter.query.DefaultQueryResult;
|
||||||
import com.bdwise.prometheus.client.converter.query.MatrixData;
|
import com.bdwise.prometheus.client.converter.query.MatrixData;
|
||||||
import com.bdwise.prometheus.client.converter.query.VectorData;
|
import com.bdwise.prometheus.client.converter.query.VectorData;
|
||||||
|
import com.bdwise.prometheus.client.converter.status.DefaultConfigResult;
|
||||||
|
import com.bdwise.prometheus.client.converter.target.DefaultTargetResult;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
@ -70,6 +78,66 @@ public class PromqlTest extends TestCase {
|
|||||||
DefaultQueryResult<VectorData> result = ConvertUtil.convertQueryResultString(rtVal);
|
DefaultQueryResult<VectorData> result = ConvertUtil.convertQueryResultString(rtVal);
|
||||||
|
|
||||||
|
|
||||||
|
System.out.println(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testSimpleLabel() throws MalformedURLException {
|
||||||
|
LabelMetaQueryBuilder lmqb = QueryBuilderType.LabelMetadaQuery.newInstance(TARGET_SERVER);
|
||||||
|
URI targetUri = lmqb.withLabel("pod").build();
|
||||||
|
System.out.println(targetUri.toURL().toString());
|
||||||
|
|
||||||
|
|
||||||
|
String rtVal = template.getForObject(targetUri, String.class);
|
||||||
|
|
||||||
|
|
||||||
|
DefaultLabelResult result = ConvertUtil.convertLabelResultString(rtVal);
|
||||||
|
|
||||||
|
|
||||||
|
System.out.println(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testSimpleConfig() throws MalformedURLException {
|
||||||
|
StatusMetaQueryBuilder smqb = QueryBuilderType.StatusMetadaQuery.newInstance(TARGET_SERVER);
|
||||||
|
URI targetUri = smqb.build();
|
||||||
|
System.out.println(targetUri.toURL().toString());
|
||||||
|
|
||||||
|
|
||||||
|
String rtVal = template.getForObject(targetUri, String.class);
|
||||||
|
|
||||||
|
|
||||||
|
DefaultConfigResult result = ConvertUtil.convertConfigResultString(rtVal);
|
||||||
|
|
||||||
|
|
||||||
|
System.out.println(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testSimpleTargets() throws MalformedURLException {
|
||||||
|
TargetMetaQueryBuilder tmqb = QueryBuilderType.TargetMetadaQuery.newInstance(TARGET_SERVER);
|
||||||
|
URI targetUri = tmqb.build();
|
||||||
|
System.out.println(targetUri.toURL().toString());
|
||||||
|
|
||||||
|
|
||||||
|
String rtVal = template.getForObject(targetUri, String.class);
|
||||||
|
|
||||||
|
|
||||||
|
DefaultTargetResult result = ConvertUtil.convertTargetResultString(rtVal);
|
||||||
|
|
||||||
|
|
||||||
|
System.out.println(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testSimpleAlertManager() throws MalformedURLException {
|
||||||
|
AlertManagerMetaQueryBuilder ammqb = QueryBuilderType.AlertManagerMetadaQuery.newInstance(TARGET_SERVER);
|
||||||
|
URI targetUri = ammqb.build();
|
||||||
|
System.out.println(targetUri.toURL().toString());
|
||||||
|
|
||||||
|
|
||||||
|
String rtVal = template.getForObject(targetUri, String.class);
|
||||||
|
|
||||||
|
|
||||||
|
DefaultAlertManagerResult result = ConvertUtil.convertAlertManagerResultString(rtVal);
|
||||||
|
|
||||||
|
|
||||||
System.out.println(result);
|
System.out.println(result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user