Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CloudWatchMetricObserver not pushing metrics to CloudWatch #412

Closed
sobel003 opened this issue Mar 15, 2017 · 3 comments
Closed

CloudWatchMetricObserver not pushing metrics to CloudWatch #412

sobel003 opened this issue Mar 15, 2017 · 3 comments

Comments

@sobel003
Copy link

I followed the little documentation out there for using CloudWatchMetricObserver but I can't see my hystrix metrics pushed into CloudWatch. I'm pretty sure I may be missing something but not sure what it can be. This is my code;

@Configuration
@Profile("aws")
public class CloudWatchMetricsConfiguration {

    
    private static final Logger LOGGER = LoggerFactory.getLogger(CloudWatchMetricsConfiguration.class);
    
    private static final int MAGIC_NUMBER_FIVE = 5;
    
    /**
     * Init method.
     */
    @PostConstruct
    public void init() {

        try{
            
            HystrixPlugins.getInstance().registerMetricsPublisher(HystrixServoMetricsPublisher.getInstance());
            
            LOGGER.info("HystrixServoMetricsPublisher registered.");
            
            CloudWatchMetricObserver cloudwatchObserver = new CloudWatchMetricObserver(
                    "cloudwatchObserver", "EVAS_", InstanceProfileCredentialsProvider.getInstance());
            MetricObserver transform = new CounterToRateMetricTransform(
                    cloudwatchObserver, 1, TimeUnit.MINUTES);

            if (!PollScheduler.getInstance().isStarted()) {
                LOGGER.info("PollScheduler not started. Starting it...");
                PollScheduler.getInstance().start();
                LOGGER.info("PollScheduler started.");
            }
            PollRunnable registeryTask = new PollRunnable(new MonitorRegistryMetricPoller(), BasicMetricFilter.MATCH_ALL, cloudwatchObserver, transform); 
            PollScheduler.getInstance().addPoller(registeryTask, MAGIC_NUMBER_FIVE, TimeUnit.SECONDS); 
            
        } catch (Exception e) {
            LOGGER.error("Error setting up Cloudwatch metric publishing mechanism: {}.", e.getMessage(), e);

        }
 
        
        
    }

I can see the logs saying that the PollScheduler started and there is no error thrown and yet I can't find the metrics.

Is there anything else I should do?

@fredshonorio
Copy link

Have you tried attaching a debugger while forcing a metric?

@sobel003
Copy link
Author

It is solved now. Actually yes, the debugger was showing that the metrics were being sent but we couldn't see them in AWS and the cause is that they were being sent to the default region instead of the one we were testing on. Changing the way we created the CloudWatchMetricObserver solved the issue by picking up the region where the application is running.

Thanks for the reply.

@brharrington
Copy link
Contributor

Glad you worked it out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants