Skip to content

Commit

Permalink
Format PrometheusMetricsCollector
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcardell committed Jan 11, 2023
1 parent 724e6b3 commit e475335
Showing 1 changed file with 96 additions and 96 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,150 +13,150 @@

public class PrometheusMetricsCollector extends AbstractMetricsCollector {

private final Gauge connections;
private final Gauge connections;

private final Gauge channels;
private final Gauge channels;

private final Counter publishedMessages;
private final Counter publishedMessages;

private final Counter failedToPublishMessages;
private final Counter failedToPublishMessages;

private final Counter ackedPublishedMessages;
private final Counter ackedPublishedMessages;

private final Counter nackedPublishedMessages;
private final Counter nackedPublishedMessages;

private final Counter unroutedPublishedMessages;
private final Counter unroutedPublishedMessages;

private final Counter consumedMessages;
private final Counter consumedMessages;

private final Counter acknowledgedMessages;
private final Counter acknowledgedMessages;

private final Counter rejectedMessages;
private final Counter rejectedMessages;

public PrometheusMetricsCollector(final CollectorRegistry registry) {
this(registry, "rabbitmq");
}
public PrometheusMetricsCollector(final CollectorRegistry registry) {
this(registry, "rabbitmq");
}

public PrometheusMetricsCollector(final CollectorRegistry registry, final String prefix) {
this.connections = Gauge.build()
public PrometheusMetricsCollector(final CollectorRegistry registry, final String prefix) {
this.connections = Gauge.build()
.name(prefix + "_connections")
.help("Current connections")
.create();
registry.register(this.connections);
registry.register(this.connections);

this.channels = Gauge.build()
this.channels = Gauge.build()
.name(prefix + "_channels")
.help("Current channels")
.create();
registry.register(this.channels);
registry.register(this.channels);

this.publishedMessages = Counter.build()
this.publishedMessages = Counter.build()
.name(prefix + "_published_messages")
.help("Count of published messages")
.create();
registry.register(this.publishedMessages);
registry.register(this.publishedMessages);

this.failedToPublishMessages = Counter.build()
this.failedToPublishMessages = Counter.build()
.name(prefix + "_failed_to_publish_messages")
.help("Count of failed to publish messages")
.create();
registry.register(failedToPublishMessages);
registry.register(failedToPublishMessages);

this.ackedPublishedMessages = Counter.build()
this.ackedPublishedMessages = Counter.build()
.name(prefix + "_acked_published_messages")
.help("Count of acknowledged publish messages")
.create();
registry.register(ackedPublishedMessages);
registry.register(ackedPublishedMessages);

this.nackedPublishedMessages = Counter.build()
this.nackedPublishedMessages = Counter.build()
.name(prefix + "_nacked_published_messages")
.help("Count of not acknowledged publish messages")
.create();
registry.register(nackedPublishedMessages);
registry.register(nackedPublishedMessages);

this.unroutedPublishedMessages = Counter.build()
this.unroutedPublishedMessages = Counter.build()
.name(prefix + "_unrouted_published_messages")
.help("Count of unrouted publish messages")
.create();
registry.register(unroutedPublishedMessages);
registry.register(unroutedPublishedMessages);

this.consumedMessages = Counter.build()
this.consumedMessages = Counter.build()
.name(prefix + "_consumed_messages")
.help("Count of consumed messages")
.create();
registry.register(consumedMessages);
registry.register(consumedMessages);

this.acknowledgedMessages = Counter.build()
this.acknowledgedMessages = Counter.build()
.name(prefix + "_acknowledged_messages")
.help("Count of acknowledged consumed messages")
.create();
registry.register(acknowledgedMessages);
registry.register(acknowledgedMessages);

this.rejectedMessages = Counter.build()
this.rejectedMessages = Counter.build()
.name(prefix + "_rejected_messages")
.help("Count of rejected consumed messages")
.create();
registry.register(rejectedMessages);

}

@Override
protected void incrementConnectionCount(Connection connection) {
connections.inc();
}

@Override
protected void decrementConnectionCount(Connection connection) {
connections.dec();
}

@Override
protected void incrementChannelCount(Channel channel) {
channels.inc();
}

@Override
protected void decrementChannelCount(Channel channel) {
channels.dec();
}

@Override
protected void markPublishedMessage() {
publishedMessages.inc();
}

@Override
protected void markMessagePublishFailed() {
failedToPublishMessages.inc();
}

@Override
protected void markConsumedMessage() {
consumedMessages.inc();
}

@Override
protected void markAcknowledgedMessage() {
acknowledgedMessages.inc();
}

@Override
protected void markRejectedMessage() {
rejectedMessages.inc();
}

@Override
protected void markMessagePublishAcknowledged() {
ackedPublishedMessages.inc();
}

@Override
protected void markMessagePublishNotAcknowledged() {
nackedPublishedMessages.inc();
}

@Override
protected void markPublishedMessageUnrouted() {
unroutedPublishedMessages.inc();
}
registry.register(rejectedMessages);

}

@Override
protected void incrementConnectionCount(Connection connection) {
connections.inc();
}

@Override
protected void decrementConnectionCount(Connection connection) {
connections.dec();
}

@Override
protected void incrementChannelCount(Channel channel) {
channels.inc();
}

@Override
protected void decrementChannelCount(Channel channel) {
channels.dec();
}

@Override
protected void markPublishedMessage() {
publishedMessages.inc();
}

@Override
protected void markMessagePublishFailed() {
failedToPublishMessages.inc();
}

@Override
protected void markConsumedMessage() {
consumedMessages.inc();
}

@Override
protected void markAcknowledgedMessage() {
acknowledgedMessages.inc();
}

@Override
protected void markRejectedMessage() {
rejectedMessages.inc();
}

@Override
protected void markMessagePublishAcknowledged() {
ackedPublishedMessages.inc();
}

@Override
protected void markMessagePublishNotAcknowledged() {
nackedPublishedMessages.inc();
}

@Override
protected void markPublishedMessageUnrouted() {
unroutedPublishedMessages.inc();
}
}

0 comments on commit e475335

Please sign in to comment.