metrics

Metrics aggregation.

License

License

Categories

Categories

Metrics Application Testing & Monitoring Monitoring
GroupId

GroupId

com.simplaex
ArtifactId

ArtifactId

metrics
Last Version

Last Version

1.4.0
Release Date

Release Date

Type

Type

jar
Description

Description

metrics
Metrics aggregation.
Project URL

Project URL

https://github.com/simplaex/metrics
Project Organization

Project Organization

Simplaex GmbH
Source Code Management

Source Code Management

https://github.com/simplaex/metrics

Download metrics

How to add to project

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

Dependencies

compile (2)

Group / Artifact Type Version
com.google.code.findbugs : jsr305 jar 3.0.2
org.apache.logging.log4j : log4j-1.2-api jar 2.13.0

provided (1)

Group / Artifact Type Version
org.projectlombok : lombok jar 1.18.10

test (1)

Group / Artifact Type Version
junit : junit jar 4.12

Project Modules

There are no modules declared in this project.

dogstatsd metrics

This library implements sending statsd metrics with dogstatsd like tags. Currently it supports sending count and gauge values as well as timings.

Maven dependency

com.simplaex:metrics is deployed in Maven central as:

<dependency>
  <groupId>com.simplaex</groupId>
  <artifactId>metrics</artifactId>
  <version>1.4.0</version>
</dependency>

How to use

com.simplaex.Metrics requires a bit of work defining the existing metrics that your application emits. This is on purpose to make it easier to maintain the emitted metrics as you will have a central definition of all your metrics that an application emits. That allows you to, for example, define sample rates for certain metrics in one place.

package com.simplaex.metrics;

import lombok.Getter;
import lombok.RequiredArgsConstructor;

public class UsageExample {

  @RequiredArgsConstructor
  public enum AppMetrics implements Metric<AppMetrics> {
    SOME_METRIC("com.simplaex.request", Kind.COUNTER, 0.1),
    SOME_OTHER_METRIC("com.simplaex.sessions", Kind.GAUGE);

    AppMetrics(final String name, final Kind kind) {
      this(name, kind, 1.0);
    }

    @Getter
    private final String name;

    @Getter
    private final Metric.Kind kind;

    @Getter
    private final double sampleRate;

  }

  public static void main(final String... args) {
    final MetricsSender<AppMetrics> metricsSender = new StatsdMetricSender<>();

    metricsSender.emit(AppMetrics.SOME_METRIC.withTag("path", "/api/v1").withTag("method", "GET"));
  }

}

Kubernetes support

By default statsd metrics will be emitted to localhost:8125. On kubernetes you may want to emit a statsd metrics collector as a daemon set. In that case expose the UDP port 8125 or your metrics collector contains as a host port. com.simplaex:metrics will automatically figure out the ip address of the node your pod is running on and send metrics there.

That way you do not need to send UDP metrics over the network.

Usage with vertx-sugar

com.simplaex:vertx-sugar uses this library. To bind the metrics sender in your module add a provider:

  @Provides
  public MetricsSender<MyApplicationMetrics> provideMetrics() {
    return new StatsdMetricSender<>();
  }

You can now inject:

private final MetricsSender<MyApplicationMetrics> metricsSender;

Example usage in Scala

package your.sample.project

import com.simplaex.metrics.Metric
import com.simplaex.metrics.Metric.Kind

import scala.beans.BeanProperty

sealed abstract class ApplicationMetrics(
  @BeanProperty val name: String,
  @BeanProperty val kind: Metric.Kind,
  sampleRate: Double = 1.0
) extends Metric[ApplicationMetrics]

object ApplicationMetrics {
  object JobStarted extends ApplicationMetrics("fountain.started", Kind.COUNTER)
  object JobFinished extends ApplicationMetrics("fountain.finished", Kind.COUNTER)
}
com.simplaex

Simplaex

The 1st party data platform that unlocks the value of your customers by turning data into insights and insights into action.

Versions

Version
1.4.0
1.3.0
1.2.1
1.2
1.1.2
1.1.1
1.1
1.0
0.9