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

[WIP] Integrating Monit for monitoring TorQ #105

Merged
merged 27 commits into from Sep 4, 2018
Merged

[WIP] Integrating Monit for monitoring TorQ #105

merged 27 commits into from Sep 4, 2018

Conversation

rdanutalexandru1993
Copy link
Contributor

This will add the basic configuration needed to use monit to monitor TorQ processes on UNIX-like systems. The processes will be read from the process.csv file, started and monitored by monit. The dashboard can be accessed on localhost port 2812 and will include basic information about the TorQ processes. If any of the processes fail to start, monit will try to restart the process and send an alert e-mail which contains information about the service.

Created the backbone of monit.sh
…om process.csv

Added monitconfig.cfg which contains the location of the process.csv and the output file
Modified the location of the files
Updated the monitrc to include the monitconfi.cfg
Added a new test alert in monitconfig.cfg which executest a test bash script
Modified the e-mail format in /code/templates/monitrc to include more details about the event
@rdanutalexandru1993 rdanutalexandru1993 self-assigned this Jul 17, 2018
@rdanutalexandru1993 rdanutalexandru1993 changed the title [WIP] Monit for monitoring TorQ [WIP] Integrating Monit for monitoring TorQ Jul 17, 2018
# backup.bar.baz port 10025, # backup mailserver on port 10025
# localhost # fallback relay
set mailserver smtp.gmail.com port 587
username "\"torqmonit@gmail.com\"" password "\"torqmonit2018\""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this a real email address & password? these should be dummy placeholders in here, and this password is now in git history so should also be changed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is an e-mail address that I will change. I only use this to test if monit works as it should. I wasn't able to make the e-mail work yet.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, but regardless you should never commit a password to any email account to git - right now anyone could log into that email account (and I did, to check)

## commands to a running Monit daemon. See the Monit Wiki if you want to
## enable SSL for the HTTP interface.
#
set httpd port 2812 and
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any way to have this port based on TorQ baseport variable? what happens if a user already has something running on port 2812?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the default port for monit. It wasn't my focus to change it, but it should be really easy to do so. monitrc is created using the environment variables which are set when setenv.sh is executed. Should I look at a way to set that port taking in consideration the baseport and the number of processes or should I maybe define a an env variable and let the user set the port (just like we do now with the baseport)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

personally I think the less a user has to think about configuring the better, so tying it to the baseport seems most logical to me

@@ -0,0 +1,3 @@
#!/bin/bash

echo -e "TORQMONIT\r\rThis is an automated message\r\rProcess SERVICE is down"|mail.mailutils -s \"SUBJECT\" rdanutalexandrugmail.com
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume this file should be removed? Doesn't seem like something that should be merged to master

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is my attempt to use an external e-mail to generate the alerts. Not very successful so far. If it works this will take the form of a template e-mail that I will use in my monitalert.cfg
`

setenv.sh Outdated
@@ -12,8 +12,10 @@ export KDBAPPCODE=${TORQAPPHOME}/code
export KDBHDB=${TORQDATA}/hdb/database
export KDBWDB=${TORQDATA}/wdbhdb

export KDBBASEPORT=6000 # set KDBBASEPORT to the default value for a TorQ Installation
export KDBBASEPORT=6000 # set KDBBASEPORT to the default value for a TorQ Installation
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like alignment changed on this comment bringing it out of line, please put it back

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will do

dirpath="$0"
fi

eval ". $(dirname "$dirpath")/setenv.sh" #set environment variables
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is eval needed here? Why not just source the file with . directly? (this pattern exists in a few places)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was already here. I think eval is used to execute ". $(dirname "$dirpath")/setenv.sh"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what you mean by "already here", this is a new file, no? I get what eval is doing, I'm asking why though? Seems like you could just do . $(dirname "$dirpath")/setenv.sh

@@ -0,0 +1 @@
${TORQHOME}/appconfig/process.csv ${TORQHOME}/torq.sh monitconfig.cfg
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This + fill_templates.sh was set up by me a long time ago rather naively, there's probably better ways to do it and definitely better ways to set up this config file, would be worth looking into it.

…e status output

Modified torq.sh to setenv using a BASEDIR defined in the .bashrc_torq
Enabled the log file output in monitrc
Modified monit.sh to create a .bashrc_torq which holds the environment variables necessary for starting torq from root
@rdanutalexandru1993
Copy link
Contributor Author

rdanutalexandru1993 commented Aug 7, 2018

bash monit.sh takes me in the root directory and tries to execute everything from there. This creates a number of issues. I have seen someone using start program = "/bin/bash -c 'cd location && ./torq.sh $procname'". At the moment I am defining TORQHOME in a file called .bashrc_torq and source it so I can use the full path. Anyone knows a better way for doing solving this problem?

@ThomasSmyth @jonathonmcmurray @jemmaborland @claire-sloan @jonnypress

monit.sh Outdated
checkst "echo $TORQHOME|wc -l" "TORQHOME present" "npres" "1"
checkst "echo $BASEDIR|wc -l" "BASEDIR present" "npres" "1"
else
echo "export TORQHOME=${PWD}" >> $HOME/.bashrc_torq
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does all this stuff need to be duplicated? Can you not just move it out of the if statement & run it regardless? Or is there a difference I'm missing?

@jonathonmcmurray
Copy link
Member

@Aqualex I don't think I understand the problem...why can't you just source setenv.sh the same way the TorQ start script does and get TORQHOME defined that way? Seems really messy to write a second script and then source it, plus the name .bashrc_torq doesn't really make sense; .bashrc is a file loaded by bash at the start of a shell session, that's not really related to this. I don't get why it's necessary to write a second script, if the purpose is to set environment variables, can you just do that directly if required? Why write into a second script & source it instead of just doing it directly?

… the path to torq.sh and process.csv from fill_templates.sh

Modified the way the path is set in templates/monitrc to include the full path not only the path relative to the current directory
Modified e-mail settings in monitrc from ssl to tslv1 and fixed the issues with sending alert e-mails
Added path to events folder in templates/monitrc
Fixed e-mail format in templates/monitrc
Changed port for HTTP interface
Fixed path to torq.sh in fill_templates
Modified monit.sh to run fill_templates to run if any of the necessary files are missing
Modified fill_templates to check if the necessary files exist and create them only it they are missing
Modified path to setenv.sh in torq.sh to be set based on the current directory
Added small script in torq.sh, monit.sh to determine the path based on the current directory
Fixed format for e-mail template
Removed personal e-mail from monitalert template
@@ -11,5 +11,5 @@ clearinactivetime:0D01:00 // the time to keep inactive handle data

// Server connection details
\d .servers
CONNECTIONS:`rdb`hdb // list of connections to make at start up
CONNECTIONS:`rdb`hdb`wdb // list of connections to make at start up
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this here?

@@ -0,0 +1,88 @@
#!/bin/bash
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather this script didn't sit at the top level directory of TorQ

Copy link
Contributor

@jonnypress jonnypress left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you walk me through this on Thursday please?

@@ -0,0 +1,162 @@
#!/bin/bash
#FUNTION DECLARATION ###############################################################################
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@@ -0,0 +1,12 @@
check system homer.aquaq.co.uk
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

take our server name out
And the google check
Best to specify that this is an example

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -0,0 +1,321 @@
###############################################################################
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't want this in here. All we want to create is the monit config file. Leave it up to the person using it to add it to their monitrc. Otherwise we become coupled to changes in monitrc

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so you want me to remove this altogether and everything the bit in monit.sh that creates it? I believe we should have monit setup in such way that it has some basic functionality straigth out of the box so that our users will see that it works at least.

@@ -221,8 +221,14 @@ usage() {
exit 1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need to change torq.sh in this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

monit executes torq.sh from the root directory. Torq.sh uses . setenv.sh and obviously the setenv.sh is not in the root directory

export TORQHOME=${PWD} # if running the kdb+tick example, change these to full paths
export TORQDATA=${PWD} # some of the kdb+tick processes will change directory, and these will no longer be valid
export TORQAPPHOME=${PWD}
if [ "-bash" = $0 ]; then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these changes strictly for this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

@jonnypress
Copy link
Contributor

As per conversation, add some documentation and we are good to go. We can start with basic documentation and flesh it out.

@jonnypress jonnypress merged commit 41b382e into master Sep 4, 2018
@jonnypress jonnypress deleted the monit branch September 4, 2018 11:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants