Skip to content

Instantly share code, notes, and snippets.

@dgl
Created May 3, 2020 17:51
Show Gist options
  • Save dgl/728f79a3d1bfedc794b5b0a47adc866b to your computer and use it in GitHub Desktop.
Save dgl/728f79a3d1bfedc794b5b0a47adc866b to your computer and use it in GitHub Desktop.
Pushgateway powered reminders!
<!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>
# 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