Jian Li
Committed by Gerrit Code Review

Handle reporting errors gracefully for various metrics reporters

Change-Id: Ifc928fa25732609ff185caf213467ee40bdb6f53
...@@ -92,7 +92,7 @@ public class DefaultGangliaMetricsReporter implements GangliaMetricsReporter { ...@@ -92,7 +92,7 @@ public class DefaultGangliaMetricsReporter implements GangliaMetricsReporter {
92 @Activate 92 @Activate
93 public void activate() { 93 public void activate() {
94 cfgService.registerProperties(getClass()); 94 cfgService.registerProperties(getClass());
95 - coreService.registerApplication("org.onosproject.metrics.reporter"); 95 + coreService.registerApplication("org.onosproject.gangliametrics");
96 metricsService.registerReporter(this); 96 metricsService.registerReporter(this);
97 97
98 startReport(); 98 startReport();
...@@ -120,7 +120,13 @@ public class DefaultGangliaMetricsReporter implements GangliaMetricsReporter { ...@@ -120,7 +120,13 @@ public class DefaultGangliaMetricsReporter implements GangliaMetricsReporter {
120 public void startReport() { 120 public void startReport() {
121 configGMetric(); 121 configGMetric();
122 gangliaReporter = buildReporter(ganglia); 122 gangliaReporter = buildReporter(ganglia);
123 - gangliaReporter.start(REPORT_PERIOD, REPORT_TIME_UNIT); 123 +
124 + try {
125 + gangliaReporter.start(REPORT_PERIOD, REPORT_TIME_UNIT);
126 + } catch (Exception e) {
127 + log.error("Errors during reporting to ganglia, msg: {}" + e.getMessage());
128 + }
129 +
124 log.info("Start to report metrics to ganglia server."); 130 log.info("Start to report metrics to ganglia server.");
125 } 131 }
126 132
...@@ -142,7 +148,13 @@ public class DefaultGangliaMetricsReporter implements GangliaMetricsReporter { ...@@ -142,7 +148,13 @@ public class DefaultGangliaMetricsReporter implements GangliaMetricsReporter {
142 public void notifyMetricsChange() { 148 public void notifyMetricsChange() {
143 gangliaReporter.stop(); 149 gangliaReporter.stop();
144 gangliaReporter = buildReporter(ganglia); 150 gangliaReporter = buildReporter(ganglia);
145 - gangliaReporter.start(REPORT_PERIOD, REPORT_TIME_UNIT); 151 +
152 + try {
153 + gangliaReporter.start(REPORT_PERIOD, REPORT_TIME_UNIT);
154 + } catch (Exception e) {
155 + log.error("Errors during reporting to ganglia, msg: {}" + e.getMessage());
156 + }
157 +
146 log.info("Metric registry has been changed, apply changes."); 158 log.info("Metric registry has been changed, apply changes.");
147 } 159 }
148 160
......
...@@ -125,7 +125,13 @@ public class DefaultGraphiteMetricsReporter implements GraphiteMetricsReporter { ...@@ -125,7 +125,13 @@ public class DefaultGraphiteMetricsReporter implements GraphiteMetricsReporter {
125 public void startReport() { 125 public void startReport() {
126 configGraphite(); 126 configGraphite();
127 graphiteReporter = buildReporter(graphite); 127 graphiteReporter = buildReporter(graphite);
128 - graphiteReporter.start(reportPeriod, REPORT_TIME_UNIT); 128 +
129 + try {
130 + graphiteReporter.start(DEFAULT_REPORT_PERIOD, REPORT_TIME_UNIT);
131 + } catch (Exception e) {
132 + log.error("Errors during reporting to graphite, msg: {}" + e.getMessage());
133 + }
134 +
129 log.info("Start to report metrics to graphite server."); 135 log.info("Start to report metrics to graphite server.");
130 } 136 }
131 137
...@@ -146,7 +152,13 @@ public class DefaultGraphiteMetricsReporter implements GraphiteMetricsReporter { ...@@ -146,7 +152,13 @@ public class DefaultGraphiteMetricsReporter implements GraphiteMetricsReporter {
146 public void notifyMetricsChange() { 152 public void notifyMetricsChange() {
147 graphiteReporter.stop(); 153 graphiteReporter.stop();
148 graphiteReporter = buildReporter(graphite); 154 graphiteReporter = buildReporter(graphite);
149 - graphiteReporter.start(DEFAULT_REPORT_PERIOD, REPORT_TIME_UNIT); 155 +
156 + try {
157 + graphiteReporter.start(DEFAULT_REPORT_PERIOD, REPORT_TIME_UNIT);
158 + } catch (Exception e) {
159 + log.error("Errors during reporting to graphite, msg: {}" + e.getMessage());
160 + }
161 +
150 log.info("Metric registry has been changed, apply changes."); 162 log.info("Metric registry has been changed, apply changes.");
151 } 163 }
152 164
......
...@@ -120,7 +120,12 @@ public class DefaultInfluxDbMetricsReporter implements InfluxDbMetricsReporter { ...@@ -120,7 +120,12 @@ public class DefaultInfluxDbMetricsReporter implements InfluxDbMetricsReporter {
120 public void startReport() { 120 public void startReport() {
121 configSender(); 121 configSender();
122 influxDbReporter = buildReporter(influxDbHttpSender); 122 influxDbReporter = buildReporter(influxDbHttpSender);
123 - influxDbReporter.start(REPORT_PERIOD, REPORT_TIME_UNIT); 123 +
124 + try {
125 + influxDbReporter.start(REPORT_PERIOD, REPORT_TIME_UNIT);
126 + } catch (Exception e) {
127 + log.error("Errors during reporting to InfluxDB, msg: {}" + e.getMessage());
128 + }
124 log.info("Start to report metrics to influxDB."); 129 log.info("Start to report metrics to influxDB.");
125 } 130 }
126 131
...@@ -142,7 +147,13 @@ public class DefaultInfluxDbMetricsReporter implements InfluxDbMetricsReporter { ...@@ -142,7 +147,13 @@ public class DefaultInfluxDbMetricsReporter implements InfluxDbMetricsReporter {
142 public void notifyMetricsChange() { 147 public void notifyMetricsChange() {
143 influxDbReporter.stop(); 148 influxDbReporter.stop();
144 influxDbReporter = buildReporter(influxDbHttpSender); 149 influxDbReporter = buildReporter(influxDbHttpSender);
145 - influxDbReporter.start(REPORT_PERIOD, REPORT_TIME_UNIT); 150 +
151 + try {
152 + influxDbReporter.start(REPORT_PERIOD, REPORT_TIME_UNIT);
153 + } catch (Exception e) {
154 + log.error("Errors during reporting to InfluxDB, msg: {}" + e.getMessage());
155 + }
156 +
146 log.info("Metric registry has been changed, apply changes."); 157 log.info("Metric registry has been changed, apply changes.");
147 } 158 }
148 159
......