package com.tzy.config;

import io.micrometer.core.instrument.Clock;
import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.logging.LoggingMeterRegistry;
import io.micrometer.core.instrument.logging.LoggingRegistryConfig;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.actuate.autoconfigure.metrics.MeterRegistryCustomizer;
import org.springframework.context.annotation.Bean;

import java.time.Duration;

//@Configuration
class MetricsConfig {
    @Bean
    public LoggingMeterRegistry loggingMeterRegistry() {

        return new LoggingMeterRegistry(new LoggingRegistryConfig() {
            @Override
            public Duration step() {
                return Duration.ofSeconds(30);//300秒输出一次
            }

            @Override
            public String get(String key) {
                return null;
            }
        }, Clock.SYSTEM);
    }


    @Bean
    public MeterRegistryCustomizer<MeterRegistry> configurer(@Value("${tzy.name}") String applicationName) {
        return (registry) -> registry.config().commonTags("application", applicationName);
    }
}