![monit log file monitoring monit log file monitoring](https://www.eventsentry.com/documentation/help/html/clip0139.png)
We pass this the configuration file’s name which determines the template file that will be run, move this file into the conf.d directory then set the ownership and permissions. This calls a monit_config method which is defined at the bottom of the file.
#Monit log file monitoring install
Here we define several tasks, one to install Monit in case we’re installing this on a new server and another to set up Monit by copying over the configuration files.
#Monit log file monitoring how to
We also need to tell Monit how to start and stop the program. We could make this path dynamic with some erb if we wanted to configure it through Capistrano, but we won’t do that here. We do this by calling check process, giving it a name and passing in a pidfile option with the path to Nginx’s pid. Our goal here is to monitor Nginx and restart it if it fails. Note that this is an erb file so that we can add dynamic content. Our first file will be for configuring Nginx. As there are multiple configuration files for Monit we’ll make a new monit directory under /config/recipes/templates. This way we can create templates for the configuration files which can be generated and copied to any server using Capistrano. It’s a good idea to create Capistrano recipes for setting up the server, like we did in episode 337. We could set up this configuration directly on the server by adding files to the /etc/monit/conf.d directory but it’s generally better not to do extensive configuration on the server but instead to put configuration files within our Rails application under source control. Monit will then check this process and we can tell it what to do if the process fails. This tells us that we can run the check process command to do this, passing in a unique name and a pidfile. The manual is a good resource when editing the configuration and there’s a Configuration Examples page that is useful. That’s all we need to do to this configuration file and next we’ll instruct Monit to monitor our Rails application. We don’t have any files in this directory but if we want to configure Monit for various processes such as Nginx or Unicorn this is a good place to put them. The last line tells Monit to include any configuration files that appear in the conf.d directory. The next few lines configure various file paths and then we have an eventqueue setting that tells Monit to remember any alert messages that it can’t send over email. We’ll change this to 30 seconds so that the application is checked more frequently. The first line above tells Monit to run in the background and to perform a check every two minutes. Slots 100 # optionally limit the queue size Set daemon 120 # check services at 2-minute intervalsīasedir /var/lib/monit/events # set the base directory where events will be stored