{"id":8005,"date":"2024-07-20T13:18:00","date_gmt":"2024-07-20T07:48:00","guid":{"rendered":"https:\/\/pheonixsolutions.com\/blog\/?p=8005"},"modified":"2024-07-20T13:18:03","modified_gmt":"2024-07-20T07:48:03","slug":"how-to-set-up-the-cpu-service-monitor-on-nagios-with-percentages","status":"publish","type":"post","link":"https:\/\/pheonixsolutions.com\/blog\/how-to-set-up-the-cpu-service-monitor-on-nagios-with-percentages\/","title":{"rendered":"HOW TO SET UP THE CPU SERVICE MONITOR ON NAGIOS WITH PERCENTAGES"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><strong>Introduction:<\/strong><br>To set up the CPU service monitor on Nagios with percentages, follow these general instructions. CPU monitors CPU utilization, load averages, and other server performance measures, and if a process exceeds a certain threshold, it alerts the Nagois server.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Prerequisite<\/strong>:<br> 1. Server root login credentials.<br><strong>Step 1:<\/strong><br>Log in to your Ubuntu or Centos server as a user with sudo privileges.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>$ ssh root@Ip<\/td><\/tr><\/tbody><\/table><figcaption class=\"wp-element-caption\"><strong>Step 2:<\/strong><br>Edit the \/usr\/local\/nagios\/etc\/nrpe.cfg configuration file and search for&nbsp;<strong><em>command<\/em><\/strong>&nbsp;definition sections. Here you can define or update check commands.<\/figcaption><\/figure>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>$ vi \/usr\/local\/nagios\/etc\/nrpe.cfg<\/td><\/tr><\/tbody><\/table><figcaption class=\"wp-element-caption\"><br>Update the below command for the CPU check.<\/figcaption><\/figure>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>command[check_cpu]=\/usr\/local\/nagios\/libexec\/check_cpu<\/td><\/tr><\/tbody><\/table><figcaption class=\"wp-element-caption\"><strong>Step 3:<\/strong><br>Go to the libexec path and create a new script file&nbsp;in the specified path, such as check_cpu. The script should check if the CPU service checking the server process.<\/figcaption><\/figure>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>vi \/usr\/local\/nagios\/libexec\/check_cpu<\/td><\/tr><\/tbody><\/table><figcaption class=\"wp-element-caption\">Copy the below commands, and paste the check_cpu file, and save the file.<br><br><br><\/figcaption><\/figure>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>#!\/bin\/bash<br><br>#Get CPU usage percentage<br>CPU_USAGE=$(top -bn1 | grep &#8220;Cpu(s)&#8221; | awk &#8216;{print $2 + $4}&#8217; | cut -d. -f1)<br><br>#Define thresholds for CPU usage<br>WARNING_THRESHOLD=70<br>CRITICAL_THRESHOLD=80<br><br>#Compare CPU usage with the thresholds<br>if [ &#8220;$CPU_USAGE&#8221; -ge &#8220;$CRITICAL_THRESHOLD&#8221; ]; then<br>echo &#8220;CPU usage is ${CPU_USAGE}%. Critical threshold exceeded!&#8221;<br>exit 2 # Nagios return code for critical status<br>elif [ &#8220;$CPU_USAGE&#8221; -ge &#8220;$WARNING_THRESHOLD&#8221; ]; then<br>echo &#8220;CPU usage is ${CPU_USAGE}%. Warning threshold exceeded!&#8221;<br>exit 1 # Nagios return code for warning status<br>else<br>echo &#8220;CPU usage is ${CPU_USAGE}%.&#8221;<br>exit 0 # Nagios return code for OK status<br>fi<\/td><\/tr><\/tbody><\/table><figcaption class=\"wp-element-caption\"><strong>Step 4:<\/strong><br>Give permission to the check_cpu file as below<\/figcaption><\/figure>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>$ chmod 755 check_cpu<\/td><\/tr><\/tbody><\/table><figcaption class=\"wp-element-caption\"><br>Restart the NRPE service.<br><br><\/figcaption><\/figure>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>$ systemctl restart nagios-nrpe-server<br>                   or<br>$ $ systemctl restart nrpe<\/td><\/tr><\/tbody><\/table><figcaption class=\"wp-element-caption\"><strong>Step 6<\/strong>:<br>Login to Nagios server<br><br><strong>Step 7<\/strong>:<br><br>Open the below for the configuration path.<\/figcaption><\/figure>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>$ vi \/usr\/local\/nagios\/etc\/servers\/server.cfg<\/td><\/tr><\/tbody><\/table><figcaption class=\"wp-element-caption\">Add the below lines for CPU checking the configuration and save it.<\/figcaption><\/figure>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>define service {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; use&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; generic-service&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ; Name of service template to use<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; host_name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; testserver2<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; service_description&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cpu_service<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; check_command&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; check_nrpe!check_cpu<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; contact_groups&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;admins<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; notifications_enabled&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<\/td><\/tr><\/tbody><\/table><figcaption class=\"wp-element-caption\"><strong>Step 8:<\/strong><br>Save the configuration file.<br><br>And finally, restart Nagios to apply the recent configuration changes:<br><\/figcaption><\/figure>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>$ systemctl restart nagios<\/td><\/tr><\/tbody><\/table><figcaption class=\"wp-element-caption\"><span style=\", Segoe, sans-serif;font-size: 17px\">We can verify the cpu_service status in the below snaps<\/span><br><figure class=\"wp-block-table\" style=\"margin-bottom: 0px;, Segoe, sans-serif;font-size: 17px\"><figcaption class=\"wp-element-caption\"><a style=\"background-color: transparent\" href=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2023\/08\/Screenshot-2023-08-14-071154.png\"><\/a><\/figcaption><a style=\"background-color: transparent\" href=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2023\/11\/Screenshot-2023-11-11-124546.png\"><\/a><\/figure><\/figcaption><\/figure>\n\n\n\n<figure class=\"wp-block-gallery has-nested-images columns-default is-cropped wp-block-gallery-1 is-layout-flex wp-block-gallery-is-layout-flex\">\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2024\/07\/Screenshot-2024-07-08-211457.png\"><img decoding=\"async\" width=\"866\" height=\"21\" data-id=\"8011\" src=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2024\/07\/Screenshot-2024-07-08-211457.png\" alt=\"\" class=\"wp-image-8011\" srcset=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2024\/07\/Screenshot-2024-07-08-211457.png 866w, https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2024\/07\/Screenshot-2024-07-08-211457-300x7.png 300w, https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2024\/07\/Screenshot-2024-07-08-211457-768x19.png 768w, https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2024\/07\/Screenshot-2024-07-08-211457-850x21.png 850w\" sizes=\"(max-width: 866px) 100vw, 866px\" \/><\/a><\/figure>\n<\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Conclusion<\/strong><br>Following the steps mentioned above, we can set up the CPU service monitor on Nagios with percentages.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction:To set up the CPU service monitor on Nagios with percentages, follow these general instructions. CPU monitors CPU utilization, load [&hellip;]<\/p>\n","protected":false},"author":499,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[1019],"tags":[],"class_list":["post-8005","post","type-post","status-publish","format-standard","hentry","category-cloud-aws","psol-cat-cloud-aws"],"jetpack_publicize_connections":[],"jetpack_shortlink":"https:\/\/wp.me\/phn2x7-257","jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/8005","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/users\/499"}],"replies":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/comments?post=8005"}],"version-history":[{"count":0,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/8005\/revisions"}],"wp:attachment":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=8005"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=8005"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=8005"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}