Skip to content

Commit

Permalink
Merge branch 'metric-api' into traverser_apis
Browse files Browse the repository at this point in the history
  • Loading branch information
SunnyBoy-WYH committed Dec 11, 2023
2 parents cdd4cce + 5e369f7 commit afe81aa
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package org.apache.hugegraph.api.metrics;

import java.util.HashMap;
import java.util.Map;

import org.apache.hugegraph.util.CommonUtil;
Expand All @@ -27,6 +28,8 @@

public class MetricsAPI extends API {

public static final String STATISTICS_PATH = "/statistics";

public MetricsAPI(RestClient client) {
super(client);
this.path(this.type());
Expand Down Expand Up @@ -65,12 +68,39 @@ public Map<String, Object> backend(String graph) {

@SuppressWarnings("unchecked")
public Map<String, Map<String, Object>> all() {
Map<String,Object> params = new HashMap<>();
params.put("type", "json");
RestResult result = this.client.get(this.path(), params);
Map<?, ?> map = result.readObject(Map.class);
CommonUtil.checkMapClass(map, String.class, Map.class);
for (Object mapValue : map.values()) {
CommonUtil.checkMapClass(mapValue, String.class, Object.class);
}
return (Map<String, Map<String, Object>>) map;
}

@SuppressWarnings("unchecked")
public String allWithPromFormat() {
RestResult result = this.client.get(this.path());
return result.content();
}

public Map<String, Map<String, Object>> statistics() {
Map<String,Object> params = new HashMap<>();
params.put("type", "json");
RestResult result = this.client.get(this.path() + STATISTICS_PATH, params);
Map<?, ?> map = result.readObject(Map.class);
CommonUtil.checkMapClass(map, String.class, Map.class);
for (Object mapValue : map.values()) {
CommonUtil.checkMapClass(mapValue, String.class, Object.class);
}

return (Map<String, Map<String, Object>>) map;
}

@SuppressWarnings("unchecked")
public String statisticsWithPromFormat() {
RestResult result = this.client.get(this.path() + STATISTICS_PATH);
return result.content();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,16 @@ public Map<String, Map<String, Object>> system() {
public Map<String, Map<String, Object>> all() {
return this.metricsAPI.all();
}

public String allWithPromFormat() {
return this.metricsAPI.allWithPromFormat();
}

public Map<String, Map<String, Object>> statistics() {
return this.metricsAPI.statistics();
}

public String statisticsWithPromFormat() {
return this.metricsAPI.statisticsWithPromFormat();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,17 @@ public void testAllMetrics() {
Assert.assertEquals(ImmutableSet.of("gauges", "counters", "histograms",
"meters", "timers"),
results.keySet());
// prom format
String resultsProm = metrics().allWithPromFormat();
Assert.assertContains("# HELP hugegraph_info", resultsProm);
}

@Test
public void testStatisticsMetrics() {
Map<String, Map<String, Object>> results = metrics().statistics();
Assert.assertNotNull(results);
// prom format
String resultsProm = metrics().statisticsWithPromFormat();
Assert.assertContains("# HELP hugegraph_info", resultsProm);
}
}

0 comments on commit afe81aa

Please sign in to comment.