Skip to content

RRD4j based Server JVM and user defined metrics in simple UI Fashion

Notifications You must be signed in to change notification settings

nitinka/JMetrics

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

48 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

  • Its a very simple java lib which allows users to capture various metrics from within running jvm and store them locally using rrd4j library and serve them back using simple http end points from with in the app

  • JMX metrics are captured out of box. Library also expose single liner code to add any user defined metrics either explicitly or by writing threaded metric monitors.

  • Such stored metrics can be viewed, graphed to make meaningful decisions in terms of scaling, improving performance and functional aspects.

  • Users can add threshold limits to any monitored metric( say deadlock, memory etc), when ever any metric breaches the threshold it would also be captured and showcased in report.

  • This library can be embedded within any existing java application to get meaningful metrics driven information with in few minutes. DThere is direct support for Dropwizard and RestExpress based web application. For stand alone application, JMetric can be told to start a light weight embedded server.

  • You can start/stop service at runtime just by hitting http end point
  • Http end points :
  http://host:port/servletPath/metrics
     Returns all metrics that are being captured
  http://host:port/servletPath/metrics/img
     Returns last 2 day graphical statistics of all metrics
  http://host:port/servletPath/metrics/metricName/img
     Returns last 2 day graphical statistics of metric specifird
  http://host:port/servletPath/metrics/metricName/raw
     Returns last 2 day raw statistics of metric specifird

  You can query statistics for specific duration with startTime and endTime query Parameters:
  Possible Values for startTime/endTime : -60s(60 seconds ago from now), -60m(60 mins ago from now)
     Use h and d   for hours and days. 
     If startTime is missing then it is assumed to be -2d (2 days ago from now)
     If endTime is missing then its assumed to be current Time
  • To Add Threshold to metrics:
  Http PUT on http://host:port/servletPath/metrics/metricName/threshold
    [
      {
        level: "CRITICAL",
        check: "GT",
        thresholdValues: [
          -1
        ]
      }
    ]
    check can take : LT, GT, BT with single, single and 2 thresholdValues respectively
    level can take CRITICAL and WARNING

  Http GET on http://host:port/servletPath/metrics/metricName/threshold 
     Returns set threshold for given metric
  • To Start/Stop Metric Collection:
  http://host:port/servletPath/stop
     Stop the monitoring
  http://host:port/servletPath/start
     Start the monitoring


Sample metric report : Alt Image


Steps to Integrate with DropWizard(0.5.*,0.6.1) based Backend Application :

  1. Add maven dep :
<repositories>
    <repository>
        <id>nitinka.mvn.repo</id>
        <url>https://github.com/nitinka/mvn-repo/raw/master</url>
        <!-- use snapshot version -->
        <snapshots>
            <enabled>true</enabled>
            <updatePolicy>always</updatePolicy>
        </snapshots>
    </repository>
</repositories>

<dependency>
    <groupId>nitinka.jmetrics</groupId>
    <artifactId>JMetrics</artifactId>
    <version>0.1.6</version>
</dependency> 

2) Add following in your application.yml file :
jMetricConfig:
  archivalEngineClass: "nitinka.jmetrics.archive.RRD4JArchivingEngine"
  configParams:
    basePath: "/var/log/your-app/jmetric/data"
  thresholdPath : "/var/log/your-app/jmetric/threshold"  

  1. Add following code in your Dropwizard Applicaion Config Class :
    private JMetricConfig jMetricConfig;

    public JMetricConfig getjMetricConfig() {
        return jMetricConfig;
    }

    public void setjMetricConfig(JMetricConfig jMetricConfig) {
        this.jMetricConfig = jMetricConfig;
    }

  1. Add following in your service initialization code :
    JMetric.initialize(configuration.getjMetricConfig());
    environment.addResource(new JMetricController())

5) Restart your app and hit urls

Steps to Integrate with RestExpress :
  1. Add maven dep :
<repositories>
    <repository>
        <id>nitinka.mvn.repo</id>
        <url>https://github.com/nitinka/mvn-repo/raw/master</url>
        <!-- use snapshot version -->
        <snapshots>
            <enabled>true</enabled>
            <updatePolicy>always</updatePolicy>
        </snapshots>
    </repository>
</repositories>

<dependency>
    <groupId>nitinka.jmetrics</groupId>
    <artifactId>JMetrics</artifactId>
    <version>0.1.6</version>
</dependency> 

2) Initialize JMetricConfig class with following details :
jMetricConfig:
  archivalEngineClass: "nitinka.jmetrics.archive.RRD4JArchivingEngine"
  configParams:
    basePath: "/var/log/your-app/jmetric/data"
  thresholdPath : "/var/log/your-app/jmetric/threshold"  

  1. Add following in your service initialization code :
    JMetric.initialize(jMetricConfigInstance);
    nitinka.jmetrics.controller.restexpress.JMetricController.setup(restexpressServerInstance);

  1. Restart your app and hit urls


Steps to Embedded JMetric Controlled in other Applications :
  1. Add maven dep :
<repositories>
    <repository>
        <id>nitinka.mvn.repo</id>
        <url>https://github.com/nitinka/mvn-repo/raw/master</url>
        <!-- use snapshot version -->
        <snapshots>
            <enabled>true</enabled>
            <updatePolicy>always</updatePolicy>
        </snapshots>
    </repository>
</repositories>

<dependency>
    <groupId>nitinka.jmetrics</groupId>
    <artifactId>JMetrics</artifactId>
    <version>0.1.6</version>
</dependency> 

2) Initialize JMetricConfig class with following details :
jMetricConfig:
  archivalEngineClass: "nitinka.jmetrics.archive.RRD4JArchivingEngine"
  configParams:
    basePath: "/var/log/your-app/jmetric/data"
  serverPort: 4567
  thresholdPath : "/var/log/your-app/jmetric/threshold"

  1. Add following in your service initialization code :
    JMetric.initialize(jMetricConfigInstance);

  1. Restart your app and hit urls

About

RRD4j based Server JVM and user defined metrics in simple UI Fashion

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages