-
Notifications
You must be signed in to change notification settings - Fork 0
Configuration
wumingshi edited this page Dec 7, 2024
·
1 revision
所有 UptimeFlare 的配置都在 uptime.config.ts 文件中完成。创建你自己的 UptimeFlare 仓库后,你需要修改仓库中的 uptime.config.ts 文件来定义所需的监控和其他配置。
这是一个 TypeScript 文件,但用作配置文件时,它类似于 JSON。
模板中提供的 uptime.config.ts 文件是最新完整的配置,通常你不需要使用所有选项。下面我将解释一些常用的配置,并提供一个更简单的配置作为参考。
PageConfig 主要是状态页面相关的配置项,包括状态页面的标题和右上角的状态页面链接。
这些配置项非常直观,根据需要进行修改即可!
const pageConfig = {
title: "lyc8503 的状态页面",
links: [
{ link: 'https://github.com/lyc8503', label: 'GitHub' },
{ link: 'https://blog.lyc8503.site/', label: '博客' },
{ link: 'mailto:me@lyc8503.site', label: '联系我', highlight: true },
],
}WorkerConfig 主要用于工作线程中的监控,主要的监控项定义在 monitors 数组中。
notification 包含与发送通知相关的配置,如果你希望在监控状态发生变化时收到通知,请参阅 设置通知。
通常你不需要更改 kvWriteCooldownMinutes 和 callbacks,只需保留其默认值即可。
如果你想将状态页面设为私有(当然这是可选的),可以通过提供 passwordProtection 来设置用户名和密码。
const workerConfig = {
kvWriteCooldownMinutes: 3,
passwordProtection: 'username:password',
monitors: [
{
id: 'foo_monitor',
name: '我的 API 监控',
method: 'GET',
target: 'https://www.google.com'
},
{
id: 'test_tcp_monitor',
name: '示例 TCP 监控',
method: 'TCP_PING',
target: '1.2.3.4:22'
},
// 你可以继续定义更多的监控项...
],
notification: {
//...
},
callbacks: {
//...
},
}单个监控项的完整配置如下所示,如果你不知道某个字段的作用,可以不包含它!
{
// `id` 应该是唯一的,如果 `id` 保持不变,历史记录将被保留
id: 'foo_monitor',
// `name` 用于状态页面和回调消息
name: '我的 API 监控',
// `method` 应该是一个有效的 HTTP 方法或 "TCP_PING" 用于 TCP 端口监控
method: 'POST',
// `target` 是一个有效的 HTTP URL 或主机名:端口用于 TCP
target: 'https://example.com',
// [可选] `tooltip` 仅用于状态页面显示提示信息
tooltip: '这是此监控的提示信息',
// [可选] `statusPageLink` 仅用于状态页面上的可点击链接
statusPageLink: 'https://example.com',
// [可选] `expectedCodes` 是一个可接受的 HTTP 响应代码数组,如果不指定,默认为 2xx
expectedCodes: [200],
// [可选] 超时时间(毫秒),如果不指定,默认为 10000
timeout: 10000,
// [可选] 随 HTTP 监控发送的头部
headers: {
'User-Agent': 'Uptimeflare',
Authorization: 'Bearer YOUR_TOKEN_HERE',
},
// [可选] 随 HTTP 监控发送的请求体
body: 'Hello, world!',
// [可选] 如果指定,HTTP 响应必须包含关键词才能被视为正常运行
responseKeyword: 'success',
// [可选] 如果指定,检查将在你指定的区域运行,
// 请在设置此值之前参考文档 https://github.com/lyc8503/UptimeFlare/wiki/Geo-specific-checks-setup
checkLocationWorkerRoute: 'https://xxx.example.com',
},const pageConfig = {
title: "lyc8503 的状态页面",
links: [
{ link: 'https://github.com/lyc8503', label: 'GitHub' },
{ link: 'mailto:me@lyc8503.site', label: '联系我', highlight: true },
],
}
const workerConfig = {
kvWriteCooldownMinutes: 3,
passwordProtection: 'username:password',
monitors: [
{
id: 'google_monitor',
name: '我的 Google 监控',
method: 'GET',
target: 'https://www.google.com'
},
{
id: 'ssh_monitor',
name: '示例 SSH 监控',
method: 'TCP_PING',
target: '1.2.3.4:22'
},
],
callbacks: {
onStatusChange: async (
env: any,
monitor: any,
isUp: boolean,
timeIncidentStart: number,
timeNow: number,
reason: string,
) => {
// 当任何监控的状态发生变化时,此回调将被调用
// 在这里编写任何 TypeScript 代码
// 这不会遵循宽限期设置,当状态变化时会立即调用
// 如果你需要实现宽限期,请手动处理
},
onIncident: async (
env: any,
monitor: any,
timeIncidentStart: number,
timeNow: number,
reason: string,
) => {
// 当任何监控出现持续事件时,此回调将每分钟调用一次
// 在这里编写任何 TypeScript 代码
},
},
}
// 不要忘记这一步,否则编译会失败。
export { pageConfig, workerConfig }