Stackify Metrics


License

License

Categories

Categories

Metrics Application Testing & Monitoring Monitoring
GroupId

GroupId

com.stackify
ArtifactId

ArtifactId

stackify-metrics
Last Version

Last Version

2.1.0
Release Date

Release Date

Type

Type

jar
Description

Description

Stackify Metrics
Stackify Metrics
Project URL

Project URL

https://github.com/stackify/stackify-metrics
Project Organization

Project Organization

Stackify, LLC
Source Code Management

Source Code Management

https://github.com/stackify/stackify-metrics

Download stackify-metrics

How to add to project

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

Dependencies

compile (5)

Group / Artifact Type Version
com.stackify : stackify-api-java jar 3.1.0
org.slf4j : slf4j-api jar 1.7.5
com.fasterxml.jackson.core : jackson-core jar 2.8.11
com.fasterxml.jackson.core : jackson-annotations jar 2.8.11
com.fasterxml.jackson.core : jackson-databind jar 2.8.11.1

test (7)

Group / Artifact Type Version
org.slf4j : slf4j-log4j12 jar 1.7.5
junit : junit jar 4.11
org.mockito : mockito-core jar 1.9.5
org.powermock : powermock-core jar 1.5.6
org.powermock : powermock-module-junit4 jar 1.5.6
org.powermock : powermock-api-mockito jar 1.5.6
nl.jqno.equalsverifier : equalsverifier jar 1.4.1

Project Modules

There are no modules declared in this project.

stackify-metrics

Maven Central Build Status Coverage Status

API for sending custom metrics to Stackify.

Custom Metrics Overview:

http://support.stackify.com/custom-metrics-overview/

Sign Up for a Trial:

http://www.stackify.com/sign-up/

Installation

Add it as a maven dependency:

<dependency>
    <groupId>com.stackify</groupId>
    <artifactId>stackify-metrics</artifactId>
    <version>2.1.1</version>
</dependency>

Usage

There are four different types of metrics:

  • Gauge: Keeps track of the last value that was set in the current minute
  • Counter: Calculates the rate per minute
  • Average: Calculates the average of all values in the current minute
  • Timer: Calculates the average elapsed time for an operation in the current minute
  • CounterAndTimer: Composite of the Counter and Timer metrics for convenience

All metrics are identified with a category and name. We will group metrics with the same category when they are displayed in Stackify. Use the MetricFactory to get different types of metrics. See below for more details on the operations available for each type of metric.

Gauge gauge = MetricFactory.getGauge("MyCategory", "MyGauge");
...

Be sure to properly shutdown to flush any queued metrics and shutdown the background thread:

MetricManager.shutdown();

Configuration

You need a stackify-api.properties file on your classpath that defines the configuration required for the Metrics API:

stackify.apiKey=YOUR_API_KEY
stackify.application=YOUR_APPLICATION_NAME
stackify.environment=YOUR_ENVIRONMENT

Note: If you are logging from a device that has the stackify-agent installed, the environment setting is optional. We will use the environment associated to your device in Stackify.

Programmatic Configuration (Optional)

Instead of providing a properties file in your classpath, you can configure the Metrics API programmatically:

ApiConfiguration.Builder builder = ApiConfiguration.newBuilder();
builder.apiKey("YOUR_API_KEY");
builder.application("YOUR_APPLICATION_NAME");
builder.environment("YOUR_ENVIRONMENT");
ApiConfiguration config = builder.build();
		
MetricManager.configure(config);

This needs to be done at application startup before any other interactions with the Metrics API.

Note: If you are logging from a device that has the stackify-agent installed, the environment setting is optional. We will use the environment associated to your device in Stackify.

Gauge Metric

// Get a Gauge metric
Gauge gauge = MetricFactory.getGauge("MyCategory", "MyGauge");
...

// Set the value of the metric to v
gauge.set(v);
...

// Adds v to the current value of the metric
gauge.add(v);
...

// Subtracts v from the current value of the metric
gauge.subtract(v);
...

// Automatically report 0 for the value of the metric if not set
gauge.autoReportZeroValue();
...

// Automatically report the last value for this metric if not set
gauge.autoReportLastValue();
...

Counter Metric

// Get a Counter metric
Counter counter = MetricFactory.getCounter("MyCategory", "MyCounter");
...

// Adds 1 to the current value of the metric
counter.increment();
...

// Adds v to the current value of the metric
counter.increment(v);
...

// Subtracts 1 from the current value of the metric
counter.decrement();
...

// Subtracts v from the current value of the metric
counter.decrement(v);
...

// Adds v to the current value of the metric
counter.add(v);
...

// Subtracts v from the current value of the metric
counter.subtract(v);
...

// Automatically report 0 for the value of the metric if not set
counter.autoReportZeroValue();
...

Average Metric

// Get a Average metric
Average average = MetricFactory.getAverage("MyCategory", "MyAverage");
...

// Adds a value to the average metric
average.addValue(v);
...

// Automatically report 0 for the value of the metric if not set
average.autoReportZeroValue();
...

// Automatically report the last value for this metric if not set
average.autoReportLastValue();
...

Timer Metric

// Get a Timer metric
Timer timer = MetricFactory.getTimer("MyCategory", "MyTimer");
...

// Calculates the time taken for this operation using the start time d (java.util.Date)
timer.start(d);
...

// Calculates the time taken for this operation using the start time d (milliseconds)
timer.startMs(d);
...

// Sets the time taken for this operation to d (milliseconds)
timer.durationMs(d);
...

// Automatically report 0 for the value of the metric if not set
timer.autoReportZeroValue();
...

CounterAndTimer Metric

// Get a CounterAndTimer metric (composite of a Counter metric and Timer metric)
CounterAndTimer counterAndTimer = MetricFactory.getCounterAndTimer("MyCategory", "MyCounterAndTimer");
...

// Counter: Adds 1 to the current value of the metric
// Timer: Calculates the time taken for this operation using the start time d (java.util.Date)
counterAndTimer.start(d);
...

// Counter: Adds 1 to the current value of the metric
// Timer: Calculates the time taken for this operation using the start time d (milliseconds)
counterAndTimer.startMs(d);
...

// Counter: Adds 1 to the current value of the metric
// Timer: Sets the time taken for this operation to d (milliseconds)
counterAndTimer.durationMs(d);
...

// Automatically report 0 for the value of the metric if not set
counterAndTimer.autoReportZeroValue();
...

License

Copyright 2020 Stackify, LLC.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

com.stackify

Stackify

Stackify helps developers manage and troubleshoot application problems with integrated monitoring, metrics, errors & logs.

Versions

Version
2.1.0
1.1.7
1.1.6
1.1.5
1.1.4
1.1.3
1.1.2
1.1.1
1.1.0
1.0.6
1.0.5
1.0.4
1.0.3
1.0.2
1.0.1
1.0.0