Skip to content

Instantly share code, notes, and snippets.

@lroudge
Last active May 26, 2020 11:25
Show Gist options
  • Select an option

  • Save lroudge/05b1dbf93eb2679ca443c4fffeebb528 to your computer and use it in GitHub Desktop.

Select an option

Save lroudge/05b1dbf93eb2679ca443c4fffeebb528 to your computer and use it in GitHub Desktop.
#!/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