private KafkaReporter(MetricRegistry registry, String name, TimeUnit rateUnit, TimeUnit durationUnit, boolean showSamples, MetricFilter filter, String topic, ProducerConfig config, String prefix, String hostName, String ip) { super(registry, name, filter, rateUnit, durationUnit); this.topic = topic; this.config = config; this.prefix = prefix; this.hostName = hostName; this.ip = ip; this.mapper = new ObjectMapper().registerModule(new MetricsModule(rateUnit, durationUnit, showSamples)); producer = new Producer<String, String>(config); kafkaExecutor = Executors .newSingleThreadExecutor(new ThreadFactoryBuilder() .setNameFormat("kafka-producer-%d").build()); }
public POMObjectMapper(JsonFactory fact) { super(fact); this.registerModule(new TolerantHealthTimeModule()); this.registerModule(new MetricsModule(TimeUnit.SECONDS, TimeUnit.MILLISECONDS, false)); //ASU CHANGE this.registerModule(new HealthCheckModule()); // this.registerModule(new ViewDefDefModule()); // the following config could be in its own Jackson Module ("VPRModule") if this list gets unwieldy or we want to // externalize the VPR's JSON serialization configuration more or not have dependencies on 3rd party libs. No need right now, though. this.setSerializationInclusion(JsonInclude.Include.NON_NULL); this.enable(SerializationFeature.WRITE_ENUMS_USING_TO_STRING); this.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); /* this.addMixInAnnotations(VistaUserDetails.class, VistaUserDetailsJacksonAnnotations.class); this.addMixInAnnotations(UserDetails.class, UserDetailsJacksonAnnotations.class); this.addMixInAnnotations(GrantedAuthority.class, GrantedAuthorityJacksonAnnotations.class); */ }
public POMObjectMapper(JsonFactory fact) { super(fact); this.registerModule(new TolerantHealthTimeModule()); this.registerModule(new MetricsModule(TimeUnit.SECONDS, TimeUnit.MILLISECONDS, false)); this.registerModule(new HealthCheckModule()); // this.registerModule(new ViewDefDefModule()); // the following config could be in its own Jackson Module ("VPRModule") if this list gets unwieldy or we want to // externalize the VPR's JSON serialization configuration more or not have dependencies on 3rd party libs. No need right now, though. this.setSerializationInclusion(JsonInclude.Include.NON_NULL); this.enable(SerializationFeature.WRITE_ENUMS_USING_TO_STRING); this.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); this.addMixInAnnotations(VistaUserDetails.class, VistaUserDetailsJacksonAnnotations.class); this.addMixInAnnotations(UserDetails.class, UserDetailsJacksonAnnotations.class); this.addMixInAnnotations(GrantedAuthority.class, GrantedAuthorityJacksonAnnotations.class); }
public POMXmlMapper() { JacksonXmlModule xmlModule = new JacksonXmlModule(); xmlModule.setDefaultUseWrapper(false); registerModule(xmlModule); // registerModule(new JaxbAnnotationModule()); registerModule(new HealthTimeModule()); registerModule(new MetricsModule(TimeUnit.SECONDS, TimeUnit.MILLISECONDS, false)); configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false); configure(JsonGenerator.Feature.AUTO_CLOSE_TARGET, false); setSerializationInclusion(JsonInclude.Include.NON_NULL); // setAnnotationIntrospector(new JaxbAnnotationIntrospector(TypeFactory.defaultInstance())); addMixInAnnotations(IPOMObject.class, POMObjectJacksonXmlAnnotations.class); }
private KafkaReporter(MetricRegistry registry, String name, MetricFilter filter, TimeUnit rateUnit, TimeUnit durationUnit, String kafkaTopic, Properties kafkaProperties) { super(registry, name, filter, rateUnit, durationUnit); this.registry = registry; this.converter = new JsonToAvroConverter(); mapper = new ObjectMapper().registerModule(new MetricsModule(rateUnit, durationUnit, false)); this.kafkaTopic = kafkaTopic; kafkaProducer = new KafkaProducer<String, IndexedRecord>(kafkaProperties); }
@Override public void onActivate( Application application ) throws ActivationException { application.plugin( JSON.class ).mapper() .registerModule( new MetricsModule( SECONDS, MILLISECONDS, true ) ) .registerModule( new HealthCheckModule() ); MetricRegistry metrics = new MetricRegistry(); HealthCheckRegistry healthChecks = new HealthCheckRegistry(); registerMetrics( application, metrics ); registerMetricsReporters( application, metrics ); registerHealthChecks( application, healthChecks ); api = new Metrics( metrics, healthChecks ); }
public void serveAdmin() { MetricsModule metricsModule = new MetricsModule(TimeUnit.SECONDS, TimeUnit.MILLISECONDS, true); ObjectMapper metricsMapper = new ObjectMapper().registerModule(metricsModule); ObjectMapper healthMapper = new ObjectMapper(); /* '/info' -> should expose version number, git commit number, etc '/metrics' -> should return the metrics reporters in JSON format '/health' -> should expose a summary of downstream health checks '/ping' -> should respond with a 200-OK status code and the text 'PONG' '/ready' -> should expose a Kubernetes or ELB specific healthcheck for liveliness '/restart' -> restart service (should be restricted to approved devs / tooling) '/killkillkill' -> shutdown service (should be restricted to approved devs / tooling)
*/
addRoute("/info", AdminHandlers.infoHandler(), HttpMethod.GET); addRoute( "/metrics", AdminHandlers.metricsHandler(metricRegistry, metricsMapper), HttpMethod.GET); addRoute( "/health", AdminHandlers.healthCheckHandler(healthCheckRegistry, healthMapper), HttpMethod.GET); addRoute("/ping", AdminHandlers.pingHandler(), HttpMethod.GET); addRoute("/ready", AdminHandlers.readyHandler(), HttpMethod.GET); addRoute("/restart", AdminHandlers.restartHandler(this), HttpMethod.GET); addRoute("/killkillkill", AdminHandlers.killHandler(this), HttpMethod.GET);
addRoute("/gc", AdminHandlers.pingHandler(), HttpMethod.GET); }
```
@Override protected void execute() { IntentMetricsService service = get(IntentMetricsService.class); if (outputJson()) { ObjectMapper mapper = new ObjectMapper() .registerModule(new MetricsModule(TimeUnit.SECONDS, TimeUnit.MILLISECONDS, false)); ObjectNode result = mapper.createObjectNode(); result = json(mapper, result, "intentSubmitted", service.intentSubmittedEventMetric()); result = json(mapper, result, "intentInstalled", service.intentInstalledEventMetric()); result = json(mapper, result, "intentFailed", service.intentFailedEventMetric()); result = json(mapper, result, "intentWithdrawRequested", service.intentWithdrawRequestedEventMetric()); result = json(mapper, result, "intentWithdrawn", service.intentWithdrawnEventMetric()); result = json(mapper, result, "intentPurged", service.intentPurgedEventMetric()); print("%s", result); } else { printEventMetric("Submitted", service.intentSubmittedEventMetric()); printEventMetric("Installed", service.intentInstalledEventMetric()); printEventMetric("Failed", service.intentFailedEventMetric()); printEventMetric("Withdraw Requested", service.intentWithdrawRequestedEventMetric()); printEventMetric("Withdrawn", service.intentWithdrawnEventMetric()); printEventMetric("Purged", service.intentPurgedEventMetric()); } }
@Override protected void execute() { TopologyMetricsService service = get(TopologyMetricsService.class); if (outputJson()) { ObjectMapper mapper = new ObjectMapper() .registerModule(new MetricsModule(TimeUnit.SECONDS, TimeUnit.MILLISECONDS, false)); ObjectNode result = mapper.createObjectNode(); result = json(mapper, result, "topologyDeviceEvent", service.topologyDeviceEventMetric()); result = json(mapper, result, "topologyHostEvent", service.topologyHostEventMetric()); result = json(mapper, result, "topologyLinkEvent", service.topologyLinkEventMetric()); result = json(mapper, result, "topologyGraphEvent", service.topologyGraphEventMetric()); result = json(mapper, result, "topologyGraphReasonsEvent", service.topologyGraphReasonsEventMetric()); print("%s", result); } else { printEventMetric("Device", service.topologyDeviceEventMetric()); printEventMetric("Host", service.topologyHostEventMetric()); printEventMetric("Link", service.topologyLinkEventMetric()); printEventMetric("Graph", service.topologyGraphEventMetric()); printEventMetric("Graph Reasons", service.topologyGraphReasonsEventMetric()); } }
private String getApplictionMetrics() throws JsonProcessingException { ObjectMapper mapper = new ObjectMapper(); mapper.registerModule( new MetricsModule( TimeUnit.SECONDS, TimeUnit.MILLISECONDS, false)); return mapper.writeValueAsString(metricRegistry); }
public SystemController(Service spark, GraknConfig config, SystemKeyspace systemKeyspace, GraknEngineStatus graknEngineStatus, MetricRegistry metricRegistry) { this.systemKeyspace = systemKeyspace; this.config = config; this.graknEngineStatus = graknEngineStatus; this.metricRegistry = metricRegistry; DropwizardExports prometheusMetricWrapper = new DropwizardExports(metricRegistry); this.prometheusRegistry = new CollectorRegistry(); prometheusRegistry.register(prometheusMetricWrapper); spark.get(REST.WebPath.ROOT, this::getRoot); spark.get(REST.WebPath.KB, (req, res) -> getKeyspaces(res)); spark.get(REST.WebPath.KB_KEYSPACE, this::getKeyspace); spark.put(REST.WebPath.KB_KEYSPACE, this::putKeyspace); spark.delete(REST.WebPath.KB_KEYSPACE, this::deleteKeyspace); spark.get(REST.WebPath.METRICS, this::getMetrics); spark.get(REST.WebPath.STATUS, (req, res) -> getStatus()); spark.get(REST.WebPath.VERSION, (req, res) -> getVersion()); final TimeUnit rateUnit = TimeUnit.SECONDS; final TimeUnit durationUnit = TimeUnit.SECONDS; final boolean showSamples = false; MetricFilter filter = MetricFilter.ALL; this.mapper = new ObjectMapper().registerModule( new MetricsModule(rateUnit, durationUnit, showSamples, filter)); }
@Override public void init(ServletConfig servletConfig) throws ServletException { super.init(servletConfig); boolean disableAuthorization = Boolean.TRUE.toString().equalsIgnoreCase(servletConfig.getInitParameter(DISABLE_AUTHORIZATION_INIT_PARAM)); if (!disableAuthorization) { String credentials = null; String username = servletConfig.getInitParameter(USERNAME_INIT_PARAM); String password = servletConfig.getInitParameter(PASSWORD_INIT_PARAM); if (StringUtils.isNotBlank(username) && StringUtils.isNotBlank(password)) { credentials = username.trim() + ":" + password.trim(); } else { credentials = DEFAULT_CREDENTIALS; } this.encodedCredentials = BaseEncoding.base64().encode(credentials.getBytes()); } this.objectMapper = new ObjectMapper() .registerModule(new MetricsModule(TimeUnit.SECONDS, TimeUnit.MICROSECONDS, false)) .registerModule(new HealthCheckModule()) .setSerializationInclusion(JsonInclude.Include.NON_NULL) .setTimeZone(TimeZone.getDefault()) .setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z")); this.graphiteMetricFormatter = new GraphiteMetricFormatter(TimeUnit.SECONDS, TimeUnit.MICROSECONDS); try { this.threadDumpGenerator = new ThreadDump(ManagementFactory.getThreadMXBean()); } catch (NoClassDefFoundError ignore) { } ServletContext servletContext = servletConfig.getServletContext(); String servletSpecVersion = servletContext.getMajorVersion() + "." + servletContext.getMinorVersion(); this.serverInfo = ServerInfo.create(servletContext.getServerInfo(), servletSpecVersion); }
private AmqpReporter(Builder builder) { super(builder.registry, "amqp-reporter", builder.filter, builder.rateUnit, builder.durationUnit); this.routingKey = builder.routingKey; this.exchangeName = builder.exchangeName; Assert.hasText(this.exchangeName, "exchangeName is null or empty"); this.exchangeFactory = builder.exchangeFactory; this.messagePropertiesCallback = builder.messagePropertiesCallback; this.connectionFactoryProvider = builder.connectionFactoryProvider; Assert.notNull(this.connectionFactoryProvider, "connectionFactoryProvider can't be null"); objectMapper.registerModules(new HealthCheckModule(), new MetricsModule(builder.rateUnit, builder.durationUnit, false /* if enable histogram data will be serialized */)); }
@Override protected void doStart() throws Exception { if (metricsRegistry == null) { Registry camelRegistry = getCamelContext().getRegistry(); metricsRegistry = camelRegistry.lookupByNameAndType(MetricsComponent.METRIC_REGISTRY_NAME, MetricRegistry.class); // create a new metricsRegistry by default if (metricsRegistry == null) { metricsRegistry = new MetricRegistry(); } } if (useJmx) { ManagementAgent agent = getCamelContext().getManagementStrategy().getManagementAgent(); if (agent != null) { MBeanServer server = agent.getMBeanServer(); if (server != null) { reporter = JmxReporter.forRegistry(metricsRegistry).registerWith(server).inDomain(jmxDomain).build(); reporter.start(); } } else { throw new IllegalStateException("CamelContext has not enabled JMX"); } } // json mapper this.mapper = new ObjectMapper().registerModule(new MetricsModule(getRateUnit(), getDurationUnit(), false)); if (getRateUnit() == TimeUnit.SECONDS && getDurationUnit() == TimeUnit.SECONDS) { // they both use same units so reuse this.secondsMapper = this.mapper; } else { this.secondsMapper = new ObjectMapper().registerModule(new MetricsModule(TimeUnit.SECONDS, TimeUnit.SECONDS, false)); } }
/** * New instance, which will report on the supplied metrics. * * @param registry * the metrics registry to provide metrics from */ public MetricsServlet(MetricRegistry registry) { super(LOGGER, MetricsServlet.class); this.registry = registry; getMapper().registerModule(new MetricsModule(TimeUnit.SECONDS, TimeUnit.SECONDS, false)); }
public static ObjectMapper create(boolean indent) { ObjectMapper objectMapper = new ObjectMapper(); // This will cause the objectmapper to not close the underlying output stream objectMapper.configure(JsonGenerator.Feature.AUTO_CLOSE_TARGET, false); objectMapper.configure(JsonParser.Feature.AUTO_CLOSE_SOURCE, false); objectMapper.registerModule(new MetricsModule(TimeUnit.SECONDS, TimeUnit.SECONDS, false, MetricFilter.ALL)); SimpleModule module = new SimpleModule(); module.addSerializer(ExtendedMeter.class, new ExtendedMeterSerializer(TimeUnit.SECONDS)); module.addSerializer(BigDecimal.class, new ToStringSerializer()); objectMapper.registerModule(module); if (indent) { objectMapper.enable(SerializationFeature.INDENT_OUTPUT); } return objectMapper; }
public JsonFileMetricsReporter(MetricRegistry registry, KylinConfig conf) { this.metricRegistry = registry; this.jsonWriter = new ObjectMapper() .registerModule(new MetricsModule(TimeUnit.MILLISECONDS, TimeUnit.MILLISECONDS, false)) .writerWithDefaultPrettyPrinter(); executorService = Executors.newSingleThreadScheduledExecutor(); this.conf = conf; frequency = KylinConfig.getInstanceFromEnv().getMetricsReporterFrequency(); pathString = KylinConfig.getInstanceFromEnv().getMetricsFileLocation(); path = new Path(pathString); }
public List<ProducerRecord<?,?>> serialize(SortedMap<String, Gauge> gauges, SortedMap<String, Counter> counters, SortedMap<String, Histogram> histograms, SortedMap<String, Meter> meters, SortedMap<String, Timer> timers, String topic, Date timestamp, TimeUnit rateUnit, TimeUnit durationUnit) throws RuntimeException { try { final StringWriter messageBody = new StringWriter(); final ObjectMapper mapper = new ObjectMapper() .disable(SerializationFeature.INDENT_OUTPUT) .registerModule(new MetricsModule(rateUnit, durationUnit, false)); final JsonGenerator generator = mapper .getFactory() .createGenerator(messageBody); List<ProducerRecord<?,?>> messages = new ArrayList<ProducerRecord<?,?>>(); addMetricMessages(messages, gauges, topic, timestamp, generator, messageBody); addMetricMessages(messages, counters, topic, timestamp, generator, messageBody); addMetricMessages(messages, histograms, topic, timestamp, generator, messageBody); addMetricMessages(messages, meters, topic, timestamp, generator, messageBody); addMetricMessages(messages, timers, topic, timestamp, generator, messageBody); return messages; } catch (java.io.IOException e) { throw new RuntimeException(e.getMessage(), e); } }
public SplunkReporter(Builder builder, Service splunk) { super(builder.registry, builder.prefix, builder.filter, builder.rateUnit, builder.durationUnit); receiver = splunk.getReceiver(); this.showSamples = builder.showSamples; splunkArgs.put("source", builder.source); splunkArgs.put("sourcetype", builder.sourcetype); this.index = builder.index; this.extraAttributes = builder.extraAttributes; mapper = new ObjectMapper().registerModule(new MetricsModule(builder.rateUnit, builder.durationUnit, this.showSamples)); }
public MetricsContent(String name, MetricRegistry metricsRegistry) { super(name); this.registry = metricsRegistry; objectMapper = new ObjectMapper(); objectMapper.registerModule(new MetricsModule(TimeUnit.MINUTES, TimeUnit.SECONDS, true)); objectMapper.registerModule(new HealthCheckModule()); objectMapper.enable(SerializationFeature.INDENT_OUTPUT); }
public ObjectMapperProvider(){ ObjectMapper mapper = new ObjectMapper(); mapper.registerModule(new OpenscoringModule()); mapper.registerModule(new MetricsModule(TimeUnit.SECONDS, TimeUnit.SECONDS, false)); mapper.enable(SerializationFeature.INDENT_OUTPUT); mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); setMapper(mapper); }
public BeyondJHazelcastMetricMonitoringService() { this.mapper = new ObjectMapper().registerModule(new MetricsModule(rateUnit, durationUnit, showSamples, filter)); }
public BeyondJConsulMetricMonitoringService() { this.mapper = new ObjectMapper().registerModule(new MetricsModule(rateUnit, durationUnit, showSamples, filter)); }
@Bean public ObjectMapper objectMapper() { final ObjectMapper mapper = new ObjectMapper(); mapper.registerModule(new MetricsModule(TimeUnit.SECONDS, TimeUnit.MILLISECONDS, false)); return mapper; }
public void register(){ LOG.info("MetricsController.Register() called"); objectMapper.registerModules(new MetricsModule(TimeUnit.SECONDS, TimeUnit.SECONDS, false)); webManager.registerController("/octopus-build-trigger/metrics.html", this); }
@VisibleForTesting public String dumpJson() throws Exception { ObjectMapper jsonMapper = new ObjectMapper() .registerModule(new MetricsModule(TimeUnit.MILLISECONDS, TimeUnit.MILLISECONDS, false)); return jsonMapper.writerWithDefaultPrettyPrinter().writeValueAsString(metricRegistry); }
private ObjectMapper createMetricsJSONMapper() { final TimeUnit rateUnit = parseTimeUnit(RATE_UNIT, TimeUnit.SECONDS); final TimeUnit durationUnit = parseTimeUnit(DURATION_UNIT, TimeUnit.SECONDS); return new ObjectMapper().registerModule(new MetricsModule(rateUnit, durationUnit, false)); }
/** * Serialize a MetricsObjectResource into JSON. For each kind of Metric, * his serializes common ONOS defined fields like name and * then calls the Metrics serializer to make the JSON string * for the actual Metric. * * @param metrics resource for all ONOS Metrics * @param jsonGenerator generator to use for the JSON output * @param serializerProvider unused, needed for Override * @throws IOException if any of the JSON serializations fail */ @Override @SuppressWarnings("rawtypes") public void serialize(final MetricsObjectResource metrics, final JsonGenerator jsonGenerator, final SerializerProvider serializerProvider) throws IOException { final ObjectMapper mapper = new ObjectMapper().registerModule( new MetricsModule(TimeUnit.SECONDS, TimeUnit.MILLISECONDS, false)); jsonGenerator.writeStartObject(); // serialize Timers jsonGenerator.writeArrayFieldStart("timers"); for (final MetricsObjectResource.TimerObjectResource timer : metrics.getTimers()) { final String timerJSON = mapper.writeValueAsString(timer.getTimer()); serializeItem(jsonGenerator, "timer", timerJSON, timer); } jsonGenerator.writeEndArray(); // Serialize Gauges jsonGenerator.writeArrayFieldStart("gauges"); for (final MetricsObjectResource.GaugeObjectResource gauge : metrics.getGauges()) { final String gaugeJSON = mapper.writeValueAsString(gauge.getGauge()); serializeItem(jsonGenerator, "gauge", gaugeJSON, gauge); } jsonGenerator.writeEndArray(); // Serialize Counters jsonGenerator.writeArrayFieldStart("counters"); for (final MetricsObjectResource.CounterObjectResource counter : metrics.getCounters()) { final String counterJSON = mapper.writeValueAsString(counter.getCounter()); serializeItem(jsonGenerator, "counter", counterJSON, counter); } jsonGenerator.writeEndArray(); // Serialize Meters jsonGenerator.writeArrayFieldStart("meters"); for (final MetricsObjectResource.MeterObjectResource meter : metrics.getMeters()) { final String meterJSON = mapper.writeValueAsString(meter.getMeter()); serializeItem(jsonGenerator, "meter", meterJSON, meter); } jsonGenerator.writeEndArray(); // Serialize Histograms jsonGenerator.writeArrayFieldStart("histograms"); for (final MetricsObjectResource.HistogramObjectResource histogram : metrics.getHistograms()) { final String histogramJSON = mapper.writeValueAsString(histogram.getHistogram()); serializeItem(jsonGenerator, "histogram", histogramJSON, histogram); } jsonGenerator.writeEndArray(); jsonGenerator.writeEndObject(); }
/** * Default constructor. */ public Sampler() { mapper = new ObjectMapper(); mapper.registerModule(new MetricsModule(RATE_UNIT, DURATION_UNIT, false)); }
/** * Instantiates a reporter instance sending {@link Metric metrics} to kafka topic * @param registry * @param name * @param rateUnit * @param durationUnit * @param filter * @param topicId * @param kafkaProducerConfig */ private KafkaReporter(MetricRegistry registry, String name, TimeUnit rateUnit, TimeUnit durationUnit, MetricFilter filter, String topicId, ProducerConfig kafkaProducerConfig) { super(registry, name, filter, rateUnit, durationUnit); this.registry = registry; this.topicId = topicId; this.kafkaProducer = new Producer<>(kafkaProducerConfig); this.jsonMapper = new ObjectMapper().registerModule(new MetricsModule(rateUnit, durationUnit, false, filter)); }