सभी सोर्स
Service Health Check
डेवलपर v1.0.0Monitor service endpoints and get notified when they go down
@codytseng #monitoring #health-check
कॉन्फ़िगरेशन
| नाम | कुंजी | प्रकार | आवश्यक | डिफ़ॉल्ट | विवरण |
|---|---|---|---|---|---|
| Service URLs | URLS | list | हाँ | — | URLs to monitor (e.g. https://example.com) |
सोर्स कोड
version: 1.0.0
name: Service Health Check
description: Monitor service endpoints and get notified when they go down
author: codytseng
author_url: https://github.com/codytseng
category: Developer
tags:
- monitoring
- health-check
config:
- key: URLS
name: Service URLs
type: list
required: true
description: URLs to monitor (e.g. https://example.com) version: 1.0.0
name: Service Health Check
description: Monitor service endpoints and get notified when they go down
author: codytseng
author_url: https://github.com/codytseng
category: Developer
tags:
- monitoring
- health-check
config:
- key: URLS
name: Service URLs
type: list
required: true
description: URLs to monitor (e.g. https://example.com) module.exports = async (api) => {
const urls = api.config.get("URLS");
async function fetchData() {
if (!urls || urls.length === 0) return;
const previousDownUrls = new Set(
JSON.parse(api.storage.get("downUrls") ?? `[]`),
);
const currentDownUrls = new Set();
await Promise.allSettled(
urls.map(async (url) => {
const res = await api.fetch(url);
if (!res.ok) {
currentDownUrls.add(url);
if (!previousDownUrls.has(url)) {
api.emit([
{
id: `${url}-${Date.now()}`,
title: `Failed to fetch ${url}`,
subtitle: `HTTP ${res.status}, error: ${res.error || "unknown"}`,
url,
timestamp: Date.now(),
},
]);
}
}
}),
);
// Store the current down URLs for the next refresh
api.storage.set("downUrls", JSON.stringify(Array.from(currentDownUrls)));
}
await fetchData();
return {
refresh: fetchData,
};
}; module.exports = async (api) => {
const urls = api.config.get("URLS");
async function fetchData() {
if (!urls || urls.length === 0) return;
const previousDownUrls = new Set(
JSON.parse(api.storage.get("downUrls") ?? `[]`),
);
const currentDownUrls = new Set();
await Promise.allSettled(
urls.map(async (url) => {
const res = await api.fetch(url);
if (!res.ok) {
currentDownUrls.add(url);
if (!previousDownUrls.has(url)) {
api.emit([
{
id: `${url}-${Date.now()}`,
title: `Failed to fetch ${url}`,
subtitle: `HTTP ${res.status}, error: ${res.error || "unknown"}`,
url,
timestamp: Date.now(),
},
]);
}
}
}),
);
// Store the current down URLs for the next refresh
api.storage.set("downUrls", JSON.stringify(Array.from(currentDownUrls)));
}
await fetchData();
return {
refresh: fetchData,
};
};