Skip to content

Instantly share code, notes, and snippets.

@ramesh-lingappan
Created July 9, 2020 15:51
Show Gist options
  • Save ramesh-lingappan/939a2faed2ed22ce7582bc820ffe465b to your computer and use it in GitHub Desktop.
Save ramesh-lingappan/939a2faed2ed22ce7582bc820ffe465b to your computer and use it in GitHub Desktop.
PushGateway HelloService
package com.example.prometheuspushgateway;
import io.micrometer.core.annotation.Timed;
import io.micrometer.core.instrument.Counter;
import io.micrometer.core.instrument.MeterRegistry;
import org.springframework.stereotype.Service;
@Service
public class HelloService {
private final Counter counter;
public HelloService(MeterRegistry meterRegistry) {
this.counter = meterRegistry.counter("hello.counter", "type", "hello");
}
@Timed(value = "hello-process", description = "Time spent processing hello", extraTags = {"type", "hello"})
public String getHello() {
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
counter.increment();
return "Hello, counter = " + counter.count();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment