{"id":274,"date":"2022-05-23T12:09:21","date_gmt":"2022-05-23T12:09:21","guid":{"rendered":"http:\/\/checkmateq.com\/blog\/?p=274"},"modified":"2024-10-19T17:27:59","modified_gmt":"2024-10-19T17:27:59","slug":"cloudwatch","status":"publish","type":"post","link":"https:\/\/www.checkmateq.com\/blog\/cloudwatch","title":{"rendered":"Java Application Monitoring With CloudWatch"},"content":{"rendered":"<p>In this article, we would like to consume AWS cloud watch agent running on the Ec2 instance hosting Java application to monitor JMX Exporter parameters. <a href=\"https:\/\/www.checkmateq.com\/cloud\">AWS Cloudwatch monitors<\/a> AWS resources and applications running on AWS in real-time.<\/p>\n<h3><strong>Prerequisites:<\/strong><\/h3>\n<ul>\n<li>A <strong>Java<\/strong> application running on <strong>Apache Tomcat<\/strong>.<\/li>\n<li><strong><a href=\"https:\/\/docs.aws.amazon.com\/AmazonCloudWatch\/latest\/monitoring\/WhatIsCloudWatch.html\">CloudWatch<\/a> Agent<\/strong> is installed on the application server.<\/li>\n<\/ul>\n<h3><strong>Step1: Configure JMX Exporter.<\/strong><\/h3>\n<ul>\n<li>Download <strong>JMX Exporter<\/strong>. Use the following command.<\/li>\n<\/ul>\n<pre>sudo wget\u00a0 https:\/\/repo1.maven.org\/maven2\/io\/prometheus\/jmx\/jmx_prometheus_javaagent\/0.16.1\/jmx_prometheus_javaagent-0.16.1.jar\r\n<\/pre>\n<ul>\n<li>Create a <strong>config.yaml<\/strong> file which is the configuration file of JMX Exporter.<\/li>\n<li>Copy the following code in config.yaml file.<\/li>\n<\/ul>\n<pre>startDelaySeconds: 0\r\nssl : false\r\nlowercaseOutputName: true\r\nlowercaseOutputLabelNames: false\r\n<\/pre>\n<ul>\n<li>Open the Tomcat Service file<\/li>\n<\/ul>\n<pre>sudo vi \/etc\/systemd\/system\/tomcat.service\r\n<\/pre>\n<ul>\n<li>Set the value of <strong>CATALINA_OPTS <\/strong>environment variable.<\/li>\n<\/ul>\n<pre>Environment=\"CATALINA_OPTS=-javaagent:home\/ubuntu\/jmx_prometheus_javaagent-0.16.1.jar=8083:\/home\/ubuntu\/config.yaml\"\r\n<\/pre>\n<p><img loading=\"lazy\" class=\"alignnone wp-image-485\" src=\"http:\/\/checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/Screenshot-2022-05-23-145646-300x37.png\" alt=\"\" width=\"1145\" height=\"141\" srcset=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/Screenshot-2022-05-23-145646-300x37.png 300w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/Screenshot-2022-05-23-145646-1024x125.png 1024w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/Screenshot-2022-05-23-145646-768x94.png 768w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/Screenshot-2022-05-23-145646-1200x147.png 1200w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/Screenshot-2022-05-23-145646.png 1507w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><\/p>\n<ul>\n<li>Restart Apache Tomcat.<\/li>\n<\/ul>\n<pre>sudo systemctl reload-daemon\r\nsudo systemctl restart tomcat\r\n<\/pre>\n<ul>\n<li>Verify that \u00a0Prometheus metrics are emitted on port 8083.<\/li>\n<\/ul>\n<pre>http:\/\/your-server-public-ip:8083\r\n<\/pre>\n<h3><\/h3>\n<h3>Step 2: Configure the CloudWatch agent to scrape Prometheus metrics<\/h3>\n<ul>\n<li>Go to the following directory to set up the Prometheus scrape configuration.<\/li>\n<\/ul>\n<pre>cd \/opt\/aws\/amazon-cloudwatch-agent\/var\r\n<\/pre>\n<ul>\n<li>Create a file prometheus.yaml and copy the following code there.<\/li>\n<\/ul>\n<pre>global:\r\nscrape_interval: 1m\r\nscrape_timeout: 10s\r\nscrape_configs:\r\n- job_name: jmx\r\nsample_limit: 10000\r\nec2_sd_configs:\r\n- region: us-east-2\r\nport: 8083\r\nfilters:\r\n- name: instance-id\r\nvalues:\r\n- i-0075da5e713e88fd9\r\n<\/pre>\n<ul>\n<li>Now create a configuration file<strong> cwagent-config.json<\/strong> for CloudWatch Agent and copy the following code there.<\/li>\n<\/ul>\n<pre>{\r\n\"agent\": {\r\n\"region\": \"us-east-1\"\r\n},\r\n\"logs\": {\r\n\"metrics_collected\": {\r\n\"prometheus\": {\r\n\"cluster_name\": \"my-cluster\",\r\n\"log_group_name\": \"prometheus-test\",\r\n\"prometheus_config_path\": \"path-to-Prometheus-Scrape-Configuration-file\",\r\n\"emf_processor\": {\r\n\"metric_declaration_dedup\": true,\r\n\"metric_namespace\": \"PrometheusTest\",\r\n\"metric_unit\":{\r\n\"jvm_threads_current\": \"Count\",\r\n\"jvm_classes_loaded\": \"Count\",\r\n\"java_lang_operatingsystem_freephysicalmemorysize\": \"Bytes\",\r\n\"catalina_manager_activesessions\": \"Count\",\r\n\"jvm_gc_collection_seconds_sum\": \"Seconds\",\r\n\"catalina_globalrequestprocessor_bytesreceived\": \"Bytes\",\r\n\"jvm_memory_bytes_used\": \"Bytes\",\r\n\"jvm_memory_pool_bytes_used\": \"Bytes\"\r\n},\r\n\"metric_declaration\": [\r\n{\r\n\"source_labels\": [\"job\"],\r\n\"label_matcher\": \"^jmx$\",\r\n\"dimensions\": [[\"instance\"]],\r\n\"metric_selectors\": [\r\n\"^jvm_threads_current$\",\r\n\"^jvm_classes_loaded$\",\r\n\"^java_lang_operatingsystem_freephysicalmemorysize$\",\r\n\"^catalina_manager_activesessions$\",\r\n\"^jvm_gc_collection_seconds_sum$\",\r\n\"^catalina_globalrequestprocessor_bytesreceived$\"\r\n]\r\n},\r\n{\r\n\"source_labels\": [\"job\"],\r\n\"label_matcher\": \"^jmx$\",\r\n\"dimensions\": [[\"area\"]],\r\n\"metric_selectors\": [\r\n\"^jvm_memory_bytes_used$\"\r\n]\r\n},\r\n{\r\n\"source_labels\": [\"job\"],\r\n\"label_matcher\": \"^jmx$\",\r\n\"dimensions\": [[\"pool\"]],\r\n\"metric_selectors\": [\r\n\"^jvm_memory_pool_bytes_used$\"\r\n]\r\n}\r\n]\r\n}\r\n}\r\n},\r\n\"force_flush_interval\": 5\r\n}\r\n}\r\n<\/pre>\n<ul>\n<li>Restart CloudWatch Agent with following command.<\/li>\n<\/ul>\n<pre>sudo \/opt\/aws\/amazon-cloudwatch-agent\/bin\/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -s -c file:\/opt\/aws\/amazon-cloudwatch-agent\/var\/cwagent-config.json\r\n<\/pre>\n<h4><strong>Step4: Monitor Metrics and Logs of Java application<\/strong><\/h4>\n<ul>\n<li>Go to CloudWatch Console.<\/li>\n<li>Go to Metrics. Select the PrometheusTest Namespace to see metrics.<\/li>\n<\/ul>\n<p><img loading=\"lazy\" class=\"alignnone wp-image-491\" src=\"http:\/\/checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/Screenshot-2022-05-23-161434-300x88.png\" alt=\"\" width=\"743\" height=\"218\" srcset=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/Screenshot-2022-05-23-161434-300x88.png 300w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/Screenshot-2022-05-23-161434-1024x302.png 1024w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/Screenshot-2022-05-23-161434-768x226.png 768w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/Screenshot-2022-05-23-161434.png 1171w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" class=\"alignnone wp-image-492\" src=\"http:\/\/checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/Screenshot-2022-05-23-161543-300x67.png\" alt=\"Java\" width=\"734\" height=\"164\" srcset=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/Screenshot-2022-05-23-161543-300x67.png 300w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/Screenshot-2022-05-23-161543-1024x229.png 1024w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/Screenshot-2022-05-23-161543-768x171.png 768w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/Screenshot-2022-05-23-161543-1536x343.png 1536w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/Screenshot-2022-05-23-161543-1200x268.png 1200w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/Screenshot-2022-05-23-161543.png 1725w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/><\/p>\n<ul>\n<li>Go to Logs-&gt;Log groups-&gt;jmx.<\/li>\n<li>Select prometheus-test to see log events.<\/li>\n<\/ul>\n<p><img loading=\"lazy\" class=\"alignnone wp-image-494\" src=\"http:\/\/checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/Screenshot-2022-05-23-161915-300x68.png\" alt=\"Java\" width=\"728\" height=\"165\" srcset=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/Screenshot-2022-05-23-161915-300x68.png 300w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/Screenshot-2022-05-23-161915-1024x232.png 1024w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/Screenshot-2022-05-23-161915-768x174.png 768w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/Screenshot-2022-05-23-161915-1200x272.png 1200w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/Screenshot-2022-05-23-161915.png 1363w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" class=\"alignnone wp-image-495\" src=\"http:\/\/checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/Screenshot-2022-05-23-163425-300x121.png\" alt=\"Java\" width=\"724\" height=\"292\" srcset=\"https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/Screenshot-2022-05-23-163425-300x121.png 300w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/Screenshot-2022-05-23-163425-1024x414.png 1024w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/Screenshot-2022-05-23-163425-768x311.png 768w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/Screenshot-2022-05-23-163425-1200x485.png 1200w, https:\/\/www.checkmateq.com\/blog\/wp-content\/uploads\/2022\/05\/Screenshot-2022-05-23-163425.png 1357w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px\" \/><\/p>\n<p><a href=\"https:\/\/www.checkmateq.com\/contact-us\"><strong>Call us<\/strong><\/a> to get more information about cloud infrastructure engineering, <a href=\"https:\/\/www.checkmateq.com\/hire-developer\">IT Staffing Services in India<\/a>, <a href=\"https:\/\/www.checkmateq.com\/hire-developer\">Hire Software Developers in India<\/a>, and <a href=\"https:\/\/www.checkmateq.com\/cloud\">cloud operations support services in India<\/a>. You can opt for our <a href=\"https:\/\/www.checkmateq.com\/virtual-cto-services\">Virtual CTO Services<\/a>\u00a0to manage entire infrastructure tech stack.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this article, we would like to consume AWS cloud watch agent running on the Ec2 instance hosting Java application to monitor JMX Exporter parameters. AWS Cloudwatch monitors AWS resources and applications running on AWS in real-time. Prerequisites: A Java application running on Apache Tomcat. CloudWatch Agent is installed on the application server. Step1: Configure &hellip; <a href=\"https:\/\/www.checkmateq.com\/blog\/cloudwatch\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Java Application Monitoring With CloudWatch&#8221;<\/span><\/a><\/p>\n","protected":false},"author":3,"featured_media":517,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[15,4,3,17,7,14],"_links":{"self":[{"href":"https:\/\/www.checkmateq.com\/blog\/wp-json\/wp\/v2\/posts\/274"}],"collection":[{"href":"https:\/\/www.checkmateq.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.checkmateq.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.checkmateq.com\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.checkmateq.com\/blog\/wp-json\/wp\/v2\/comments?post=274"}],"version-history":[{"count":22,"href":"https:\/\/www.checkmateq.com\/blog\/wp-json\/wp\/v2\/posts\/274\/revisions"}],"predecessor-version":[{"id":4625,"href":"https:\/\/www.checkmateq.com\/blog\/wp-json\/wp\/v2\/posts\/274\/revisions\/4625"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.checkmateq.com\/blog\/wp-json\/wp\/v2\/media\/517"}],"wp:attachment":[{"href":"https:\/\/www.checkmateq.com\/blog\/wp-json\/wp\/v2\/media?parent=274"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.checkmateq.com\/blog\/wp-json\/wp\/v2\/categories?post=274"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.checkmateq.com\/blog\/wp-json\/wp\/v2\/tags?post=274"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}