Giter VIP home page Giter VIP logo

carbon-metrics's Introduction

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

carbon-metrics's People

Contributors

anugayan avatar chathurikaa avatar chrishantha avatar dnwick avatar gdlmadushanka avatar gimantha avatar grainier avatar heshansudarshana avatar janithcmw avatar ksdperera avatar lasanthas avatar madushadhanushka avatar maheshika avatar mohanvive avatar nandika avatar nirmal070125 avatar nirothipan avatar niveathika avatar ramindu90 avatar raveensr avatar senthuran16 avatar suhothayan avatar tanyam avatar wso2-jenkins-bot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

carbon-metrics's Issues

Error when reporting gauges - Data conversion error

Description:

The following repetititve stack trace can be seen when metrics is enabled in Identity Server 5.1.0 with ~one minute time interval. The issue happens when the Metrics property is enabled.

[16-01-2019 00:51:08.948] [ERROR] [] [] [org.wso2.carbon.metrics.reporter.JDBCReporter]:  [58] Error when reporting gauges
org.h2.jdbc.JdbcSQLException: Data conversion error converting "l.testhost.com^Eʼʧí
 jvm.c^@" [90021-140]
        at org.h2.message.DbException.getJdbcSQLException(DbException.java:327)
        at org.h2.message.DbException.get(DbException.java:156)
        at org.h2.value.Value.convertTo(Value.java:791)
        at org.h2.table.Table.compareTypeSave(Table.java:969)
        at org.h2.index.BaseIndex.compareValues(BaseIndex.java:297)
        at org.h2.index.BaseIndex.compareRows(BaseIndex.java:245)
        at org.h2.index.PageBtree.find(PageBtree.java:117)
        at org.h2.index.PageBtreeNode.addRowTry(PageBtreeNode.java:198)
        at org.h2.index.PageBtreeIndex.addRow(PageBtreeIndex.java:90)
        at org.h2.index.PageBtreeIndex.add(PageBtreeIndex.java:81)
        at org.h2.table.RegularTable.addRow(RegularTable.java:116)
        at org.h2.store.PageStore.redo(PageStore.java:1331)
        at org.h2.store.PageLog.recover(PageLog.java:288)
        at org.h2.store.PageStore.recover(PageStore.java:1179)
        at org.h2.store.PageStore.openExisting(PageStore.java:317)
        at org.h2.store.PageStore.open(PageStore.java:271)
        at org.h2.engine.Database.getPageStore(Database.java:2059)
        at org.h2.engine.Database.open(Database.java:534)
        at org.h2.engine.Database.openDatabase(Database.java:207)
        at org.h2.engine.Database.<init>(Database.java:202)
        at org.h2.engine.Engine.openSession(Engine.java:56)
        at org.h2.engine.Engine.openSession(Engine.java:146)
        at org.h2.engine.Engine.getSession(Engine.java:125)
        at org.h2.engine.Session.createSession(Session.java:122)
        at org.h2.engine.SessionRemote.connectEmbeddedOrServer(SessionRemote.java:241)
        at org.h2.engine.SessionRemote.createSession(SessionRemote.java:219)
        at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:111)
        at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:95)
        at org.h2.Driver.connect(Driver.java:73)
        at org.apache.tomcat.jdbc.pool.PooledConnection.connectUsingDriver(PooledConnection.java:278)
        at org.apache.tomcat.jdbc.pool.PooledConnection.connect(PooledConnection.java:182)
        at org.apache.tomcat.jdbc.pool.ConnectionPool.createConnection(ConnectionPool.java:701)
        at org.apache.tomcat.jdbc.pool.ConnectionPool.borrowConnection(ConnectionPool.java:635)
        at org.apache.tomcat.jdbc.pool.ConnectionPool.getConnection(ConnectionPool.java:188)
        at org.apache.tomcat.jdbc.pool.DataSourceProxy.getConnection(DataSourceProxy.java:128)
        at org.wso2.carbon.metrics.reporter.JDBCReporter.reportGauges(JDBCReporter.java:203)
        at org.wso2.carbon.metrics.reporter.JDBCReporter.report(JDBCReporter.java:181)
        at com.codahale.metrics.ScheduledReporter.report(ScheduledReporter.java:162)        
        at com.codahale.metrics.ScheduledReporter$1.run(ScheduledReporter.java:117)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
        at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.NumberFormatException: For input string: "l.testhost.com^Eʼʧí
 jvm.c"
        at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
        at java.lang.Long.parseLong(Long.java:589)
        at java.lang.Long.valueOf(Long.java:776)
        at java.lang.Long.decode(Long.java:928)
        at org.h2.value.Value.convertTo(Value.java:750)
        ... 43 more

Also, the metrics property is enabled by default in the products. AFAIU, it should be disabled by default and let someone enable it if only they need to use it.

Suggested Labels:

Suggested Assignees:

Affected Product Version:
v1.1.1

OS, DB, other environment details and versions:

Steps to reproduce:

Related Issues:

BatchUpdateException when Metrics DB is configured using Postgres SQL

Please see : https://wso2.org/jira/projects/CMETRICS/issues/CMETRICS-2

Steps to recreate the issue

  1. Configure datasources to use Postgres
  2. Start analytics pack using -Dsetup
    Below error observed in the terminal.
    [2016-07-25 16:29:38,136] INFO {org.wso2.carbon.event.stream.core.internal.EventJunction} - WSO2EventConsumer added to the junction. Stream:esb-event:1.0.0
    [2016-07-25 16:29:38,136] INFO {org.wso2.carbon.analytics.eventsink.AnalyticsEventStoreDeployer} - Deployed successfully analytics event store: esb-event.xml
    [2016-07-25 16:30:02,081] INFO {org.wso2.carbon.event.processor.manager.core.internal.CarbonEventManagementService} - Starting polling event receivers
    [2016-07-25 16:31:09,895] ERROR {org.wso2.carbon.metrics.jdbc.reporter.JDBCReporter} - Error when reporting gauges
    java.sql.BatchUpdateException: Batch entry 0 INSERT INTO METRIC_GAUGE (SOURCE, TIMESTAMP, NAME, VALUE) VALUES ('sashika',1469444469892,'jvm.class-loading.loaded.current',25561) was aborted. Call getNextException to see the cause.
    at org.postgresql.jdbc2.AbstractJdbc2Statement$BatchResultHandler.handleError(AbstractJdbc2Statement.java:2778)
    at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1912)
    at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:338)
    at org.postgresql.jdbc2.AbstractJdbc2Statement.executeBatch(AbstractJdbc2Statement.java:2959)
    at org.wso2.carbon.metrics.jdbc.reporter.JDBCReporter.reportGauges(JDBCReporter.java:221)
    at org.wso2.carbon.metrics.jdbc.reporter.JDBCReporter.report(JDBCReporter.java:188)
    at com.codahale.metrics.ScheduledReporter.report(ScheduledReporter.java:162)
    at com.codahale.metrics.ScheduledReporter$1.run(ScheduledReporter.java:117)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
    at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:304)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:178)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:745)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.