Coder Social home page Coder Social logo

sinopower / dropwizard-metrics-newrelic Goto Github PK

View Code? Open in Web Editor NEW

This project forked from newrelic/dropwizard-metrics-newrelic

0.0 1.0 0.0 152 KB

Implementation of a DropWizard metrics Reporter that sends data as dimensional metrics to New Relic

License: Apache License 2.0

Kotlin 5.53% Shell 0.41% Java 94.06%

dropwizard-metrics-newrelic's Introduction

New Relic Dropwizard Reporter

A Dropwizard metrics reporter for sending dimensional metrics to New Relic using the New Relic Java Telemetry SDK. For the juicy details on how Dropwizard metrics are mapped to New Relic dimensional metrics, please visit the exporter specs documentation repo.

How To Use

gradle

build.gradle:

compile("com.newrelic.telemetry:dropwizard-metrics-newrelic:0.3.0")
compile("com.newrelic.telemetry:telemetry-http-okhttp:0.3.3")

or if you're using kotlin build gradle...

build.gradle.kts:

implementation("com.newrelic.telemetry:dropwizard-metrics-newrelic:0.3.0")
implementation("com.newrelic.telemetry:telemetry-http-okhttp:0.3.3")

If you do not want to depend on okhttp, you can remove the dependency on telemetry-http-okhttp, but you will need to construct a MetricBatchSender instance using its builder and provide your own implementation of the com.newrelic.telemetry.http.HttpPoster interface.

MetricBatchSender sender = MetricBatchSender.builder().httpPoster(<your implementation>);

Note: to use the sample code below, you will need the telemetry-http-okhttp library mentioned above. It provides implementations communicating via HTTP using the okhttp libraries, respectively.

Start The Reporter

Early in the lifecycle of your application, you will want to create and start a NewRelicReporter.

The YOUR_SECRET_API_KEY is referring to your New Relic Event API insert key. For more information and how to obtain a key, visit our docs.

MetricRegistry metricRegistry = new MetricRegistry(); // If you're already using dropwizard-metrics you may already have one of these.
...
String apiKey = "<YOUR_SECRET_API_KEY>";
MetricBatchSender metricBatchSender = SimpleMetricBatchSender.builder(apiKey).build();

Attributes commonAttributes = new Attributes()
            .put("host", InetAddress.getLocalHost().getHostName())
            .put("appName", "Your Application Name Here")
            .put("other", "any other common attributes you wish");
            
NewRelicReporter reporter = NewRelicReporter.build(metricRegistry, metricBatchSender)
        .commonAttributes(commonAttributes)
        .build();
        
reporter.start(15, TimeUnit.SECONDS);

Dropwizard Integration

If you are using the actual Dropwizard REST framework, you can get a reference to the MetricRegistry from the Dropwizard Environment in order to register your reporter.
It might look something like this:

public class MyApplication extends Application<MyConfig> {

...
    @Override
    public void run(MyConfig configuration, Environment environment) {
        MetricRegistry registry = environment.metrics();
        MetricBatchSender metricBatchSender = buildMetricBatchSender(); // see above for more complete example
        NewRelicReporter reporter = NewRelicReporter.build(registry, metricBatchSender)
                .commonAttributes(commonAttributes)
                .build();
        reporter.start(15, TimeUnit.SECONDS);

        ...
    }
...
}

Building

CI builds are run on Azure Pipelines: Build Status The project uses gradle 5 for building, and the gradle wrapper is provided.

To compile, run the tests and build the jars:

$ ./gradlew build

dropwizard-metrics-newrelic's People

Contributors

breedx-nr avatar xixiapdx avatar jasonjkeller avatar jeemar avatar jkwatson avatar

Watchers

James Cloos 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.