|
@@ -11,22 +11,23 @@ import io.prometheus.client.GaugeMetricFamily;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Arrays;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.util.*;
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
import java.util.concurrent.ConcurrentMap;
|
|
|
|
|
|
+import static com.alibaba.otter.canal.prometheus.CanalInstanceExports.DEST_LABELS_LIST;
|
|
|
+
|
|
|
/**
|
|
|
* @author Chuanyi Li
|
|
|
*/
|
|
|
public class MetaCollector extends Collector implements InstanceRegistry {
|
|
|
|
|
|
- private static final List<String> InfoLabel = Arrays.asList("destination", "mode");
|
|
|
+ private static final List<String> INFO_LABELS_LIST = Arrays.asList("destination", "mode");
|
|
|
private static final Logger logger = LoggerFactory.getLogger(MetaCollector.class);
|
|
|
- private static final String SUBSCRIPTION = "canal_instance";
|
|
|
- private static final String SUBSCRIPTION_HELP = "Canal instance";
|
|
|
+ private static final String INSTANCE = "canal_instance";
|
|
|
+ private static final String INSTANCE_HELP = "Canal instance";
|
|
|
+ private static final String SUBSCRIPTION = "canal_instance_subscriptions";
|
|
|
+ private static final String SUBSCRIPTION_HELP = "Canal instance subscriptions";
|
|
|
private final ConcurrentMap<String, MetaMetricsHolder> instances = new ConcurrentHashMap<String, MetaMetricsHolder>();
|
|
|
|
|
|
private MetaCollector() {}
|
|
@@ -42,18 +43,20 @@ public class MetaCollector extends Collector implements InstanceRegistry {
|
|
|
@Override
|
|
|
public List<MetricFamilySamples> collect() {
|
|
|
List<MetricFamilySamples> mfs = new ArrayList<MetricFamilySamples>();
|
|
|
- GaugeMetricFamily instanceInfo = new GaugeMetricFamily(
|
|
|
- SUBSCRIPTION,
|
|
|
- SUBSCRIPTION_HELP,
|
|
|
- InfoLabel);
|
|
|
+ GaugeMetricFamily instanceInfo = new GaugeMetricFamily(INSTANCE,
|
|
|
+ INSTANCE_HELP, INFO_LABELS_LIST);
|
|
|
+ GaugeMetricFamily subsInfo = new GaugeMetricFamily(SUBSCRIPTION,
|
|
|
+ SUBSCRIPTION_HELP, DEST_LABELS_LIST);
|
|
|
for (Map.Entry<String, MetaMetricsHolder> nme : instances.entrySet()) {
|
|
|
final String destination = nme.getKey();
|
|
|
final MetaMetricsHolder nmh = nme.getValue();
|
|
|
+ instanceInfo.addMetric(nmh.infoLabelValues, 1);
|
|
|
List<ClientIdentity> subs = nmh.metaManager.listAllSubscribeInfo(destination);
|
|
|
int count = subs == null ? 0 : subs.size();
|
|
|
- instanceInfo.addMetric(nmh.infoLabelValues, count);
|
|
|
+ subsInfo.addMetric(nmh.destLabelValues, count);
|
|
|
}
|
|
|
mfs.add(instanceInfo);
|
|
|
+ mfs.add(subsInfo);
|
|
|
return mfs;
|
|
|
}
|
|
|
|
|
@@ -63,6 +66,7 @@ public class MetaCollector extends Collector implements InstanceRegistry {
|
|
|
MetaMetricsHolder holder = new MetaMetricsHolder();
|
|
|
String mode = (instance instanceof CanalInstanceWithSpring) ? "spring" : "manager";
|
|
|
holder.infoLabelValues = Arrays.asList(destination, mode);
|
|
|
+ holder.destLabelValues = Collections.singletonList(destination);
|
|
|
holder.metaManager = instance.getMetaManager();
|
|
|
Preconditions.checkNotNull(holder.metaManager);
|
|
|
MetaMetricsHolder old = instances.put(destination, holder);
|
|
@@ -79,6 +83,7 @@ public class MetaCollector extends Collector implements InstanceRegistry {
|
|
|
|
|
|
private class MetaMetricsHolder {
|
|
|
private List<String> infoLabelValues;
|
|
|
+ private List<String> destLabelValues;
|
|
|
private CanalMetaManager metaManager;
|
|
|
}
|
|
|
|