Git Product home page Git Product logo

metrics-library-1's Introduction

CircleCI GitHub release Maven Central wizzie-io

metrics-library

This library allows you to register custom and JVM metrics on java applications. It uses listeners to send this metrics to different backends, by default the metrics-library register the common JVM metrics (heap, gc count, gc time ...).

Properties

Listener class Description Default Type
metric.enable Enable or disable the metric library true boolean
metric.verbose.mode Enable verbose metrics (1min, 5min, 15min ...) false boolean
metric.listeners The listeners that metric library should be use to export metrics ["io.wizzie.metrics.listeners.ConsoleMetricListener"] List
metric.interval The interval to configure when the metric are sent (milliseconds) 60000 Long
application.id Identifier to specific what application is exporting the metrics Depends of the listener String
metric.databag Static data to add to all exported metrics. Map[String, Object]

Listeners

The listeners are the process that listen the reported metrics and do something with them. You can have multiple listeners at the same time.

Listener class Description
io.wizzie.metrics.listeners.ConsoleMetricListener Log the metrics ussing log4j-slf4j
io.wizzie.metrics.listeners.KafkaMetricListener Send metrics to Kafka topic

KafkaMetricListener

Properties

Listener class Description Default Type
metric.kafka.topic     Topic to send metrics                             __metrics String
bootstrap.servers Kafka brokers (ip111:9092,ip222:9092) String
application.id Identifier to specific what application is exporting the metrics Thread.currentThread().getName() String 

Work with library

To work with this library you need to add this dependency to your pom.xml:

<dependency>
    <groupId>io.wizzie.metrics</groupId>
    <artifactId>metrics-library</artifactId>
    <version>0.0.4</version>
</dependency>

Later you can init the MetricsManager class and register your metrics:

  Map<String, Object> config = new HashMap<>();

  config.put(METRIC_ENABLE, true);
  config.put(METRIC_INTERVAL, 2000);
  config.put(APPLICATION_ID, "testing-metric-manager");
  config.put(METRIC_LISTENERS, Collections.singletonList("io.wizzie.metrics.listeners.ConsoleMetricListener"));

  MetricsManager metricsManager = new MetricsManager(config);
  
  Counter myCounter = new Counter();
  Timer myTimer = new Timer();
  
  metricsManager.registerMetric("myCounterMetric", myCounter);
  metricsManager.registerMetric("myTimerMetric", myTimer);
  
  metricsManager.start();
  
  // Now you can use the metric instances.

  myCounter.inc();
  myCounter.dec();
  myCounter.inc(10);
  
  myTimer.update(1, TimeUnit.SECONDS);

Custom Listeners

You can made new listeners to do this you need to implement the MetricListener Class. On this class you receive the metric on the method void updateMetric(String metricName, Object metricValue);

metrics-library-1's People

Contributors

andresgomezfrr avatar pablocasares avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.