use of io.mantisrx.shaded.com.fasterxml.jackson.core.JsonProcessingException in project mantis by Netflix.
the class MetricsServer method start.
public void start() {
final Observable<Measurements> measurements = measurements(publishRateInSeconds);
logger.info("Starting metrics server on port: " + port);
server = RxNetty.createHttpServer(port, new RequestHandler<ByteBuf, ServerSentEvent>() {
@Override
public Observable<Void> handle(HttpServerRequest<ByteBuf> request, final HttpServerResponse<ServerSentEvent> response) {
final Map<String, List<String>> queryParameters = request.getQueryParameters();
final List<String> namesToFilter = new LinkedList<>();
logger.info("got query params {}", queryParameters);
if (queryParameters != null && queryParameters.containsKey("name")) {
namesToFilter.addAll(queryParameters.get("name"));
}
Observable<Measurements> filteredObservable = measurements.filter(new Func1<Measurements, Boolean>() {
@Override
public Boolean call(Measurements measurements) {
if (!namesToFilter.isEmpty()) {
// check filters
for (String name : namesToFilter) {
if (name.indexOf('*') != -1) {
// check for ends with
if (name.indexOf('*') == 0 && measurements.getName().endsWith(name.substring(1)))
return true;
// check for starts with
if (name.indexOf('*') > 0 && measurements.getName().startsWith(name.substring(0, name.indexOf('*')))) {
return true;
}
}
if (measurements.getName().equals(name)) {
// filter match
return true;
}
}
// not found in filters
return false;
} else {
// no filters provided
return true;
}
}
});
return filteredObservable.flatMap(new Func1<Measurements, Observable<Void>>() {
@Override
public Observable<Void> call(Measurements metrics) {
response.getHeaders().set("Access-Control-Allow-Origin", "*");
response.getHeaders().set("content-type", "text/event-stream");
ServerSentEvent event = null;
try {
ByteBuf data = response.getAllocator().buffer().writeBytes((mapper.writeValueAsString(metrics)).getBytes());
event = new ServerSentEvent(data);
// event = new ServerSentEvent(null, "data", mapper.writeValueAsString(metrics));
} catch (JsonProcessingException e) {
logger.error("Failed to map metrics to JSON", e);
}
if (event != null) {
response.write(event);
return response.writeStringAndFlush("\n");
}
return null;
}
});
}
}, PipelineConfigurators.<ByteBuf>serveSseConfigurator()).start();
}
use of io.mantisrx.shaded.com.fasterxml.jackson.core.JsonProcessingException in project mantis by Netflix.
the class MantisEnvelopeTest method deserTest.
@Test
public void deserTest() {
String data = "{\"ts\":1571174446676,\"originServer\":\"origin\",\"eventList\":[{\"id\":1,\"data\":\"{\\\"mantisStream\\\":\\\"defaultStream\\\",\\\"matched-clients\\\":[\\\"MantisPushRequestEvents_PushRequestEventSourceJobLocal-1_nj3\\\"],\\\"id\\\":44,\\\"type\\\":\\\"EVENT\\\"}\"}]}";
final ObjectMapper mapper = new ObjectMapper();
ObjectReader mantisEventEnvelopeReader = mapper.readerFor(MantisEventEnvelope.class);
try {
MantisEventEnvelope envelope = mantisEventEnvelopeReader.readValue(data);
System.out.println("Envelope=>" + envelope);
} catch (JsonProcessingException e) {
e.printStackTrace();
fail();
}
}
use of io.mantisrx.shaded.com.fasterxml.jackson.core.JsonProcessingException in project mantis by Netflix.
the class DataDroppedPayloadSetter method setPayload.
protected void setPayload(final long intervalSecs) {
final Collection<Metrics> metrics = MetricsRegistry.getInstance().getMetrics(metricNamePrefix);
long totalDropped = 0L;
long totalOnNext = 0L;
try {
if (metrics != null && !metrics.isEmpty()) {
// logger.info("Got " + metrics.size() + " metrics for DropOperator");
for (Metrics m : metrics) {
final Counter dropped = m.getCounter("" + DropOperator.Counters.dropped);
final Counter onNext = m.getCounter("" + DropOperator.Counters.onNext);
if (dropped != null)
totalDropped += dropped.value();
else
logger.warn("Unexpected to get null dropped counter for metric " + m.getMetricGroupId().id());
if (onNext != null)
totalOnNext += onNext.value();
else
logger.warn("Unexpected to get null onNext counter for metric " + m.getMetricGroupId().id());
}
final StatusPayloads.DataDropCounts dataDrop = new StatusPayloads.DataDropCounts(totalOnNext, totalDropped);
try {
heartbeat.addSingleUsePayload("" + StatusPayloads.Type.IncomingDataDrop, objectMapper.writeValueAsString(dataDrop));
} catch (JsonProcessingException e) {
logger.warn("Error writing json for dataDrop payload: " + e.getMessage());
}
dropCountGauge.set(dataDrop.getDroppedCount());
onNextCountGauge.set(dataDrop.getOnNextCount());
} else
logger.debug("Got no metrics from DropOperator");
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
}
Aggregations