Created
May 3, 2020 17:51
-
-
Save dgl/728f79a3d1bfedc794b5b0a47adc866b to your computer and use it in GitHub Desktop.
Pushgateway powered reminders!
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
<!DOCTYPE html> | |
<script> | |
const PUSHGATEWAY = 'http://pushgateway:9091'; | |
class Pushgateway { | |
constructor(baseUrl, instanceLabels) { | |
this.baseUrl = baseUrl; | |
this.instanceLabels = instanceLabels; | |
} | |
async push(metrics) { | |
let url = this.baseUrl + "/metrics/" + | |
Object.keys(this.instanceLabels).map(k => k + "/" + | |
encodeURIComponent(this.instanceLabels[k])).join("/"); | |
return await fetch(url, { | |
mode: "no-cors", | |
method: "POST", | |
headers: { | |
"Content-Type": "text/plain", | |
}, | |
body: Object.keys(metrics).map( | |
k => k + " " + metrics[k]).join("\n") + "\n", | |
}); | |
} | |
} | |
let pg = new Pushgateway(PUSHGATEWAY, { | |
job: "reminder", | |
for: "Walk the dog", | |
}); | |
</script> | |
<button onclick="pg.push({reminder_in_seconds: 6*3600})">Add reminder to walk the dog in 6 hours</button> |
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
# Prometheus alert rule: | |
groups: | |
- name: reminder | |
rules: | |
- alert: TimeTo | |
expr: | | |
time() > push_time_seconds{job="reminder"} | |
+ reminder_in_seconds{job="reminder"} | |
labels: | |
severity: reminder | |
annotations: | |
summary: "{{ $labels.for }}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment