#35 springboot: custom metric - counter
This commit is contained in:
@@ -1,13 +1,15 @@
|
||||
package hello;
|
||||
|
||||
import hello.order.v0.OrderConfigV0;
|
||||
import hello.order.v1.OrderConfigV1;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.actuate.web.exchanges.InMemoryHttpExchangeRepository;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
@Import(OrderConfigV0.class)
|
||||
//@Import(OrderConfigV0.class)
|
||||
@Import(OrderConfigV1.class)
|
||||
@SpringBootApplication(scanBasePackages = "hello.controller")
|
||||
public class ActuatorApplication {
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ public class OrderServiceV0 implements OrderService {
|
||||
@Override
|
||||
public void cancel() {
|
||||
log.info("취소");
|
||||
stock.decrementAndGet();
|
||||
stock.incrementAndGet();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package hello.order.v1;
|
||||
|
||||
import hello.order.OrderService;
|
||||
import hello.order.v0.OrderServiceV0;
|
||||
import io.micrometer.core.instrument.MeterRegistry;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
public class OrderConfigV1 {
|
||||
|
||||
@Bean
|
||||
OrderService orderService(MeterRegistry registry) {
|
||||
return new OrderServiceV1(registry);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package hello.order.v1;
|
||||
|
||||
import hello.order.OrderService;
|
||||
import io.micrometer.core.instrument.Counter;
|
||||
import io.micrometer.core.instrument.MeterRegistry;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
public class OrderServiceV1 implements OrderService {
|
||||
|
||||
private final MeterRegistry registry;
|
||||
|
||||
private final AtomicInteger stock = new AtomicInteger(100);
|
||||
|
||||
@Override
|
||||
public void order() {
|
||||
log.info("주문");
|
||||
stock.decrementAndGet();
|
||||
|
||||
Counter.builder("my.order")
|
||||
.tag("class", this.getClass().getName())
|
||||
.tag("method", "order")
|
||||
.description("order")
|
||||
.register(registry)
|
||||
.increment();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancel() {
|
||||
log.info("취소");
|
||||
stock.incrementAndGet();
|
||||
|
||||
Counter.builder("my.order")
|
||||
.tag("class", this.getClass().getName())
|
||||
.tag("method", "cancel")
|
||||
.description("order")
|
||||
.register(registry)
|
||||
.increment();
|
||||
}
|
||||
|
||||
@Override
|
||||
public AtomicInteger getStock() {
|
||||
return stock;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user