use of backtype.storm.generated.Nimbus.Iface in project jstorm by alibaba.
the class JStormUtils method getMetrics.
/**
* Get Topology Metrics
*
* @param topologyName topology name
* @param metricType, please refer to MetaType, default to MetaType.TASK.getT()
* @param window, please refer to AsmWindow, default to AsmWindow.M1_WINDOW
* @return
*/
public static Map<String, Double> getMetrics(Map conf, String topologyName, MetaType metricType, Integer window) {
NimbusClientWrapper nimbusClient = null;
Iface client = null;
Map<String, Double> summary = new HashMap<>();
try {
nimbusClient = new NimbusClientWrapper();
nimbusClient.init(conf);
client = nimbusClient.getClient();
String topologyId = client.getTopologyId(topologyName);
if (metricType == null) {
metricType = MetaType.TASK;
}
List<MetricInfo> allTaskMetrics = client.getMetrics(topologyId, metricType.getT());
if (allTaskMetrics == null) {
throw new RuntimeException("Failed to get metrics");
}
if (window == null || !AsmWindow.TIME_WINDOWS.contains(window)) {
window = AsmWindow.M1_WINDOW;
}
for (MetricInfo taskMetrics : allTaskMetrics) {
Map<String, Map<Integer, MetricSnapshot>> metrics = taskMetrics.get_metrics();
if (metrics == null) {
System.out.println("Failed to get task metrics");
continue;
}
for (Entry<String, Map<Integer, MetricSnapshot>> entry : metrics.entrySet()) {
String key = entry.getKey();
MetricSnapshot metric = entry.getValue().get(window);
if (metric == null) {
throw new RuntimeException("Failed to get one minute metrics of " + key);
}
if (metric.get_metricType() == MetricType.COUNTER.getT()) {
summary.put(key, (double) metric.get_longValue());
} else if (metric.get_metricType() == MetricType.GAUGE.getT()) {
summary.put(key, metric.get_doubleValue());
} else {
summary.put(key, metric.get_mean());
}
}
}
return summary;
} catch (Exception e) {
throw new RuntimeException(e);
} finally {
if (client != null) {
nimbusClient.cleanup();
}
}
}
use of backtype.storm.generated.Nimbus.Iface in project jstorm by alibaba.
the class NimbusServer method initThrift.
@SuppressWarnings("rawtypes")
private void initThrift(Map conf) throws TTransportException {
Integer thrift_port = JStormUtils.parseInt(conf.get(Config.NIMBUS_THRIFT_PORT));
TNonblockingServerSocket socket = new TNonblockingServerSocket(thrift_port);
Integer maxReadBufSize = JStormUtils.parseInt(conf.get(Config.NIMBUS_THRIFT_MAX_BUFFER_SIZE));
THsHaServer.Args args = new THsHaServer.Args(socket);
args.workerThreads(ServiceHandler.THREAD_NUM);
args.protocolFactory(new TBinaryProtocol.Factory(false, true, maxReadBufSize, -1));
args.processor(new Nimbus.Processor<Iface>(serviceHandler));
args.maxReadBufferBytes = maxReadBufSize;
thriftServer = new THsHaServer(args);
LOG.info("Successfully started nimbus: started Thrift server...");
thriftServer.serve();
}
Aggregations