Commit 0be8d431 by amir

graphite_hostport' (default to null) , if null no reporting will start

parent 47538921
### Microservice Framework in JAVA
## Version 1.2.2:
- graphite_hostport' (default to null) , if null no reporting will start
## Version 1.2.1:
- create with metrics false/true
- init metrics publisher only once
......
group 'com.ipgallery.common'
version '1.2.1'
version '1.2.2'
apply plugin: 'java'
apply plugin: 'maven-publish'
......
......@@ -349,7 +349,7 @@ public class MicroserviceApp
if (this.enableMetrics)
{
IMetricsFactoryImpl.getInstance().startReporting();
IMetricsFactoryImpl.getInstance().startReporting(appName);
}
if (rsiParams != null && restServerActive) {
......@@ -447,7 +447,7 @@ public class MicroserviceApp
if (serverList != null)
{
if (this.enableMetrics) {
IMetricsFactoryImpl.getInstance().startReporting();
IMetricsFactoryImpl.getInstance().startReporting(appName);
}
......
......@@ -32,8 +32,9 @@ public interface IMetricsFactory
/**
* must be at the end of init , after the netrics are defined
* @param appName
*/
public void startReporting();
public void startReporting(String appName);
public IMeter createMeter(String name);
public ICounter createCounter(String name);
......
......@@ -3,7 +3,6 @@ package microservice.io.impl;
import com.codahale.metrics.*;
import com.codahale.metrics.Timer.Context;
import com.codahale.metrics.graphite.Graphite;
import com.codahale.metrics.graphite.GraphiteReporter;
import com.codahale.metrics.graphite.PickledGraphite;
import microservice.MicroserviceApp;
......@@ -137,20 +136,22 @@ public class IMetricsFactoryImpl implements IMetricsFactory
}
@Override
public void startReporting()
public void startReporting(String appName)
{
String graphite_hostport = MicroserviceApp.getsInstance().getConfiguration().getString("graphite_hostport", "localhost:2015");
String graphite_hostport = MicroserviceApp.getsInstance().getConfiguration().getString("graphite_hostport", null);
Long interval = MicroserviceApp.getsInstance().getConfiguration().getLong("graphite_report_intrerval",Long.valueOf(10));
if (graphite_hostport != null) {
int index = graphite_hostport.indexOf(':');
final PickledGraphite pickledGraphite = new PickledGraphite(new InetSocketAddress(graphite_hostport.substring(0,index), Integer.valueOf(graphite_hostport.substring(index + 1)).intValue()));
final PickledGraphite pickledGraphite = new PickledGraphite(new InetSocketAddress(graphite_hostport.substring(0, index), Integer.valueOf(graphite_hostport.substring(index + 1)).intValue()));
reporter = GraphiteReporter.forRegistry(metrics)
.prefixedWith("web1.example.com")
.prefixedWith(appName)
.convertRatesTo(TimeUnit.SECONDS)
.convertDurationsTo(TimeUnit.MILLISECONDS)
.filter(MetricFilter.ALL)
.build(pickledGraphite);
reporter.start(interval.intValue(), TimeUnit.SECONDS);
}
}
@Override
public IMeter createMeter(String name)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment