use of com.epam.pipeline.entity.monitoring.IdleRunAction in project cloud-pipeline by epam.
the class ResourceMonitoringManager method monitorResourceUsage.
public void monitorResourceUsage() {
int idleTimeout = preferenceManager.getPreference(SYSTEM_MAX_IDLE_TIMEOUT_MINUTES);
Map<String, PipelineRun> running = pipelineRunManager.loadRunningPipelineRuns().stream().filter(r -> DateUtils.nowUTC().isAfter(r.getProlongedAtTime().plus(idleTimeout, ChronoUnit.MINUTES))).collect(Collectors.toMap(PipelineRun::getPodId, r -> r));
LOGGER.debug("Checking cpu stats for pipelines: " + running.keySet().stream().collect(Collectors.joining(", ")));
LocalDateTime now = DateUtils.nowUTC();
Map<String, Double> cpuMetrics = monitoringDao.loadCpuUsageRateMetrics(running.keySet(), now.minusMinutes(idleTimeout), now);
LOGGER.debug("CPU Metrics received: " + cpuMetrics.entrySet().stream().map(e -> e.getKey() + ":" + e.getValue()).collect(Collectors.joining(", ")));
double idleCpuLevel = preferenceManager.getPreference(SYSTEM_IDLE_CPU_THRESHOLD_PERCENT) / PERCENT;
int actionTimeout = preferenceManager.getPreference(SYSTEM_IDLE_ACTION_TIMEOUT_MINUTES);
IdleRunAction action = IdleRunAction.valueOf(preferenceManager.getPreference(SystemPreferences.SYSTEM_IDLE_ACTION));
List<PipelineRun> runsToUpdate = processRuns(running, cpuMetrics, idleCpuLevel, actionTimeout, action);
pipelineRunManager.updatePipelineRunsLastNotification(runsToUpdate);
}
Aggregations