mirror of
https://github.com/mtan93/cachet-url-monitor.git
synced 2026-03-08 05:31:58 +00:00
Creating agent that schedules the monitoring task.
This commit is contained in:
5
README.md
Normal file
5
README.md
Normal file
@@ -0,0 +1,5 @@
|
||||
# Status
|
||||
|
||||
cachet-url-monitor
|
||||
========================
|
||||
Python plugin for [cachet](cachethq.io) that monitors an URL, verifying it's response status and latency.
|
||||
@@ -12,6 +12,8 @@ class Configuration(object):
|
||||
"""
|
||||
def __init__(self, config_file):
|
||||
#TODO(mtakaki|2016-04-26): Needs validation if the config is correct.
|
||||
#TODO(mtakaki|2016-04-28): Accept overriding settings using environment
|
||||
# variables so we have a more docker-friendly approach.
|
||||
self.config_file = config_file
|
||||
self.data = load(file(self.config_file, 'r'))
|
||||
self.expectations = [Expectaction.create(expectation) for expectation
|
||||
|
||||
@@ -1,10 +1,33 @@
|
||||
#!/usr/bin/env python
|
||||
from threading import Timer
|
||||
import configuration
|
||||
from configuration import Configuration
|
||||
import logging
|
||||
import schedule
|
||||
import sys
|
||||
import time
|
||||
|
||||
|
||||
class Agent(object):
|
||||
def __init__(self, configuration):
|
||||
self.configuration = configuration
|
||||
|
||||
def execute(self):
|
||||
self.configuration.evaluate()
|
||||
self.configuration.push_status_and_metrics()
|
||||
|
||||
def start(self):
|
||||
schedule.every(self.configuration.data['frequency']).seconds.do(self.execute)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) <= 1:
|
||||
logging.fatal('Missing configuration file argument')
|
||||
sys.exit(1)
|
||||
|
||||
configuration = Configuration(sys.argv[1])
|
||||
agent = Agent(configuration)
|
||||
|
||||
agent.start()
|
||||
logging.info('Starting monitor agent...')
|
||||
while True:
|
||||
schedule.run_pending()
|
||||
time.sleep(configuration.data['frequency'])
|
||||
|
||||
@@ -2,3 +2,4 @@ PyYAML==3.11
|
||||
ipython==4.2.0
|
||||
pudb==2016.1
|
||||
requests==2.9.1
|
||||
schedule==0.3.2
|
||||
|
||||
3
requirements.txt
Normal file
3
requirements.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
PyYAML==3.11
|
||||
requests==2.9.1
|
||||
schedule==0.3.2
|
||||
Reference in New Issue
Block a user