Skip to content
This repository has been archived by the owner on May 11, 2021. It is now read-only.

Metrics publishing

Maciej Peruga edited this page Dec 2, 2015 · 11 revisions

Description

We have microservices so we need to monitor our system. Not only whether they are alive or not. We want to measure as much as possible. From every possible angle - amount of requests, technical stuff like how many errors we have or from business perspective - how many loans are issued per minute (or whatever). We collect those measurements in Graphite.

If you select this module we will give you two publishers (Graphite - GraphitePublisher and JMX - JmxPublisher) that will provide setup for your metrics to be published in Graphite and as an MBean.

As a Spring bean we are providing beans (including MetricRegistry that is required by all metrics) that will take care of the metric name standards that we have in 4finance:

 (root-name).(environment).(country).(application-name).(metric-name).(node-name)

It is possible to switch off metrics publishing to Graphite using configuration parameter graphite.publishing.enabled. It accepts following values: on | true | yes to enable publishing and off | false | no to disable it.

Example of usage

Sample metric gathering class (extract from Boot microservice template):

class MatchProbabilityMetrics {

    private final Map<PlaceResolutionProbability, Meter> probabilityMeters = [:]

    MatchProbabilityMetrics(MetricRegistry metricRegistry) {
        registerProbabilityMetrics(metricRegistry)
    }

    void update(PlaceResolutionProbability probability) {
        probabilityMeters[probability].mark()
    }

    private void registerProbabilityMetrics(MetricRegistry metricRegistry) {
        PlaceResolutionProbability.values().each { probability ->
            probabilityMeters[probability] = metricRegistry.meter("twitter.places.analyzed.probability.$probability")
        }
    }
}

Example of a metric path (for different measurements of high probability of locations of tweets)

apps.test.pl.apl-001.twitter-places-analyzer.places.analyzed.probability.high

Metrics properties

Below you can find properties with its default values:

# Host where Graphite is deployed
graphite.host=graphite.4finance.net

# Port for Graphite
graphite.port=2003

# Enable/disable metrics publishing to Graphite in production profile
# Accepted values are on|true|yes to enable publishing and off|false|no to disable it
graphite.publishing.enabled=on

# Publishing interval in ms 
graphite.publishing.interval=15000

# Root metrics param of 'apps'
metrics.path.root=apps

# Environment to which you deploy application ('test', 'stage', 'prod')
metrics.path.environment=test

# Country for which you deploy your app
metrics.path.country=pl

# Your app name
metrics.path.app=service-name

# Node name
metrics.path.node=apl-001

Module configuration

If you want to use only this module just add a dependency:

repositories {
    jcenter()
}

dependencies {
    compile 'com.ofg:micro-infra-spring-base:0.6.0'
}

and enable this feature via annotation:

@Configuration
@EnableMetrics
class MyWebAppConfiguration {

}

Built-in metrics

! DEFAULT setting : rest.client.metrics.enabled:false

When using ServiceRestClient library publishes many built-in metrics to Graphite, including client request latencies and volume. Moreover we automatically publish all Hystrix metrics, so you can get much longer history of circuit breaker statistics.