-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
[Monit] Monitor multiple processes with the same name but using different arguments. #4257
base: master
Are you sure you want to change the base?
Changes from 6 commits
2c6a35f
448cb6b
da8fbd6
52a7efd
97765c1
0249e6a
828a7ae
bb2c63f
976906b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
############################################################################### | ||
## Monit configuration for dhcp_relay container | ||
## process list | ||
## dhcrelay | ||
############################################################################### | ||
check program monit_dhcrelay with path "/usr/bin/monit_dhcrelay_processes" | ||
if status != 0 then alert |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#!/usr/bin/python | ||
''' | ||
This script is used to monitor dhcrelay processes in dhcp_relay docker container. | ||
Since Monit can only monitor the process with unique name, it is unable to do | ||
this monitoring for dhcrelay processes. Usually there will be multiple dhcrelay | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. s/Usually there will be multiple/There can exist multiple/ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reworded. |
||
processes which executes a same commad but with different arguments. The number | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. s/commad/command There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed. |
||
of dhcrelay processes is determined by Vlans which have non-empry list of dhcp servers. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. s/non-empry/non-empty/ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed. |
||
As such, we let Monit to monitor this script which will read number of vlans with | ||
no-empty list of dhcp servers form Config_DB, then find whether there exist a | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. s/no-empry/non-empty/ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. s/exist/exists/ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed. |
||
process in Linux corresponding to a vlan. If this script fails to find such process, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove extra space before "such" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed extra space. |
||
it will write an alert message into syslog file. | ||
''' | ||
|
||
import os | ||
import subprocess | ||
import re | ||
import sys | ||
import syslog | ||
|
||
from swsssdk import ConfigDBConnector | ||
|
||
def retrieve_vlans(): | ||
vlans = [] | ||
|
||
config_db = ConfigDBConnector() | ||
config_db.connect() | ||
vlan_table = config_db.get_table('VLAN') | ||
|
||
for vlan in vlan_table.keys(): | ||
if vlan_table[vlan].has_key('dhcp_servers') and len(vlan_table[vlan]['dhcp_servers']) != 0: | ||
vlans.append(vlan) | ||
|
||
return vlans | ||
|
||
def check_dhcrelay_processes(): | ||
vlans = retrieve_vlans() | ||
cmd = "sudo monit procmatch '/usr/sbin/dhcrelay -d -m discard'" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rather than making a call to monit, I'd prefer if we use a Python library like psutil. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I used psutil library to check whether one of dhcrelay processes is running or not. Please help me review. |
||
cmd_res = subprocess.check_output(cmd, shell=True) | ||
|
||
for vlan in vlans: | ||
found_process = re.findall(vlan, cmd_res) | ||
if len(found_process) == 0: | ||
syslog.syslog(syslog.LOG_ERR, "dhcrelay process with {} is not running.".format(vlan)) | ||
|
||
|
||
def main(): | ||
check_dhcrelay_processes() | ||
|
||
if __name__ == '__main__': | ||
main() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
############################################################################### | ||
## Monit configuration for teamd container | ||
## process list: | ||
## teamd | ||
############################################################################### | ||
check program monit_teamd with path "/usr/bin/monit_teamd_processes" | ||
if status != 0 then alert |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#!/usr/bin/python | ||
''' | ||
This script is used to monitor teamd process in teamd docker container. | ||
Since Monit can only monitor the process with unique name, | ||
it is unable to do this monitoring for teamd processes. Usually there will be | ||
multiple teamd processes which executes a same command but with different arguments. | ||
The number of teamd processes is decided by the number of port channels in Config_DB. | ||
As such, we let Monit to monitor this script which will read number of port channels, | ||
then find whether there exist a process in Linux corresponding to a port channel. | ||
If this script fails to find such process, it will write an alert message into syslog file. | ||
''' | ||
|
||
import os | ||
import subprocess | ||
import re | ||
import sys | ||
import syslog | ||
|
||
from swsssdk import ConfigDBConnector | ||
|
||
|
||
def retrieve_portchannels(): | ||
port_channels = [] | ||
|
||
config_db = ConfigDBConnector() | ||
config_db.connect() | ||
port_channel_table = config_db.get_table('PORTCHANNEL') | ||
|
||
for key in port_channel_table.keys(): | ||
port_channels.append(key) | ||
|
||
return port_channels | ||
|
||
def check_teamd_processes(): | ||
port_channels = retrieve_portchannels() | ||
cmd = "sudo monit procmatch '/usr/bin/teamd -r -t '" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rather than making a call to monit, I'd prefer if we use a Python library like psutil. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good suggestion! I will do that. I also found psutil library is not installed by default in host image. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I used psutil library to check whether one of teamd processes is running or not. Please help me review. |
||
cmd_res = subprocess.check_output(cmd, shell=True) | ||
|
||
for port_channel in port_channels: | ||
found_process = re.findall(port_channel, cmd_res) | ||
if len(found_process) == 0: | ||
syslog.syslog(syslog.LOG_ERR, "Teamd process with {} is not running.".format(port_channel)) | ||
|
||
def main(): | ||
check_teamd_processes() | ||
|
||
if __name__ == '__main__': | ||
main() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/the process with unique name/processes with unique names/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reworded.