1
0
mirror of https://github.com/tormachris/cf-workers-status-page.git synced 2025-07-17 04:15:15 +02:00

feat: collect response metrics from cron locations

This commit is contained in:
Adam Janis
2020-11-21 22:01:28 +01:00
parent 35c620f485
commit 7051f275e7
12 changed files with 177 additions and 106 deletions

View File

@ -1,18 +1,20 @@
import config from '../../config.yaml'
import { useEffect, useState } from 'react'
export async function getMonitors() {
return await getKVWithMetadata('monitors_data', 'json')
export async function getKVMonitors() {
// trying both to see performance difference
return KV_STATUS_PAGE.get('monitors_data', 'json')
//return JSON.parse(await KV_STATUS_PAGE.get('monitors_data', 'text'))
}
export async function setKVMonitors(data) {
return setKV('monitors_data', JSON.stringify(data))
}
export async function setKV(key, value, metadata, expirationTtl) {
return KV_STATUS_PAGE.put(key, value, { metadata, expirationTtl })
}
export async function getKVWithMetadata(key, type = 'text') {
return KV_STATUS_PAGE.getWithMetadata(key, type)
}
export async function notifySlack(monitor, operational) {
const payload = {
attachments: [
@ -23,10 +25,11 @@ export async function notifySlack(monitor, operational) {
type: 'section',
text: {
type: 'mrkdwn',
text: `Monitor *${monitor.name}* changed status to *${operational
text: `Monitor *${monitor.name}* changed status to *${
operational
? config.settings.monitorLabelOperational
: config.settings.monitorLabelNotOperational
}*`,
}*`,
},
},
{
@ -34,9 +37,11 @@ export async function notifySlack(monitor, operational) {
elements: [
{
type: 'mrkdwn',
text: `${operational ? ':white_check_mark:' : ':x:'} \`${monitor.method ? monitor.method : 'GET'
} ${monitor.url}\` - :eyes: <${config.settings.url
}|Status Page>`,
text: `${operational ? ':white_check_mark:' : ':x:'} \`${
monitor.method ? monitor.method : 'GET'
} ${monitor.url}\` - :eyes: <${
config.settings.url
}|Status Page>`,
},
],
},
@ -78,3 +83,10 @@ export function useKeyPress(targetKey) {
return keyPressed
}
export async function getCheckLocation() {
const res = await fetch('https://cloudflare-dns.com/dns-query', {
method: 'OPTIONS',
})
return res.headers.get('cf-ray').split('-')[1]
}