-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from CatoTH/integrate-prometheus
Prometheus integration
- Loading branch information
Showing
15 changed files
with
209 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
ANTRAGSGRUEN_INSTALLATIONS_0_ID=std | ||
ANTRAGSGRUEN_INSTALLATIONS_0_PUBLIC_KEY=MII... | ||
ANTRAGSGRUEN_WS_ORIGINS=http://*.antragsgruen.test | ||
ACTUATOR_USER=admin | ||
ACTUATOR_PASSWORD=admin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
global: | ||
scrape_interval: 10s | ||
|
||
scrape_configs: | ||
- job_name: 'prometheus' | ||
static_configs: | ||
- targets: | ||
- 'localhost:9090' | ||
|
||
- job_name: 'antragsgruen_live' | ||
metrics_path: /actuator/prometheus | ||
# https://github.com/prometheus/prometheus/issues/10554 - no support for environment variables | ||
basic_auth: | ||
username: admin | ||
password: admin | ||
static_configs: | ||
- targets: | ||
- 'live:8080' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
src/main/java/de/antragsgruen/live/metrics/ActiveWebsocketConnectionMetric.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package de.antragsgruen.live.metrics; | ||
|
||
import de.antragsgruen.live.multisite.ConsultationScope; | ||
import de.antragsgruen.live.websocket.TopicPermissionChecker; | ||
import io.micrometer.core.instrument.MeterRegistry; | ||
import io.micrometer.core.instrument.Tag; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.messaging.simp.user.SimpUserRegistry; | ||
import org.springframework.scheduling.annotation.Scheduled; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.List; | ||
import java.util.function.Function; | ||
import java.util.stream.Collectors; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Slf4j | ||
public class ActiveWebsocketConnectionMetric { | ||
private final SimpUserRegistry userRegistry; | ||
private final MeterRegistry registry; | ||
|
||
private static final String METRIC_NAME = "antragsgruen_live.ws.active_connections"; | ||
|
||
@Scheduled(fixedRateString = "${antragsgruen.metrics.interval.ms}") | ||
public void processGauge() { | ||
userRegistry.findSubscriptions(subscription -> true) | ||
.stream() | ||
.map(subscription -> TopicPermissionChecker.consultationScopeFromPathParts(subscription.getDestination().split("/"))) | ||
.collect(Collectors.groupingBy(Function.identity(), Collectors.counting())) | ||
.forEach(this::trackMetric); | ||
} | ||
|
||
private void trackMetric(ConsultationScope scope, Long subscribers) { | ||
log.debug("Logging active websocket metrics: " + scope + " - " + subscribers); | ||
|
||
registry.gauge( | ||
METRIC_NAME, | ||
List.of( | ||
Tag.of("installation", scope.installation()), | ||
Tag.of("site", scope.site()), | ||
Tag.of("consultation", scope.consultation()) | ||
), | ||
subscribers | ||
); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
src/main/java/de/antragsgruen/live/metrics/ReceivedRabbitMQMessagesMetric.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package de.antragsgruen.live.metrics; | ||
|
||
import de.antragsgruen.live.multisite.ConsultationScope; | ||
import io.micrometer.core.instrument.MeterRegistry; | ||
import io.micrometer.core.instrument.Tag; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.List; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Slf4j | ||
public class ReceivedRabbitMQMessagesMetric { | ||
private final MeterRegistry registry; | ||
|
||
private static final String METRIC_NAME = "antragsgruen_live.rabbitmq.msg_count"; | ||
|
||
private static final String TYPE_SPEECH = "speech"; | ||
private static final String TYPE_USER = "user"; | ||
|
||
public void onSpeechEvent(ConsultationScope scope) { | ||
this.receivedMessage(scope, TYPE_SPEECH); | ||
} | ||
|
||
public void onUserEvent(ConsultationScope scope) { | ||
this.receivedMessage(scope, TYPE_USER); | ||
} | ||
|
||
private void receivedMessage(ConsultationScope scope, String type) { | ||
log.debug("Logging RabbitMQ message count: " + scope + " - " + type); | ||
|
||
registry.counter(METRIC_NAME, List.of( | ||
Tag.of("installation", scope.installation()), | ||
Tag.of("site", scope.site()), | ||
Tag.of("consultation", scope.consultation()), | ||
Tag.of("type", type) | ||
)).increment(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
@NonNullApi | ||
@NonNullFields | ||
package de.antragsgruen.live.metrics; | ||
|
||
import org.springframework.lang.NonNullApi; | ||
import org.springframework.lang.NonNullFields; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.