use of io.codekvast.dashboard.dashboard.model.status.AgentDescriptor in project codekvast by crispab.
the class DashboardServiceImpl method getStatus.
@Override
@Transactional(readOnly = true)
public GetStatusResponse getStatus() {
long startedAt = clock.millis();
Long customerId = customerIdProvider.getCustomerId();
CustomerData customerData = customerService.getCustomerDataByCustomerId(customerId);
PricePlan pricePlan = customerData.getPricePlan();
List<EnvironmentStatusDescriptor> environments = getEnvironments(customerId);
List<ApplicationDescriptor2> applications = getApplications(customerId, pricePlan);
List<AgentDescriptor> agents = getAgents(customerId, pricePlan.getPublishIntervalSeconds());
Instant now = clock.instant();
Instant collectionStartedAt = customerData.getCollectionStartedAt();
Instant trialPeriodEndsAt = customerData.getTrialPeriodEndsAt();
Duration trialPeriodDuration = collectionStartedAt == null || trialPeriodEndsAt == null ? null : Duration.between(collectionStartedAt, trialPeriodEndsAt);
Duration trialPeriodProgress = trialPeriodDuration == null ? null : Duration.between(collectionStartedAt, now);
Integer trialPeriodPercent = trialPeriodProgress == null ? null : Math.min(100, Math.toIntExact(trialPeriodProgress.toMillis() * 100L / trialPeriodDuration.toMillis()));
return GetStatusResponse.builder().timestamp(startedAt).queryTimeMillis(clock.millis() - startedAt).pricePlan(pricePlan.getName()).retentionPeriodDays(pricePlan.getRetentionPeriodDays()).collectionResolutionSeconds(pricePlan.getPublishIntervalSeconds()).maxNumberOfAgents(pricePlan.getMaxNumberOfAgents()).maxNumberOfMethods(pricePlan.getMaxMethods()).collectedSinceMillis(pricePlan.adjustInstantToMillis(collectionStartedAt, clock)).trialPeriodEndsAtMillis(trialPeriodEndsAt == null ? null : trialPeriodEndsAt.toEpochMilli()).trialPeriodExpired(customerData.isTrialPeriodExpired(now)).trialPeriodPercent(trialPeriodPercent).numMethods(customerService.countMethods(customerId)).numAgents(agents.size()).numLiveAgents((int) agents.stream().filter(AgentDescriptor::isAgentAlive).count()).numLiveEnabledAgents((int) agents.stream().filter(AgentDescriptor::isAgentLiveAndEnabled).count()).environments(environments).applications(applications).agents(agents).build();
}
use of io.codekvast.dashboard.dashboard.model.status.AgentDescriptor in project codekvast by crispab.
the class DashboardServiceImpl method getAgents.
private List<AgentDescriptor> getAgents(Long customerId, int publishIntervalSeconds) {
val startedAt = clock.instant();
List<AgentDescriptor> result = new ArrayList<>();
jdbcTemplate.query("SELECT agent_state.id AS agentId, agent_state.enabled, agent_state.lastPolledAt, agent_state.nextPollExpectedAt, jvms.id AS " + "jvmId,\n" + " jvms.startedAt, jvms.publishedAt, jvms.methodVisibility, jvms.packages, jvms.excludePackages, jvms.hostname, jvms" + ".agentVersion,\n" + " jvms.tags, jvms.applicationVersion AS appVersion, applications.name AS appName, environments.name AS envName\n" + "FROM agent_state, jvms, applications, environments\n" + "WHERE jvms.customerId = ? AND jvms.uuid = agent_state.jvmUuid AND jvms.applicationId = applications.id AND\n" + " jvms.environmentId = environments.id AND jvms.garbage = FALSE AND agent_state.garbage = FALSE\n" + "ORDER BY jvms.id ", rs -> {
Timestamp lastPolledAt = rs.getTimestamp("lastPolledAt");
Timestamp nextPollExpectedAt = rs.getTimestamp("nextPollExpectedAt");
Timestamp publishedAt = rs.getTimestamp("publishedAt");
boolean isAlive = nextPollExpectedAt != null && nextPollExpectedAt.after(Timestamp.from(clock.instant().minusSeconds(60)));
Instant nextPublicationExpectedAt = lastPolledAt.toInstant().plusSeconds(publishIntervalSeconds);
result.add(AgentDescriptor.builder().agentId(rs.getLong("agentId")).agentAlive(isAlive).agentLiveAndEnabled(isAlive && rs.getBoolean("enabled")).agentVersion(rs.getString("agentVersion")).appName(rs.getString("appName")).appVersion(rs.getString("appVersion")).environment(rs.getString("envName")).excludePackages(rs.getString("excludePackages")).jvmId(rs.getLong("jvmId")).hostname(rs.getString("hostname")).methodVisibility(rs.getString("methodVisibility")).nextPublicationExpectedAtMillis(nextPublicationExpectedAt.toEpochMilli()).nextPollExpectedAtMillis(nextPollExpectedAt.getTime()).packages(rs.getString("packages")).pollReceivedAtMillis(lastPolledAt.getTime()).publishedAtMillis(publishedAt.getTime()).startedAtMillis(rs.getTimestamp("startedAt").getTime()).tags(rs.getString("tags")).build());
}, customerId);
logger.debug("Fetched {} agents for customer {} in {}", result.size(), customerId, Duration.between(startedAt, clock.instant()));
return result;
}
Aggregations