use of com.twitter.heron.statemgr.localfs.LocalFileSystemStateManager in project heron by twitter.
the class MetricsCacheManagerHttpServer method main.
/**
* manual test for local mode topology, for debug
* How to run:
* in the [source root directory], run bazel test,
* bazel run heron/metricscachemgr/src/java:metricscache-queryclient-unshaded -- \
* <topology_name> <component_name> <metrics_name>
* Example:
* 1. run the example topology,
* ~/bin/heron submit local ~/.heron/examples/heron-examples.jar \
* com.twitter.heron.examples.ExclamationTopology ExclamationTopology \
* --deploy-deactivated --verbose
* 2. in the [source root directory],
* bazel run heron/metricscachemgr/src/java:metricscache-queryclient-unshaded -- \
* ExclamationTopology exclaim1 \
* __emit-count __execute-count __fail-count __ack-count __complete-latency __execute-latency \
* __process-latency __jvm-uptime-secs __jvm-process-cpu-load __jvm-memory-used-mb \
* __jvm-memory-mb-total __jvm-gc-collection-time-ms __server/__time_spent_back_pressure_initiated \
* __time_spent_back_pressure_by_compid
*/
public static void main(String[] args) throws ExecutionException, InterruptedException, IOException {
if (args.length < 3) {
System.out.println("Usage: java MetricsQuery <topology_name> <component_name> <metrics_name>");
} else {
System.out.println("topology: " + args[0] + "; component: " + args[1]);
}
Config config = Config.newBuilder().put(Key.STATEMGR_ROOT_PATH, System.getProperty("user.home") + "/.herondata/repository/state/local").build();
LocalFileSystemStateManager stateManager = new LocalFileSystemStateManager();
stateManager.initialize(config);
TopologyMaster.MetricsCacheLocation location = stateManager.getMetricsCacheLocation(null, args[0]).get();
if (location == null || !location.isInitialized()) {
System.out.println("MetricsCacheMgr is not ready");
return;
}
// construct metric cache stat url
String url = "http://" + location.getHost() + ":" + location.getStatsPort() + MetricsCacheManagerHttpServer.PATH_STATS;
// construct query payload
byte[] requestData = TopologyMaster.MetricRequest.newBuilder().setComponentName(args[1]).setMinutely(true).setInterval(-1).addAllMetric(Arrays.asList(Arrays.copyOfRange(args, 2, args.length))).build().toByteArray();
// http communication
HttpURLConnection con = NetworkUtils.getHttpConnection(url);
NetworkUtils.sendHttpPostRequest(con, "X", requestData);
byte[] responseData = NetworkUtils.readHttpResponse(con);
// parse response data
TopologyMaster.MetricResponse response = TopologyMaster.MetricResponse.parseFrom(responseData);
System.out.println(response.toString());
}
Aggregations