使用UptimeFlare在Cloudflare Workers上部署Status Page
UptimeFlare不僅是一個Status Page(服務狀態),更像是網站監控服務,一旦斷線馬上發送通知。本身部署在Cloudflare Pages、Workers和KV上,功能相當全面,所以我也用它在status.ghost.tw建立一個Status Page。第一次部署要花一些時間,請耐心等待。
其中最耗流量的是Cloudflare Workers KV免費版限制──每日1000次寫入、刪除、列出操作。我監控自己的四個網站,寫入操作偶爾超過500次多一點,平常皆低於500次。
該專案持續更新中,作者把安裝文件寫的很清楚:
https://github.com/lyc8503/UptimeFlare/wiki
部署時,只要修改設定檔uptime.config.ts:
const pageConfig = {
// Title for your status page
title: "MYNET's Status Page",
// Links shown at the header of your status page, could set `highlight` to `true`
links: [
{ link: 'mailto:reports@mynet.tw', label: 'Email Me', highlight: true },
],
}
const workerConfig = {
// Write KV at most every 3 minutes unless the status changed.
kvWriteCooldownMinutes: 3,
// Define all your monitors here
monitors: [
{
id: 'foo_monitor_1',
name: 'Carlos Life Book',
method: 'GET',
target: 'https://carlos.mynet.tw',
tooltip: 'Carlos Life Book',
statusPageLink: 'https://carlos.mynet.tw',
expectedCodes: [200],
timeout: 10000,
headers: {
'User-Agent': 'Uptimeflare',
},
},
{
id: 'foo_monitor_2',
name: 'RACE.TW',
method: 'GET',
target: 'https://race.tw',
tooltip: 'RACE.TW',
statusPageLink: 'https://race.tw',
expectedCodes: [200],
timeout: 10000,
headers: {
'User-Agent': 'Uptimeflare',
},
},
{
id: 'foo_monitor_3',
name: 'GHOST.TW',
method: 'GET',
target: 'https://ghost.tw',
tooltip: 'GHOST.TW',
statusPageLink: 'https://ghost.tw',
expectedCodes: [200],
timeout: 10000,
headers: {
'User-Agent': 'Uptimeflare',
},
},
],
notification: {
// [Optional] apprise API server URL
// if not specified, no notification will be sent
appriseApiServer: "https://apprise.example.com/notify",
// [Optional] recipient URL for apprise, refer to https://github.com/caronc/apprise
// if not specified, no notification will be sent
recipientUrl: "tgram://bottoken/ChatID",
// [Optional] timezone used in notification messages, default to "Etc/GMT"
timeZone: "Asia/Taipei",
// [Optional] grace period in minutes before sending a notification
// notification will be sent only if the monitor is down for N continuous checks after the initial failure
// if not specified, notification will be sent immediately
gracePeriod: 5,
},
callbacks: {
onStatusChange: async (
env: any,
monitor: any,
isUp: boolean,
timeIncidentStart: number,
timeNow: number,
reason: string
) => {
// This callback will be called when there's a status change for any monitor
// Write any Typescript code here
// This will not follow the grace period settings and will be called immediately when the status changes
// You need to handle the grace period manually if you want to implement it
},
onIncident: async (
env: any,
monitor: any,
timeIncidentStart: number,
timeNow: number,
reason: string
) => {
// This callback will be called EVERY 1 MINTUE if there's an on-going incident for any monitor
// Write any Typescript code here
},
},
}
// Don't forget this, otherwise compilation fails.
export { pageConfig, workerConfig }
斷線通知要另外部署機器人(文件也有教學),並填入設定,並備份好該設定檔。
安裝文件已經寫的很無腦(看圖都懂),連自動更新方式都寫好了,沒什麼部署難度。因為KV流量是共用,如果有其他專案也在跑,很快就耗盡。以後流量不夠用的話,計畫用其他免費方案替代,例如:在〈Awesome status pages〉列出許多方案供大家參考。