All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.hylexus.jt.dashboard.server.service.Jt1078ServerSimpleMetricsUpdater Maven / Gradle / Ivy

The newest version!
package io.github.hylexus.jt.dashboard.server.service;

import io.github.hylexus.jt.dashboard.common.consts.JtDashboardConstants;
import io.github.hylexus.jt.dashboard.server.model.values.instance.JtInstance;
import io.github.hylexus.jt.dashboard.server.proxy.DashboardWebClient;
import io.github.hylexus.jt.dashboard.server.registry.Jt1078InstanceRegistry;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.ParameterizedTypeReference;
import reactor.core.publisher.Mono;

import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;

/**
 * 这个类是从 spring-boot-admin 中复制过来修改的。
 * 

* 这个类是从 spring-boot-admin 中复制过来修改的。 *

* 这个类是从 spring-boot-admin 中复制过来修改的。 * * @see https://github.com/codecentric/spring-boot-admin * @see de.codecentric.boot.admin.server.services.StatusUpdater */ @Slf4j public class Jt1078ServerSimpleMetricsUpdater { private final Jt1078InstanceRegistry instanceRegistry; private final DashboardWebClient dashboardWebClient; public Jt1078ServerSimpleMetricsUpdater(Jt1078InstanceRegistry instanceRegistry, DashboardWebClient.Builder builder) { this.instanceRegistry = instanceRegistry; this.dashboardWebClient = builder.build(); } public Mono updateMetrics(String id) { return this.instanceRegistry.getInstance(id).map(this::doUpdateMetrics).orElseGet(Mono::empty); } protected Mono doUpdateMetrics(JtInstance instance) { log.debug("Update status for {}", instance); return this.dashboardWebClient.mutateForInstance(instance) .get() .uri("/actuator/jt1078SimpleMetrics") .retrieve().bodyToMono(new ParameterizedTypeReference>() { }) .doOnNext(resp -> { log.debug("res: {}", resp); resp.putIfAbsent("updatedAt", JtDashboardConstants.YYYY_MM_DD_HH_MM_SS_SSS.format(LocalDateTime.now())); instance.setMetrics(resp); }) .log(log.getName(), Level.FINEST) .doOnError((ex) -> log.error(ex.getMessage(), ex)) .onErrorResume(this::handleError) .then(); } protected Mono> handleError(Throwable ex) { Map details = new HashMap<>(); details.put("message", ex.getMessage()); details.put("exception", ex.getClass().getName()); return Mono.just(details); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy