@@ -93,20 +93,25 @@ MetricFamilySamples fromCounter(String dropwizardName, Counter counter) {
93
93
* Export gauge as a prometheus gauge.
94
94
*/
95
95
MetricFamilySamples fromGauge (String dropwizardName , Gauge gauge ) {
96
- Object obj = gauge .getValue ();
97
- double value ;
98
- if (obj instanceof Number ) {
99
- value = ((Number ) obj ).doubleValue ();
100
- } else if (obj instanceof Boolean ) {
101
- value = ((Boolean ) obj ) ? 1 : 0 ;
102
- } else {
103
- LOGGER .log (Level .FINE , String .format ("Invalid type for Gauge %s: %s" , sanitizeMetricName (dropwizardName ),
104
- obj == null ? "null" : obj .getClass ().getName ()));
105
- return null ;
96
+ try {
97
+ Object obj = gauge .getValue ();
98
+ double value ;
99
+ if (obj instanceof Number ) {
100
+ value = ((Number ) obj ).doubleValue ();
101
+ } else if (obj instanceof Boolean ) {
102
+ value = ((Boolean ) obj ) ? 1 : 0 ;
103
+ } else {
104
+ LOGGER .log (Level .FINE , String .format ("Invalid type for Gauge %s: %s" , sanitizeMetricName (dropwizardName ),
105
+ obj == null ? "null" : obj .getClass ().getName ()));
106
+ return null ;
107
+ }
108
+ MetricFamilySamples .Sample sample = sampleBuilder .createSample (dropwizardName , "" ,
109
+ new ArrayList <String >(), new ArrayList <String >(), value );
110
+ return new MetricFamilySamples (sample .name , Type .GAUGE , getHelpMessage (dropwizardName , gauge ), Arrays .asList (sample ));
111
+ } catch (NullPointerException e ) {
112
+ e .printStackTrace ();
106
113
}
107
- MetricFamilySamples .Sample sample = sampleBuilder .createSample (dropwizardName , "" ,
108
- new ArrayList <String >(), new ArrayList <String >(), value );
109
- return new MetricFamilySamples (sample .name , Type .GAUGE , getHelpMessage (dropwizardName , gauge ), Arrays .asList (sample ));
114
+ return null ;
110
115
}
111
116
112
117
/**
0 commit comments