io.github.aparnachaudhary:mongodb-metrics

Reporter extension for the Codahale/DropWizard Metrics library which stores data in MongoDB

License

License

Categories

Categories

MongoDB Data Databases Metrics Application Testing & Monitoring Monitoring
GroupId

GroupId

io.github.aparnachaudhary
ArtifactId

ArtifactId

mongodb-metrics
Last Version

Last Version

0.0.2
Release Date

Release Date

Type

Type

jar
Description

Description

io.github.aparnachaudhary:mongodb-metrics
Reporter extension for the Codahale/DropWizard Metrics library which stores data in MongoDB

Download mongodb-metrics

How to add to project

<!-- https://jarcasting.com/artifacts/io.github.aparnachaudhary/mongodb-metrics/ -->
<dependency>
    <groupId>io.github.aparnachaudhary</groupId>
    <artifactId>mongodb-metrics</artifactId>
    <version>0.0.2</version>
</dependency>
// https://jarcasting.com/artifacts/io.github.aparnachaudhary/mongodb-metrics/
implementation 'io.github.aparnachaudhary:mongodb-metrics:0.0.2'
// https://jarcasting.com/artifacts/io.github.aparnachaudhary/mongodb-metrics/
implementation ("io.github.aparnachaudhary:mongodb-metrics:0.0.2")
'io.github.aparnachaudhary:mongodb-metrics:jar:0.0.2'
<dependency org="io.github.aparnachaudhary" name="mongodb-metrics" rev="0.0.2">
  <artifact name="mongodb-metrics" type="jar" />
</dependency>
@Grapes(
@Grab(group='io.github.aparnachaudhary', module='mongodb-metrics', version='0.0.2')
)
libraryDependencies += "io.github.aparnachaudhary" % "mongodb-metrics" % "0.0.2"
[io.github.aparnachaudhary/mongodb-metrics "0.0.2"]

Dependencies

compile (3)

Group / Artifact Type Version
io.dropwizard.metrics : metrics-core jar 3.1.2
org.mongodb : mongo-java-driver jar 3.1.1
org.slf4j : slf4j-api jar 1.7.13

test (4)

Group / Artifact Type Version
ch.qos.logback : logback-classic jar 1.1.3
junit : junit jar 4.12
org.mockito : mockito-core jar 1.10.19
de.flapdoodle.embed : de.flapdoodle.embed.mongo jar 1.50.0

Project Modules

There are no modules declared in this project.

mongodb-metrics-reporter

Build Status (Travis CI) Coverage Status Apache License Maven Central

This project provides a reporter for CodaHale/DropWizard Metrics library to store the metric data in MongoDB.

How does it work?

  1. Define MetricsRegistry which is a JVM wide singleton for metric data

  2. Metrics Reporter is associated with the Metrics Registry

  3. Application services are instrumented with DropWizard Metrics

  4. The reporter reads the data from registry at fixed defined interval and writes this data to the MongoDB datastore is the relevant collection

MetricsMongoDB

Build Requirements:

  • Apache Maven version 3.x

  • Java8

Building

Clone the repository using command

git clone git://github.com/aparnachaudhary/mongodb-metrics-reporter.git

To build, issue this from the command line

mvn clean install

Dependencies

The module has following compile time dependencies

  • io.dropwizard.metrics:metrics-core:jar:3.1.2

  • org.mongodb:mongo-java-driver:jar:3.1.1

  • org.slf4j:slf4j-api:jar:1.7.13

Usage

Add the following dependency to your project’s Maven POM file.

    <dependency>
        <groupId>io.github.aparnachaudhary</groupId>
        <artifactId>mongodb-metrics</artifactId>
        <version>${version.mongodb-reporter}</version>
    </dependency>
        // create metric registry
        MetricRegistry metricRegistry = new MetricRegistry();
        // register JVM metrics
        metricRegistry.register("jvm.attribute", new JvmAttributeGaugeSet());

        MongoDBReporter reporter = MongoDBReporter.forRegistry(metricRegistry)
                .serverAddresses(new ServerAddress[]{new ServerAddress("192.168.99.100", 32768)})
                .withDatabaseName("javasedemo")
                .prefixedWith("javase")
                .build();
        // Report metrics every 5 seconds
        reporter.start(5, TimeUnit.SECONDS);

        // register metric
        metricRegistry.counter("demo.counter").inc();

        // sleep for 10 seconds so that metric is reported to MongoDB store
        try {
            TimeUnit.SECONDS.sleep(10);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

Executing the above program creates two collections (counter and gauge) in javasedemo database.

Counter collection:

/* 0 */
{
    "_id" : ObjectId("565b3b7ec8f3530f3a327001"),
    "name" : "javase.demo.counter",
    "count" : 1,
    "timestamp" : ISODate("2015-11-29T17:53:02Z")
}

/* 1 */
{
    "_id" : ObjectId("565b3b83c8f3530f3a327005"),
    "name" : "javase.demo.counter",
    "count" : 1,
    "timestamp" : ISODate("2015-11-29T17:53:07Z")
}

Gauge collection:

Since we also registered the JvmAttributeGaugeSet; JVM metrics are registered in the gauge collection.

/* 0 */
{
    "_id" : ObjectId("565b3b7ec8f3530f3a326ffe"),
    "name" : "javase.jvm.attribute.name",
    "value" : "[email protected]",
    "timestamp" : ISODate("2015-11-29T17:53:02Z")
}

/* 1 */
{
    "_id" : ObjectId("565b3b7ec8f3530f3a326fff"),
    "name" : "javase.jvm.attribute.uptime",
    "value" : 5711,
    "timestamp" : ISODate("2015-11-29T17:53:02Z")
}

/* 2 */
{
    "_id" : ObjectId("565b3b7ec8f3530f3a327000"),
    "name" : "javase.jvm.attribute.vendor",
    "value" : "Oracle Corporation Java HotSpot(TM) 64-Bit Server VM 25.5-b02 (1.8)",
    "timestamp" : ISODate("2015-11-29T17:53:02Z")
}

/* 3 */
{
    "_id" : ObjectId("565b3b83c8f3530f3a327002"),
    "name" : "javase.jvm.attribute.name",
    "value" : "[email protected]",
    "timestamp" : ISODate("2015-11-29T17:53:07Z")
}

/* 4 */
{
    "_id" : ObjectId("565b3b83c8f3530f3a327003"),
    "name" : "javase.jvm.attribute.uptime",
    "value" : 10561,
    "timestamp" : ISODate("2015-11-29T17:53:07Z")
}

/* 5 */
{
    "_id" : ObjectId("565b3b83c8f3530f3a327004"),
    "name" : "javase.jvm.attribute.vendor",
    "value" : "Oracle Corporation Java HotSpot(TM) 64-Bit Server VM 25.5-b02 (1.8)",
    "timestamp" : ISODate("2015-11-29T17:53:07Z")
}

Samples

Versions

Version
0.0.2
0.0.1