Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default Metrics collection (Spring Boot) #145

Closed
bitzl opened this issue Apr 2, 2020 · 0 comments
Closed

Default Metrics collection (Spring Boot) #145

bitzl opened this issue Apr 2, 2020 · 0 comments

Comments

@bitzl
Copy link
Member

bitzl commented Apr 2, 2020

To monitor a Flusswerk applications performance Flow has a metrics callback that calls a Consumer<FlowStatus>. Most Spring Boot based applications will have the same implementation of a Metrics class using the Micrometer library or extend a similar Metrics implementation...

The Spring Boot Starter should provide a default Metrics implementation that can be overridden by defining a custom Metrics bean.

Example

public class Metrics implements Consumer<FlowStatus> {

  private final Map<Status, Counter> executionTime;
  private final Map<Status, Counter> processedItems;

  public Metrics(MeterFactory meterFactory) {
    this.executionTime = new EnumMap<>(Status.class);
    this.processedItems = new EnumMap<>(Status.class);

    for (Status status : Status.values()) {
      processedItems.put(status, meterFactory.counter("processed.items", status));
      executionTime.put(status, meterFactory.counter("execution.time", status));
    }
  }

  public void accept(FlowStatus flowStatus) {
    var status = flowStatus.getStatus();
    processedItems.get(status).increment();
    executionTime.get(status).increment(flowStatus.duration());
  }
}
@bitzl bitzl closed this as completed Jun 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant