use of io.datarouter.util.duration.DatarouterDuration in project datarouter by hotpads.
the class JobWrapper method logSuccess.
protected void logSuccess() {
long startDelayMs = Duration.between(scheduledTime, tracker.getStartTime()).toMillis();
Duration elapsedTime = Duration.between(tracker.getStartTime(), tracker.getFinishTime());
jobCounters.duration(jobClass, elapsedTime);
Optional<Instant> nextJobTriggerTime = jobPackage.getNextValidTimeAfter(Date.from(scheduledTime)).map(Date::toInstant);
String jobCompletionLog = "finished in " + new DatarouterDuration(elapsedTime) + " jobName=" + jobClass.getSimpleName() + " durationMs=" + elapsedTime.toMillis();
if (startDelayMs > 1000) {
jobCounters.startedAfterLongDelay(jobClass);
jobCompletionLog += " startDelayMs= " + startDelayMs;
}
if (nextJobTriggerTime.isPresent() && Instant.now().isAfter(nextJobTriggerTime.get())) {
jobCounters.missedNextTrigger(jobClass);
jobCompletionLog += " missed next trigger";
}
if (ComparableTool.gt(elapsedTime, Duration.ofHours(3))) {
logger.warn("long-running job " + jobCompletionLog);
} else if (ComparableTool.gt(elapsedTime, Duration.ofMillis(500))) {
logger.warn(jobCompletionLog);
} else {
logger.info(jobCompletionLog);
}
}
use of io.datarouter.util.duration.DatarouterDuration in project datarouter by hotpads.
the class WebappInstanceAlertJob method run.
@Override
public void run(TaskTracker tracker) {
WebappInstance webappInstance = webappInstanceService.buildCurrentWebappInstance();
Instant build = webappInstance.getBuildInstant();
DatarouterDuration buildAge = DatarouterDuration.age(build);
if (buildAge.isLongerThan(settings.staleWebappInstanceThreshold.get())) {
sendEmail(webappInstance, buildAge);
}
}
use of io.datarouter.util.duration.DatarouterDuration in project datarouter by hotpads.
the class WebappInstanceAlertJob method makeContent.
private ContainerTag<?> makeContent(WebappInstance webappInstance, DatarouterDuration buildAge) {
ZoneId zoneId = defaultDistributionListZoneId.get();
var rows = List.of(new Twin<>("webapp", webappInstance.getKey().getWebappName()), new Twin<>("build date", ZonedDateFormatterTool.formatInstantWithZone(webappInstance.getBuildInstant(), zoneId)), new Twin<>("build age", buildAge.toString()), new Twin<>("startup date", ZonedDateFormatterTool.formatInstantWithZone(webappInstance.getStartupInstant(), zoneId)), new Twin<>("commitId", webappInstance.getCommitId()));
return new J2HtmlEmailTable<Twin<String>>().withColumn(new J2HtmlEmailTableColumn<>(null, row -> makeDivBoldRight(row.getLeft()))).withColumn(new J2HtmlEmailTableColumn<>(null, row -> text(row.getRight()))).build(rows);
}
use of io.datarouter.util.duration.DatarouterDuration in project datarouter by hotpads.
the class ResponseTool method sendJson.
public static void sendJson(HttpServletResponse response, String body) throws IOException {
response.setContentType(ResponseTool.CONTENT_TYPE_APPLICATION_JSON);
// close the writer before the trace to be able to include the close() duration in the measure
long start = System.currentTimeMillis();
try (var $ = TracerTool.startSpan("ResponseTool sendJson", TraceSpanGroupType.HTTP);
OutputStreamWriter writer = new OutputStreamWriter(response.getOutputStream(), StandardCharsets.UTF_8)) {
writer.append(body);
}
DatarouterDuration duration = DatarouterDuration.ageMs(start);
if (duration.isLongerThan(LOG_THRESHOLD)) {
logger.warn("duration={} durationMs={} size={} traceContext={}", duration, duration.toMillis(), body.length(), TracerTool.getCurrentTraceparent().orElse(null));
}
}
use of io.datarouter.util.duration.DatarouterDuration in project datarouter by hotpads.
the class WebappInstanceServersHandler method makeContent.
private ContainerTag<?> makeContent(Page<WebappInstanceLogDto> page, List<String> activeServerNames) {
var form = Bootstrap4PagerHtml.renderForm(page).withClass("mt-4");
var linkBar = Bootstrap4PagerHtml.renderLinkBar(page).withClass("mt-2");
ZoneId zoneId = getUserZoneId();
var table = new J2HtmlTable<WebappInstanceLogDto>().withClasses("sortable table table-sm table-striped my-4 border").withHtmlColumn("", row -> {
if (activeServerNames.contains(row.key.serverName)) {
if (row.shutdown.isEmpty()) {
return td();
}
if (row.shutdown.get().toEpochMilli() < System.currentTimeMillis()) {
return td();
}
return td(span("Active").withClass("badge badge-success"));
}
return td();
}).withColumn("Server Name", row -> row.key.serverName).withColumn("Private IP", row -> row.key.serverPrivateIp).withColumn("Build Date", row -> ZonedDateFormatterTool.formatInstantWithZone(row.key.buildDate, zoneId)).withColumn("Startup Range", row -> row.startup.map(date -> ZonedDateFormatterTool.formatInstantWithZone(date, zoneId)).orElse("unknown") + " - " + row.shutdown.map(date -> ZonedDateFormatterTool.formatInstantWithZone(date, zoneId)).orElse("unknown")).withColumn("Up Time", row -> {
if (row.startup.isEmpty() || row.shutdown.isEmpty()) {
return "unknown";
}
var duration = Duration.ofMillis(row.shutdown.get().toEpochMilli() - row.startup.get().toEpochMilli());
return new DatarouterDuration(duration).toString(TimeUnit.MINUTES);
}).build(page.rows);
return div(form, linkBar, table).withClass("container-fluid");
}
Aggregations