-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
118 additions
and
4 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
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
49 changes: 49 additions & 0 deletions
49
app/src/main/java/com/github/bsideup/liiklus/monitoring/MetricsCollector.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,49 @@ | ||
package com.github.bsideup.liiklus.monitoring; | ||
|
||
import com.github.bsideup.liiklus.positions.PositionsStorage; | ||
import io.prometheus.client.Collector; | ||
import io.prometheus.client.CollectorRegistry; | ||
import io.prometheus.client.GaugeMetricFamily; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.experimental.FieldDefaults; | ||
import lombok.extern.slf4j.Slf4j; | ||
import lombok.val; | ||
import org.springframework.stereotype.Component; | ||
import reactor.core.publisher.Flux; | ||
|
||
import javax.annotation.PostConstruct; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
@FieldDefaults(makeFinal = true) | ||
@Slf4j | ||
public class MetricsCollector extends Collector { | ||
|
||
CollectorRegistry collectorRegistry; | ||
|
||
PositionsStorage positionsStorage; | ||
|
||
@PostConstruct | ||
public void init() { | ||
// TODO use MicroMeter abstractions | ||
collectorRegistry.register(this); | ||
} | ||
|
||
@Override | ||
public List<MetricFamilySamples> collect() { | ||
return Flux.from(positionsStorage.findAll()) | ||
.<MetricFamilySamples>map(positions -> { | ||
val gauge = new GaugeMetricFamily("liiklus_topic_position", "", Arrays.asList("topic", "groupId", "partition")); | ||
|
||
for (val entry : positions.getValues().entrySet()) { | ||
gauge.addMetric(Arrays.asList(positions.getTopic(), positions.getGroupId(), entry.getKey().toString()), entry.getValue().doubleValue()); | ||
} | ||
|
||
return gauge; | ||
}) | ||
.collectList() | ||
.block(); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -3,4 +3,8 @@ spring: | |
enabled: false | ||
|
||
cache: | ||
type: NONE | ||
type: NONE | ||
|
||
endpoints: | ||
prometheus: | ||
sensitive: false |
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