WSO2 Carbon Metrics Core

WSO2 Carbon Metrics is an API for WSO2 Carbon Components to use Dropwizard Metrics library

License

License

Categories

Categories

Metrics Application Testing & Monitoring Monitoring
GroupId

GroupId

org.wso2.carbon.metrics
ArtifactId

ArtifactId

org.wso2.carbon.metrics.core
Last Version

Last Version

2.3.14
Release Date

Release Date

Type

Type

bundle
Description

Description

WSO2 Carbon Metrics Core
WSO2 Carbon Metrics is an API for WSO2 Carbon Components to use Dropwizard Metrics library
Project Organization

Project Organization

WSO2

Download org.wso2.carbon.metrics.core

Dependencies

compile (8)

Group / Artifact Type Version
io.dropwizard.metrics : metrics-core jar 3.2.5
io.dropwizard.metrics : metrics-jvm jar 3.2.5
org.hdrhistogram : HdrHistogram jar 2.1.10
org.wso2.eclipse.osgi » org.eclipse.osgi Optional jar 3.11.0.v20160603-1336
org.wso2.eclipse.osgi » org.eclipse.osgi.services Optional jar 3.5.100.v20160504-1419
org.wso2.carbon : org.wso2.carbon.core jar 5.2.0
org.wso2.carbon.config : org.wso2.carbon.config jar 2.1.13
org.slf4j : slf4j-api jar 1.7.25

test (6)

Group / Artifact Type Version
org.testng : testng jar 7.1.0
org.mockito : mockito-core jar 2.11.0
org.apache.logging.log4j : log4j-api jar 2.9.1
org.apache.logging.log4j : log4j-core jar 2.9.1
org.apache.logging.log4j : log4j-slf4j-impl jar 2.9.1
org.wso2.carbon.secvault : org.wso2.carbon.secvault jar 5.0.14

Project Modules

There are no modules declared in this project.

WSO2 Carbon Metrics


Branch Build Status
master Build Status

"WSO2 Carbon Metrics" provides an API for WSO2 Carbon Components to use the Metrics library.

Configuring Metrics

The metrics is configured via a YAML file. The Metrics is enabled by default and it can be disabled from the configuration. The Metrics is also configured to register a standard Java MBean for management operations.

All reporters are also configured using the same configuration file. By default, the JMX Reporter will be enabled.

Metric Levels

The WSO2 Carbon Metrics APIs associate a Level with each Metric. These levels are similar to the Levels used in Logging Libraries.

Metrics Levels are organized from most specific to least:

  • OFF (most specific, no metrics)
  • INFO
  • DEBUG
  • TRACE (least specific, a lot of data)
  • ALL (least specific, all data)

The levels are configured in YAML file.

Similar to Apache Log4j, the WSO2 Carbon Metrics implementation uses a Metric Hierarchy. The hierarchy is maintained via the Metric names.

The levels in Metrics configuration can be configured to any hierarchy. For example, if we use jvm.memory.heap=INFO, all metrics under jvm.memory.heap memory will have INFO as the configured level.

If there is no configured level for specific metric name hierarachy, the level configured in "rootLevel" will be used.

Components

This repository has multiple components.

  • org.wso2.carbon.metrics.core - Provides the core Metrics and Management APIs. The main Metric Manager implementation uses the Metrics library.
  • org.wso2.carbon.metrics.jdbc.reporter - A JDBC Reporter for Metrics Library.
  • org.wso2.carbon.metrics.das.reporter - A reporter to send metrics events to WSO2 Data Analytics Server (WSO2 DAS).
  • org.wso2.carbon.metrics.das.capp - The artifacts used to create the main Carbon Application (C-App). This C-App is required by the DAS Reporter. The artifacts in this C-App are the event streams, event receivers and the event stores for all Metric types.
  • org.wso2.carbon.metrics.jdbc.core - Extending Metrics Core to support the JDBC Reporter.
  • org.wso2.carbon.metrics.das.core - Extending Metrics Core to support the DAS Reporter.

Maven Dependency

In order to use WSO2 Carbon Metrics in your components, you need to add following dependency to your pom.xml

<dependency>
    <groupId>org.wso2.carbon.metrics</groupId>
    <artifactId>org.wso2.carbon.metrics.core</artifactId>
    <version>${carbon.metrics.version}</version>
</dependency>

Usage

The APIs to create Metrics are defined in org.wso2.carbon.metrics.core.MetricService. The APIs to manage Metrics, such as setting metric levels and adding reporters are defined in org.wso2.carbon.metrics.core.MetricManagementService.

In Carbon (OSGi) environment, these APIs are available as OSGi services.

See the sample ServiceComponent.

When using Metrics in standalone application, the Metrics can be initialized as follows.

Metrics metrics = new Metrics(<ConfigProvider>);
metrics.activate();

MetricService metricService = metrics.getMetricService();
MetricManagementService metricManagementService = metrics.getMetricManagementService();

After getting a reference to the MetricService, the Metrics can be created as follows.

// Create a Gauge
metricService.gauge(MetricService.name("test", "gauge"), Level.INFO, () -> number);

// Create a Counter
Counter counter = metricService.counter(MetricService.name("test", "count"), Level.INFO);
// Increment
counter.inc();
// Decrement
counter.dec();

// Create a Meter
Meter meter = metricService.meter(MetricService.name("test", "meter"), Level.INFO);
// Mark an event
meter.mark();

// Create a Histogram
Histogram histogram = metricService.histogram(MetricService.name("test", "histogram"), Level.INFO);
// Update the histogram
histogram.update(value);

// Create a Timer
Timer timer = metricService.timer(MetricService.name("test", "timer"), Level.INFO);
// Start the timer
Timer.Context context = timer.start();
// Stop the timer
context.stop();

See the sample RandomNumberServiceImpl.

License

Copyright 2014 WSO2 Inc.

Licensed under the Apache License, Version 2.0

org.wso2.carbon.metrics

WSO2

Welcome to the WSO2 source code! For info on working with the WSO2 repositories and contributing code, click the link below.

Versions

Version
2.3.14
2.3.13
2.3.7
2.3.6
2.3.5
2.3.4
2.3.3