GithubHelp home page GithubHelp logo

isabella232 / wavefront-dropwizard-metrics-sdk-java Goto Github PK

View Code? Open in Web Editor NEW

This project forked from wavefronthq/wavefront-dropwizard-metrics-sdk-java

0.0 0.0 0.0 268 KB

Send Dropwizard Metrics to Wavefront

License: Apache License 2.0

Java 100.00%

wavefront-dropwizard-metrics-sdk-java's Introduction

Wavefront Dropwizard Metrics SDK build status Released Version

Table of Content

Welcome to the Wavefront Dropwizard Metrics SDK

The Tanzu Observability by Wavefront Dropwizard Metrics SDK for Java is a library that supports reporting Dropwizard metrics, delta counters, and histograms to Wavefront.

Before you start implementing, let us make sure you are using the correct SDK!

Wavefront Dropwizard Metrics SDK Decision Tree

Note:
This is the Tanzu Observability by Wavefront Metrics SDK for the Java Dropwizard Framework! If this SDK is not what you were looking for, see the table given below.

Wavefront SDKs

SDK Type SDK Description Supported Languages
OpenTracing SDK Implements the OpenTracing specification. Lets you define, collect, and report custom trace data from any part of your application code.
Automatically derives Rate Errors Duration (RED) metrics from the reported spans.
Metrics SDK Implements a standard metrics library. Lets you define, collect, and report custom business metrics and histograms from any part of your application code.
Framework SDK Reports predefined traces, metrics, and histograms from the APIs of a supported app framework. Lets you get started quickly with minimal code changes.
Sender SDK Lets you send raw values to Wavefront for storage as metrics, histograms, or traces, e.g., to import CSV data into Wavefront.

Prerequisites

If you are using Maven, add the following maven dependency to your pom.xml file:

<dependency>
    <groupId>com.wavefront</groupId>
    <artifactId>wavefront-dropwizard-metrics-sdk-java</artifactId>
    <version>$releaseVersion</version>
</dependency>

Replace $releaseVersion with the latest version available on maven.

Set Up a DropwizardMetricsReporter

This SDK provides a DropwizardMetricsReporter to report metrics and histograms to Wavefront.

To create a DropwizardMetricsReporter, follow these steps:

  1. Create a DropwizardMetricsReporter.Builder instance.
  2. Optionally, use the builder to configure the DropwizardMetricsReporter.
  3. Create a WavefrontSender to send data to Wavefront.
  4. Use the builder to create a DropwizardMetricsReporter with the WavefrontSender.

For details of each step, see the sections below.

Step 1: Create a Builder for a DropwizardMetricsReporter

The DropwizardMetricsReporter object reports any metrics, delta counters, and histograms you register in a MetricRegistry. This step creates a builder that supports configuring the metrics reporter.

// Create a registry
MetricRegistry metricRegistry = new MetricRegistry();

// Create a builder instance for the registry
DropwizardMetricsReporter.Builder builder = DropwizardMetricsReporter.forRegistry(metricRegistry);

Step 2: Configure the DropwizardMetricsReporter (Optional)

You can use the DropwizardMetricsReporter builder to specify various optional properties.

Basic Properties

// Optional: Set a nondefault source for your metrics, delta counters, and histograms.
// Defaults to hostname if omitted
builder.withSource("mySource");

// Add individual reporter-level point tags for your metrics, delta counters, and histograms
// The point tags are sent with every metric and histogram reported to Wavefront.
builder.withReporterPointTag("env", "staging");  // Example - replace values!
builder.withReporterPointTag("location", "SF");  // Example - replace values!

// Optional: Add application tags, which are propagated as point tags with the reported metric.
// See https://github.com/wavefrontHQ/wavefront-sdk-java/blob/master/docs/apptags.md for details.
builder.withApplicationTags(new ApplicationTags.Builder("OrderingApp", "Inventory").
       cluster("us-west-1").
       shard("primary").build());   // Example - replace values!

// Optional: Report your metrics, delta counters, and histograms with the specified prefix.
builder.prefixedWith("myPrefix");   // Example - replace value!

// Optional: Report JVM metrics for your Java application.
builder.withJvmMetrics();

// Optional: Report minute bin Wavefront histograms.
builder.reportMinuteDistribution();

// Optional: Report hour bin Wavefront histograms.
builder.reportHourDistribution();

// Optional: Report day bin Wavefront histograms.
builder.reportDayDistribution();

Advanced Properties

// Optional: Explicitly set the clock to override default behavior
builder.withClock(new Clock() {
  @Override
  public long getTick() {
    return System.currentTimeMillis();
  }
});

// Optional: Set a filter to report metrics only if they begin with 'my*'
builder.filter(MetricFilter.startsWith("my"));

// Optional: Don't report stddev and m15
builder.disabledMetricAttributes(ImmutableSet.<MetricAttribute>builder().
    add(MetricAttribute.STDDEV).
    add(MetricAttribute.M15_RATE).
    build());

Step 3: Set Up a WavefrontSender

The WavefrontSender object implements the low-level interface to send data to Wavefront.

Step 4: Create a DropwizardMetricsReporter

Use the configured builder to create the DropwizardMetricsReporter. You must first specify the WavefrontSender object (see above).

// Create a DropwizardMetricsReporter instance
WavefrontSender wavefrontSender = buildWavefrontSender(); // pseudocode
DropwizardMetricsReporter dropwizardMetricsReporter = builder.build(wavefrontSender);

Start the DropwizardMetricsReporter

You need to explicitly start the DropwizardMetricsReporter to start reporting any metrics, delta counters, or histograms you create. Reporting continues until you stop the DropwizardMetricsReporter (see below).

The DropwizardMetricsReporter reports metrics/delta counters/histograms at regular intervals. Specify the length of the reporting interval to control how often you send data to the WavefrontSender. The reporting interval determines the timestamps on the data sent to Wavefront.

// Start the reporter to report metrics/delta counters/histograms at regular interval (example: 30s)
dropwizardMetricsReporter.start(30, TimeUnit.SECONDS);

Stop the DropwizardMetricsReporter

You must explicitly stop the DropwizardMetricsReporter before shutting down your application.

// Get total failure count reported by this reporter
int totalFailures = dropwizardMetricsReporter.getFailureCount();

// stop the reporter
dropwizardMetricsReporter.stop();

Types of Data You Can Report to Wavefront

The Dropwizard metrics library supports various metric types. This Wavefront SDK additionally provides a DeltaCounter type and a WavefrontHistogram type.

After you have created and started the DropwizardMetricsReporter, the metrics/delta counters/histograms you create are automatically reported to Wavefront.

// Assume a DropwizardMetricsReporter that is configured with the filter shown in Advanced Properties, above.

// Raw Counters
// Counter name begins with 'my*', so it's reported.
Counter counter = metricRegistry.counter("myCounter");
// Counter name does not begin with 'my*', so it's ignored.
Counter notReported = metricRegistry.counter("notMyCounter");

// Wavefront Delta Counter
DeltaCounter deltaCounter = DeltaCounter.get(metricRegistry, "myDeltaCounter");

// Gauge
AtomicInteger bufferSize = new AtomicInteger();
Gauge gauge = metricRegistry.register("myGauge", () -> bufferSize.get());

// Meter
Meter meter = metricRegistry.meter("myMeter");

// Timer
Timer timer = metricRegistry.timer("myTimer");

// Default Dropwizard Histogram
Histogram dropwizardHistogram = metricRegistry.histogram("myDropwizardHistogram");

// WavefrontHistogram
WavefrontHistogram wavefrontHistogram = WavefrontHistogram.get(metricRegistry, "myWavefrontHistogram");

Monitoring the SDK

See the diagnostic metrics documentation for details on the internal metrics that this SDK collects and reports to Wavefront.

License

Apache 2.0 License.

How to Contribute

  • Reach out to us on our public Slack channel.
  • If you run into any issues, let us know by creating a GitHub issue.
  • If you didn't find the information you are looking for in our Wavefront Documentation, create a GitHub issue or PR.

wavefront-dropwizard-metrics-sdk-java's People

Contributors

akodali18 avatar conorbev avatar dependabot[bot] avatar hanwavefront avatar joannatk avatar oppegard avatar panghy avatar shavidissa avatar srujann avatar susanjlindner avatar sushantdewan123 avatar vikramraman avatar wf-jenkins 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.