-
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
Open
yozhao101
wants to merge
9
commits into
sonic-net:master
Choose a base branch
from
yozhao101:monit_multiprocesses
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
2c6a35f
[Monit] We use Monit to monitor multiprocess with the same name but with
yozhao101 448cb6b
[Monit] Add new Monit configuration files for teamd and dhcp_relay.
yozhao101 da8fbd6
[Monit] Add an else statement in script to decide whether the container
yozhao101 52a7efd
[Monitoring] Split the single script file into two separate files for
yozhao101 97765c1
[Monitoring] Change the functions names from check_teamd_process to
yozhao101 0249e6a
[Monitoring] Change the lines in docker-teamd.mk file.
yozhao101 828a7ae
[Monitoring] Reword the comments in two scripts files.
yozhao101 bb2c63f
[Monitoring] Use psutil library to decide whether one of teamd or dhc…
yozhao101 976906b
[Monitoring] Delete extra blank lines.
yozhao101 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_multiprocesses.py --container-name dhcp_relay" | ||
if status != 0 then alert |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_multiprocesses.py --container-name teamd" | ||
if status != 0 then alert |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
#!/usr/bin/python | ||
''' | ||
This script is used to monitor teamd process and dhcrelay process in teamd and dhcp_relay | ||
docker container respectively. Since Monit can only monitor the process with unique name, | ||
it is unable to do this monitoring for teamd and dhcrelay processes. Usually there will be | ||
multiple teamd and dhcrelay processes which executes a same commad but with different arguments. | ||
The number of teamd processes is decided by the number of port channels in Config_DB and | ||
the number of dhcrelay processes is determined by Vlans which have non-empry list of dhcp servers. | ||
As such, we let Monit to monitor this script which will read number of port channles and | ||
vlans with no-empty list of dhcp servers form Config_DB, then find whether there exist a | ||
process in Linux corresponding to a port channel or a vlan. 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 | ||
import argparse | ||
|
||
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_process(): | ||
port_channels = retrieve_portchannels() | ||
cmd = "sudo monit procmatch '/usr/bin/teamd -r -t '" | ||
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 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_dhcp_relay_process(): | ||
vlans = retrieve_vlans() | ||
cmd = "sudo monit procmatch '/usr/sbin/dhcrelay -d -m discard'" | ||
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(): | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument('-c', '--container-name') | ||
args = parser.parse_args() | ||
if args.container_name == '': | ||
syslog.syslog(syslog.LOG_ERR, "contianer name is not specified. Exiting...") | ||
sys.exit(1) | ||
|
||
if args.container_name == 'teamd': | ||
check_teamd_process() | ||
elif args.container_name == 'dhcp_relay': | ||
check_dhcp_relay_process() | ||
else: | ||
syslog.syslog(syslog.LOG_ERR, "container name is invalid. Exiting...") | ||
sys.exit(2) | ||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I think this file should be broken into two separate files, one for teamd and one for dhcp_relay. In the repo, the files should reside in the directories of their respective dockers.
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.
Will break it into two separate files and place each one into their docker directories in the repo.