|
@@ -20,68 +20,60 @@ public class PrometheusClientInstanceProfiler implements ClientInstanceProfiler
|
|
|
private static final String EMPTY_BATCHES = "canal_instance_client_empty_batches";
|
|
|
private static final String ERRORS = "canal_instance_client_request_error";
|
|
|
private static final String LATENCY = "canal_instance_client_request_latency";
|
|
|
+ private final Counter outboundCounter;
|
|
|
+ private final Counter packetsCounter;
|
|
|
+ private final Counter emptyBatchesCounter;
|
|
|
+ private final Counter errorsCounter;
|
|
|
+ private final Histogram responseLatency;
|
|
|
private volatile boolean running = false;
|
|
|
- private final String destination;
|
|
|
- private final String[] destLabelValues;
|
|
|
- private final Counter outboundCounter;
|
|
|
- private final Counter packetsCounter;
|
|
|
- private final Counter emptyBatchesCounter;
|
|
|
- private final Counter errorsCounter;
|
|
|
- private final Histogram responseLatency;
|
|
|
|
|
|
- public PrometheusClientInstanceProfiler(String destination) {
|
|
|
- this.destination = destination;
|
|
|
- this.destLabelValues = new String[]{destination};
|
|
|
+ public PrometheusClientInstanceProfiler() {
|
|
|
this.outboundCounter = Counter.build()
|
|
|
.labelNames(DEST_LABELS)
|
|
|
.name(OUTBOUND_BYTES)
|
|
|
- .help("Send bytes to client of instance " + destination)
|
|
|
+ .help("Total bytes sent to client.")
|
|
|
.create();
|
|
|
this.packetsCounter = Counter.build()
|
|
|
.labelNames(new String[]{DEST, "packetType"})
|
|
|
.name(PACKET_TYPE)
|
|
|
- .help("Send packets to client of instance " + destination)
|
|
|
+ .help("Total packets sent to client.")
|
|
|
.create();
|
|
|
this.emptyBatchesCounter = Counter.build()
|
|
|
.labelNames(DEST_LABELS)
|
|
|
.name(EMPTY_BATCHES)
|
|
|
- .help("Send empty batches to client of instance " + destination)
|
|
|
+ .help("Total empty batches sent to client.")
|
|
|
.create();
|
|
|
this.errorsCounter = Counter.build()
|
|
|
.labelNames(new String[]{DEST, "errorCode"})
|
|
|
.name(ERRORS)
|
|
|
- .help("Client request errors of instance " + destination)
|
|
|
+ .help("Total client request errors.")
|
|
|
.create();
|
|
|
this.responseLatency = Histogram.build()
|
|
|
.labelNames(DEST_LABELS)
|
|
|
.name(LATENCY)
|
|
|
- .help("Client request latency of instance " + destination)
|
|
|
+ .help("Client request latency.")
|
|
|
// buckets in milliseconds
|
|
|
.buckets(1.0, 2.5, 5.0, 10.0, 25.0, 50.0, 100.0)
|
|
|
.create();
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public String getDestination() {
|
|
|
- return this.destination;
|
|
|
- }
|
|
|
-
|
|
|
@Override
|
|
|
public void profiling(ClientRequestResult result) {
|
|
|
+ String destination = result.getDestination();
|
|
|
PacketType type = result.getType();
|
|
|
- outboundCounter.labels(destLabelValues).inc(result.getAmount());
|
|
|
+ outboundCounter.labels(destination).inc(result.getAmount());
|
|
|
packetsCounter.labels(destination, type.name()).inc();
|
|
|
short errorCode = result.getErrorCode();
|
|
|
if (errorCode > 0) {
|
|
|
errorsCounter.labels(destination, Short.toString(errorCode)).inc();
|
|
|
}
|
|
|
long latency = result.getLatency();
|
|
|
- responseLatency.labels(destLabelValues).observe(latency / 1000000);
|
|
|
+ responseLatency.labels(destination).observe(latency / 1000000);
|
|
|
switch (type) {
|
|
|
case GET:
|
|
|
boolean empty = result.getEmpty();
|
|
|
if (empty) {
|
|
|
- emptyBatchesCounter.labels(destLabelValues).inc();
|
|
|
+ emptyBatchesCounter.labels(destination).inc();
|
|
|
}
|
|
|
break;
|
|
|
// reserve for others
|
|
@@ -90,7 +82,8 @@ public class PrometheusClientInstanceProfiler implements ClientInstanceProfiler
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- @Override public void start() {
|
|
|
+ @Override
|
|
|
+ public void start() {
|
|
|
if (outboundCounter != null) {
|
|
|
outboundCounter.register();
|
|
|
}
|
|
@@ -109,7 +102,8 @@ public class PrometheusClientInstanceProfiler implements ClientInstanceProfiler
|
|
|
running = true;
|
|
|
}
|
|
|
|
|
|
- @Override public void stop() {
|
|
|
+ @Override
|
|
|
+ public void stop() {
|
|
|
running = false;
|
|
|
if (outboundCounter != null) {
|
|
|
CollectorRegistry.defaultRegistry.unregister(outboundCounter);
|
|
@@ -128,7 +122,8 @@ public class PrometheusClientInstanceProfiler implements ClientInstanceProfiler
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- @Override public boolean isStart() {
|
|
|
+ @Override
|
|
|
+ public boolean isStart() {
|
|
|
return running;
|
|
|
}
|
|
|
}
|