Last active
May 26, 2020 11:25
-
-
Save lroudge/05b1dbf93eb2679ca443c4fffeebb528 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| #!/usr/bin/env python | |
| # Instantiate the Dispatcher | |
| dispatcher = Dispatcher( | |
| Client(), | |
| 'localhost:9091', | |
| 'http', | |
| '' | |
| ) | |
| # Instantiate the Metric | |
| jobStepMetric = JobStepTimestamp({ | |
| 'application': 'my_cron', | |
| 'service': 'cli' | |
| }) | |
| # Register the metric in the dispatcher | |
| dispatcher.registerMetric(jobStepMetric) | |
| # The actual cron job | |
| if __name__ == '__main__': | |
| # Set the value of the "start" step to the current time in milliseconds | |
| jobStepMetric.setValue(int(time.time() * 1000), { | |
| 'name': 'my_cron', | |
| 'step': 'start' | |
| }) | |
| print('Hi, I am a cron job. I am currently executing') | |
| # Set the value of the "end" step to the current time in milliseconds | |
| jobStepMetric.setValue(int(time.time() * 1000), { | |
| 'name': 'my_cron', | |
| 'step': 'end' | |
| }) | |
| # Dispatch the "start" and "end" of "my_cron" to Pushgateway | |
| dispatcher.dispatch('my_cron') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment