-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMetricReporter.java
More file actions
89 lines (68 loc) · 2.4 KB
/
MetricReporter.java
File metadata and controls
89 lines (68 loc) · 2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package com.opensoc.metrics;
import com.codahale.metrics.ConsoleReporter;
import com.codahale.metrics.Counter;
import com.codahale.metrics.JmxReporter;
import com.codahale.metrics.MetricRegistry;
import com.codahale.metrics.graphite.Graphite;
import com.codahale.metrics.graphite.GraphiteReporter;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import org.apache.log4j.Logger;
public class MetricReporter {
final MetricRegistry metrics = new MetricRegistry();
private ConsoleReporter consoleReporter = null;
private JmxReporter jmxReporter = null;
private GraphiteReporter graphiteReporter = null;
private Class _klas;
private String _topologyname = "topology";
/** The Constant LOGGER. */
private static final Logger _Logger = Logger
.getLogger(MetricReporter.class);
public void initialize(Map config, Class klas) {
_Logger.debug("===========Initializing Reporter");
this._klas = klas;
if (config.get("topologyname")!=null)
_topologyname = (String) config.get("topologyname");
this.start(config);
}
public Counter registerCounter(String countername) {
return metrics.counter(MetricRegistry.name(_topologyname,_klas.getCanonicalName(), countername));
}
public void start(Map config) {
try {
if (config.get("reporter.jmx").equals("true")) {
jmxReporter = JmxReporter.forRegistry(metrics).build();
jmxReporter.start();
}
if (config.get("reporter.console").equals("true")) {
consoleReporter = ConsoleReporter.forRegistry(metrics).build();
consoleReporter.start(1, TimeUnit.SECONDS);
}
} catch (Exception e) {
e.printStackTrace();
}
try {
if (config.get("reporter.graphite").equals("true")) {
String address = (String) config.get("graphite.address");
int port = Integer.parseInt((String) config
.get("graphite.port"));
_Logger.debug("===========Graphite ADDRESS: " + address + ":"
+ port);
Graphite graphite = new Graphite(new InetSocketAddress(address,
port));
// Check if graphite connectivity works
graphite.connect();
graphite.close();
graphiteReporter = GraphiteReporter.forRegistry(metrics).build(
graphite);
_Logger.debug("---------******STARTING GRAPHITE*********---------");
graphiteReporter.start(1, TimeUnit.SECONDS);
}
}
catch (IOException io) {
_Logger.warn("Unable to Connect to Graphite");
}
}
}