Skip to content

an environment monitor tool based on scheduled task

Notifications You must be signed in to change notification settings

waaaaaaz/EMonitor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

EMonitor

an environment monitor tool based on scheduled task

Requirement

  • apscheduler
  • fabric
  • ensure time synchronization between local and remote host
  • target hosts only support linux/Unix which could enable ssh

Usage

  • Configure hosts info including hostname/username/password/groups from hosts.py
{
        "hostname":"10.100.138.30:2222",
        "username":"yxgly",
        "password":"0okm,lp-",
        "groups":[
            "all",
            "webserver",
            "dbserver",
            "nginxserver"
            ]
        } 
  • Customize monitor script to script, example: memory_check.py

  • Customize task class for monitor script in task.py, which including warning condition and mail details

class TaskDiskCheck(Model):

	def task_job(self):
		result = run('python /app/EMonitor/Script/disk_check.py')
		for filesystem, usage in ast.literal_eval(result).items():
			if int(usage.rstrip("%")) > 95:
				send(_mail_info())

	def _mail_info(self):
		MAIL_INFO['mail_subject'] = "Warning from {0}".format(self.__class__.__name__)
		MAIL_INFO['mail_text'] = "Host: {0}\n\rResult: {1}".format(env.host_string.split(":")[0], result)
		return MAIL_INFO 
  • Assign monitor task/ hosts group/ interval time to a job in run.py
class Schedule(object):
    def __init__(self):
       self.scheduler = BackgroundScheduler()
       self.scheduler.add_job(TaskMemCheck('all', 'memory_check').task_execute, 'interval', seconds=3)
       self.scheduler.add_job(TaskDiskCheck('all', 'disk_check').task_execute, 'interval', seconds=5)
       self.scheduler.print_jobs()
  • Execute from cmdline

Screen

License

MIT

About

an environment monitor tool based on scheduled task

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages