52
52
import org .apache .inlong .dataproxy .metrics .DataProxyMetricItem ;
53
53
import org .apache .inlong .dataproxy .metrics .MetricItemValue ;
54
54
import org .apache .inlong .dataproxy .metrics .MetricListener ;
55
+ import org .slf4j .Logger ;
56
+ import org .slf4j .LoggerFactory ;
55
57
56
58
import io .prometheus .client .Collector ;
57
59
import io .prometheus .client .CounterMetricFamily ;
58
60
import io .prometheus .client .exporter .HTTPServer ;
59
- import org .slf4j .Logger ;
60
- import org .slf4j .LoggerFactory ;
61
61
62
62
/**
63
63
*
@@ -70,10 +70,9 @@ public class PrometheusMetricListener extends Collector implements MetricListene
70
70
public static final int DEFAULT_PROMETHEUS_HTTP_PORT = 8080 ;
71
71
public static final String DEFAULT_DIMENSION_LABEL = "dimension" ;
72
72
73
- //
73
+ private String metricName ;
74
74
private DataProxyMetricItem metricItem ;
75
75
private Map <String , AtomicLong > metricValueMap = new ConcurrentHashMap <>();
76
- private String metricName ;
77
76
protected HTTPServer httpServer ;
78
77
private Map <String , MetricItemValue > dimensionMetricValueMap = new ConcurrentHashMap <>();
79
78
private List <String > dimensionKeys = new ArrayList <>();
@@ -82,19 +81,20 @@ public class PrometheusMetricListener extends Collector implements MetricListene
82
81
* Constructor
83
82
*/
84
83
public PrometheusMetricListener () {
84
+ this .metricName = CommonPropertiesHolder .getString (RemoteConfigManager .KEY_PROXY_CLUSTER_NAME );
85
85
this .metricItem = new DataProxyMetricItem ();
86
- this .metricItem .clusterId = CommonPropertiesHolder . getString ( RemoteConfigManager . KEY_PROXY_CLUSTER_NAME ) ;
86
+ this .metricItem .clusterId = metricName ;
87
87
final MBeanServer mbs = ManagementFactory .getPlatformMBeanServer ();
88
88
StringBuilder beanName = new StringBuilder ();
89
- beanName .append (JMX_DOMAIN ).append (DOMAIN_SEPARATOR ).append ("type=DataProxyCounter " );
90
- this . metricName = beanName .toString ();
89
+ beanName .append (JMX_DOMAIN ).append (DOMAIN_SEPARATOR ).append ("type=DataProxyPrometheus " );
90
+ String strBeanName = beanName .toString ();
91
91
try {
92
- ObjectName objName = new ObjectName (metricName );
92
+ ObjectName objName = new ObjectName (strBeanName );
93
93
mbs .registerMBean (metricItem , objName );
94
94
} catch (Exception ex ) {
95
- LOG .error ("exception while register mbean:{},error:{}" , metricName , ex . getMessage () );
95
+ LOG .error ("exception while register mbean:{},error:{}" , strBeanName , ex );
96
96
}
97
- //
97
+ // prepare metric value map
98
98
metricValueMap .put (M_READ_SUCCESS_COUNT , metricItem .readSuccessCount );
99
99
metricValueMap .put (M_READ_SUCCESS_SIZE , metricItem .readSuccessSize );
100
100
metricValueMap .put (M_READ_FAIL_COUNT , metricItem .readFailCount );
@@ -115,6 +115,7 @@ public PrometheusMetricListener() {
115
115
int httpPort = CommonPropertiesHolder .getInteger (KEY_PROMETHEUS_HTTP_PORT , DEFAULT_PROMETHEUS_HTTP_PORT );
116
116
try {
117
117
this .httpServer = new HTTPServer (httpPort );
118
+ this .register ();
118
119
} catch (IOException e ) {
119
120
LOG .error ("exception while register prometheus http server:{},error:{}" , metricName , e .getMessage ());
120
121
}
@@ -142,7 +143,7 @@ public void snapshot(String domain, List<MetricItemValue> itemValues) {
142
143
// id dimension
143
144
String dimensionKey = itemValue .getKey ();
144
145
MetricItemValue dimensionMetricValue = this .dimensionMetricValueMap .get (dimensionKey );
145
- if (dimensionKey == null ) {
146
+ if (dimensionMetricValue == null ) {
146
147
dimensionMetricValue = new MetricItemValue (dimensionKey , new ConcurrentHashMap <String , String >(),
147
148
new ConcurrentHashMap <String , MetricValue >());
148
149
this .dimensionMetricValueMap .putIfAbsent (dimensionKey , dimensionMetricValue );
@@ -202,7 +203,7 @@ public List<MetricFamilySamples> collect() {
202
203
203
204
// id dimension
204
205
CounterMetricFamily idCounter = new CounterMetricFamily (metricName + "&group=id" ,
205
- "The metrics of inlong dataflow ." , this .dimensionKeys );
206
+ "The metrics of inlong datastream ." , this .dimensionKeys );
206
207
for (Entry <String , MetricItemValue > entry : this .dimensionMetricValueMap .entrySet ()) {
207
208
MetricItemValue itemValue = entry .getValue ();
208
209
// read
0 commit comments