{"id":1890,"date":"2016-01-12T13:00:18","date_gmt":"2016-01-12T13:00:18","guid":{"rendered":"https:\/\/intelligentbee.com\/blog\/?p=1890"},"modified":"2024-11-28T13:51:21","modified_gmt":"2024-11-28T13:51:21","slug":"how-to-monitor-symfony-and-apache-logs-with-mmonit","status":"publish","type":"post","link":"https:\/\/intelligentbee.com\/blog\/how-to-monitor-symfony-and-apache-logs-with-mmonit\/","title":{"rendered":"How to monitor Symfony and Apache logs with M\/Monit"},"content":{"rendered":"<p>So you have developed and deployed a fresh new project and you want to be alerted in case an error happens.<\/p>\n<h2><strong>Here&#8217;s how you do it\u00a0using the M\/Monit tool.<\/strong><\/h2>\n<p>It can be installed on an Ubuntu machine using the following command:<\/p>\n<pre class=\"nums:false lang:sh decode:true \">sudo apt-get install monit<\/pre>\n<p>Now edit the <code>\/etc\/monit\/monitrc<\/code>\u00a0configuration file and add the following:<\/p>\n<pre class=\"nums:false lang:sh decode:true\">set mailserver smtp.sendgrid.net port 587\r\n  username \"USERNAME\" password \"PASSWORD\"\r\n\r\nset alert YOUR_EMAIL@HOST.COM not on { instance, action }\r\n\r\nset httpd port 2812 and\r\n    use address localhost  # only accept connection from localhost\r\n    allow localhost        # allow localhost to connect to the server and\r\n    allow admin:monit      # require user 'admin' with password 'monit'\r\n\r\ncheck file error.log with path \/var\/log\/apache2\/error.log\r\n      if match \"error\" then alert\r\n\r\ncheck file prod.log with path \/var\/www\/sfproject\/app\/logs\/prod.log\r\n      if match \"request.CRITICAL\" then alert\r\n<\/pre>\n<p>First\u00a0we\u00a0need to tell M\/Monit what mail server to use (we used Sendgrid but you can use whatever you want), then\u00a0to specify the email address which will receive the alerts. We also have to allow connections from localhost so the <code>status<\/code> command below can be executed.<\/p>\n<p>The\u00a0actual monitoring\u00a0is set up in the last two blocks of code, one for the apache error log and the next for the Symfony production logs. Anytime the specified string will appear in the logs, an alert email will be sent to the address we defined above.<\/p>\n<h3>To enable the changes, reload configuration:<\/h3>\n<pre class=\"nums:false lang:sh decode:true\">monit reload<\/pre>\n<p>You can now check the status with the command:<\/p>\n<pre class=\"nums:false lang:sh decode:true \">monit status<\/pre>\n<p>It&#8217;s that simple!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>So you have developed and deployed a fresh new project and you want to be alerted in case an error [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":1905,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[82],"tags":[194,238],"yst_prominent_words":[422,545,1053,1224],"post_mailing_queue_ids":[],"_links":{"self":[{"href":"https:\/\/intelligentbee.com\/blog\/wp-json\/wp\/v2\/posts\/1890"}],"collection":[{"href":"https:\/\/intelligentbee.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/intelligentbee.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/intelligentbee.com\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/intelligentbee.com\/blog\/wp-json\/wp\/v2\/comments?post=1890"}],"version-history":[{"count":1,"href":"https:\/\/intelligentbee.com\/blog\/wp-json\/wp\/v2\/posts\/1890\/revisions"}],"predecessor-version":[{"id":133327,"href":"https:\/\/intelligentbee.com\/blog\/wp-json\/wp\/v2\/posts\/1890\/revisions\/133327"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/intelligentbee.com\/blog\/wp-json\/wp\/v2\/media\/1905"}],"wp:attachment":[{"href":"https:\/\/intelligentbee.com\/blog\/wp-json\/wp\/v2\/media?parent=1890"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/intelligentbee.com\/blog\/wp-json\/wp\/v2\/categories?post=1890"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/intelligentbee.com\/blog\/wp-json\/wp\/v2\/tags?post=1890"},{"taxonomy":"yst_prominent_words","embeddable":true,"href":"https:\/\/intelligentbee.com\/blog\/wp-json\/wp\/v2\/yst_prominent_words?post=1890"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}