// Path: src/main/java/no/cantara/cs/config/ConstrettoConfig.java
// public class ConstrettoConfig {
// 	private static final ConstrettoConfiguration configuration = new ConstrettoBuilder()
//             .createPropertiesStore()
//             .addResource(Resource.create("classpath:application.properties"))
//             .addResource(Resource.create("file:./config_override/application_override.properties"))
//             .done()
//             .getConfiguration();
// 	
// 	private ConstrettoConfig() {}
// 	
// 	public static String getString(String key) {
// 		return configuration.evaluateToString(key);
// 	}
// 	
// 	public static Integer getInt(String key) {
// 		return configuration.evaluateToInt(key);
// 	}
// 
// 	public static Integer getInt(String key, int defaultValue) {
// 		return configuration.evaluateTo(key, defaultValue);
// 	}
// 
// 	public static boolean getBoolean(String key) {
// 		return configuration.evaluateToBoolean(key);
// 	}
// }


import com.amazonaws.regions.Region;
import com.amazonaws.regions.Regions;
import com.amazonaws.services.cloudwatch.AmazonCloudWatch;
import com.amazonaws.services.cloudwatch.AmazonCloudWatchClient;
import com.amazonaws.services.cloudwatch.model.Dimension;
import com.amazonaws.services.cloudwatch.model.MetricDatum;
import com.amazonaws.services.cloudwatch.model.PutMetricDataRequest;
import com.amazonaws.services.cloudwatch.model.StandardUnit;
import no.cantara.cs.config.ConstrettoConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ConcurrentSkipListMap;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
package no.cantara.cs.cloudwatch;



/**
 * Publishes custom metrics to Amazon CloudWatch.
 * <p>
 * Currently the only metric published is the number of heartbeats received per client.
 * <p>
 * Uses the following configuration properties:
 * <ul>
 * <li>cloudwatch.metrics.enabled - Whether Amazon CloudWatch metrics publishing is enabled.</li>
 * <li>cloudwatch.region - The AWS region to use, e.g., "eu-west-1".</li>
 * <li>cloudwatch.metrics.namespace - The namespace to use for custom CloudWatch metrics.</li>
 * <li>cloudwatch.metrics.intervalSeconds - How often to publish metrics.</li>
 * </ul>
 *
 * @author Sindre Mehus
 */
@Service
public class CloudWatchMetricsPublisher {

    private static final Logger log = LoggerFactory.getLogger(CloudWatchMetricsPublisher.class);

    private final ConcurrentMap<String, Integer> heartbeats = new ConcurrentSkipListMap<>();
    private AmazonCloudWatch awsClient;
    private String namespace;

    public CloudWatchMetricsPublisher() {
// Path: src/main/java/no/cantara/cs/config/ConstrettoConfig.java
// public class ConstrettoConfig {
// 	private static final ConstrettoConfiguration configuration = new ConstrettoBuilder()
//             .createPropertiesStore()
//             .addResource(Resource.create("classpath:application.properties"))
//             .addResource(Resource.create("file:./config_override/application_override.properties"))
//             .done()
//             .getConfiguration();
// 	
// 	private ConstrettoConfig() {}
// 	
// 	public static String getString(String key) {
// 		return configuration.evaluateToString(key);
// 	}
// 	
// 	public static Integer getInt(String key) {
// 		return configuration.evaluateToInt(key);
// 	}
// 
// 	public static Integer getInt(String key, int defaultValue) {
// 		return configuration.evaluateTo(key, defaultValue);
// 	}
// 
// 	public static boolean getBoolean(String key) {
// 		return configuration.evaluateToBoolean(key);
// 	}
// }


// Path: src/main/java/no/cantara/cs/cloudwatch/CloudWatchMetricsPublisher.java
import com.amazonaws.regions.Region;
import com.amazonaws.regions.Regions;
import com.amazonaws.services.cloudwatch.AmazonCloudWatch;
import com.amazonaws.services.cloudwatch.AmazonCloudWatchClient;
import com.amazonaws.services.cloudwatch.model.Dimension;
import com.amazonaws.services.cloudwatch.model.MetricDatum;
import com.amazonaws.services.cloudwatch.model.PutMetricDataRequest;
import com.amazonaws.services.cloudwatch.model.StandardUnit;
import no.cantara.cs.config.ConstrettoConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ConcurrentSkipListMap;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

package no.cantara.cs.cloudwatch;



/**
 * Publishes custom metrics to Amazon CloudWatch.
 * <p>
 * Currently the only metric published is the number of heartbeats received per client.
 * <p>
 * Uses the following configuration properties:
 * <ul>
 * <li>cloudwatch.metrics.enabled - Whether Amazon CloudWatch metrics publishing is enabled.</li>
 * <li>cloudwatch.region - The AWS region to use, e.g., "eu-west-1".</li>
 * <li>cloudwatch.metrics.namespace - The namespace to use for custom CloudWatch metrics.</li>
 * <li>cloudwatch.metrics.intervalSeconds - How often to publish metrics.</li>
 * </ul>
 *
 * @author Sindre Mehus
 */
@Service
public class CloudWatchMetricsPublisher {

    private static final Logger log = LoggerFactory.getLogger(CloudWatchMetricsPublisher.class);

    private final ConcurrentMap<String, Integer> heartbeats = new ConcurrentSkipListMap<>();
    private AmazonCloudWatch awsClient;
    private String namespace;

    public CloudWatchMetricsPublisher() {
        if (ConstrettoConfig.getBoolean("cloudwatch.metrics.enabled")) {