Skip to content

Instantly share code, notes, and snippets.

@TharindaW
Last active September 1, 2021 06:56
Show Gist options
  • Save TharindaW/90b9c5358d828450574a81c5a24ac480 to your computer and use it in GitHub Desktop.
Save TharindaW/90b9c5358d828450574a81c5a24ac480 to your computer and use it in GitHub Desktop.
ApplicationMonitoring
dependencies {
implementation(
"io.micrometer:micrometer-core:${micrometerVersion}",
"io.micrometer:micrometer-registry-prometheus:${micrometerVersion}",
"org.springframework.boot:spring-boot-starter-actuator:${spring_boot_version}"
)
}
@Configuration
@EnableConfigurationProperties(CommonTags.class)
public class HubMetricsConfiguration {
@Bean
public MeterRegistryCustomizer<MeterRegistry> meterRegistryCustomizer( CommonTags tags ) {
return registry -> registry.config()
.commonTags("applicationInstance", tags.getInstanceId(),
"applicationName", tags.getApplicationName(),
"productGroup", tags.getProductGroup(),
"productName", tags.getProductName(),
"environment", tags.getServicedEnvironment());
}
@Bean
public TimedAspect timedAspect(MeterRegistry registry) {
return new TimedAspect(registry);
}
}
# HELP hub_task_seconds
# TYPE hub_task_seconds summary
hub_task_seconds_count{ applicationInstance="25005",applicationName="Hub",num_executions="0",
productGroup="integration",productName="Hub",servicedEnvironment="dev",type="OrderAssignedToLager",action="SyncBack" } 1.0
hub_task_seconds_sum {
applicationInstance="25005",
applicationName="Hub",
num_executions="0",
productGroup="integration",
productName="Hub",
servicedEnvironment="dev",
type="X"
action="SyncBack" } 1.786964501
private final MeterRegistry meterRegistry;
@Timed(
value = "hub.task.histo",
histogram = true,
percentiles = {0.5, 0.90, 0.95},
extraTags = {
"type", "all",
"action", "all"
}
)
public TaskExecution execute(Task task) {
task.setUuid(UUID.randomUUID());
TaskEntity domain = mapper.mapToDomain(task);
return meterRegistry.timer("hub.task",
"type", api.getType(),
"action", api.getAction(),
"num_executions", String.valueOf(domain.getNumExecutions()))
.record(() -> execute(task, domain.asRunning()));
}
private TaskExecution execute(Task api, TaskEntity domain) {
//Make your BL magic here
}
spring:
application:
name: Sync-Hub
management:
endpoints:
web:
exposure:
include: health,status,info,metrics,prometheus
metrics:
tags:
application: ${spring.application.name}
productGroup: integration
productName: Hub
servicedEnvironment: dev
enable:
tomcat: true
hikaricp: true
jvm: true
jvm.memory: true
jvm.gc.pause: true
jdbc: true
scrape_configs:
- job_name: Hub
honor_timestamps: true
scrape_interval: 5s
scrape_timeout: 5s
metrics_path: actuator/prometheus
scheme: http
static_configs:
- targets:
- localhost:25005
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment