diff --git a/api/core/endpoints.js b/api/core/endpoints.js index d7323cce..c44ab44f 100644 --- a/api/core/endpoints.js +++ b/api/core/endpoints.js @@ -13,7 +13,7 @@ import stream from "../modules/stream/stream.js"; import { generateHmac } from "../modules/util/crypto.js"; import { verifyStream } from "../modules/stream/manage.js"; -export function runAPI(express, app, gitCommit, gitBranch, __dirname) { +export function runAPI(express, app, gitCommit, gitBranch, __dirname) { const corsConfig = process.env.CORS_WILDCARD === '0' ? { origin: process.env.CORS_URL, optionsSuccessStatus: 200 @@ -62,8 +62,7 @@ export function runAPI(express, app, gitCommit, gitBranch, __dirname) { app.use(expressPrometheusMiddleware({ metricsApp: app, - collectGCMetrics: true, - + collectGCMetrics: true })) app.use((req, res, next) => { diff --git a/api/modules/processing/services/bilibili.js b/api/modules/processing/services/bilibili.js index 5700573b..dad55e35 100644 --- a/api/modules/processing/services/bilibili.js +++ b/api/modules/processing/services/bilibili.js @@ -1,7 +1,17 @@ import { genericUserAgent, maxVideoDuration } from "../../../core/config.js"; +import { Counter } from "prom-client"; // TO-DO: higher quality downloads (currently requires an account) +let successBilibiliStreamCount = new Counter({ + name: "cobalt_bilibili_stream_count", + help: "Successful Bilibili stream counts" +}); +let failedBilibiliStreamCount = new Counter({ + name: "cobalt_bilibili_stream_count", + help: "Failed Bilibili stream counts" +}); + function com_resolveShortlink(shortId) { return fetch(`https://b23.tv/${shortId}`, { redirect: 'manual' }) .then(r => r.status > 300 && r.status < 400 && r.headers.get('location')) @@ -11,7 +21,7 @@ function com_resolveShortlink(shortId) { if (path.startsWith('/video/')) return path.split('/')[2]; }) - .catch(() => {}) + .catch(() => { failedBilibiliStreamCount.inc() }) } function getBest(content) { @@ -96,10 +106,22 @@ export default async function({ comId, tvId, comShortLink }) { } if (comId) { - return com_download(comId); + let status = com_download(comId); + if (!status) { + failedBilibiliStreamCount.inc(); + } else { + successBilibiliStreamCount.inc(); + } + return status; } else if (tvId) { - return tv_download(tvId); + let status = tv_download(tvId); + if (!status) { + failedBilibiliStreamCount.inc() + } else { + successBilibiliStreamCount.inc() + } + return status } - + failedBilibiliStreamCount.inc() return { error: 'ErrorCouldntFetch' }; } diff --git a/api/modules/processing/services/dailymotion.js b/api/modules/processing/services/dailymotion.js index 598123c7..f915d876 100644 --- a/api/modules/processing/services/dailymotion.js +++ b/api/modules/processing/services/dailymotion.js @@ -1,8 +1,17 @@ import HLSParser from 'hls-parser'; import { maxVideoDuration } from '../../../core/config.js'; +import { Counter } from 'prom-client'; let _token; +let successDailymotionStreamCount = new Counter({ + name: "cobalt_success_dailymotion_stream_count", + help: "Success Dailymotion stream counts" +}); +let failedDailymotionStreamCount = new Counter({ + name: "cobalt_dailymotion_stream_count", + help: "Failed Dailymotion stream counts" +}); function getExp(token) { return JSON.parse( Buffer.from(token.split('.')[1], 'base64') @@ -29,7 +38,7 @@ const getToken = async () => { } } -export default async function({ id }) { +async function download({ id }) { const token = await getToken(); if (!token) return { error: 'ErrorSomethingWentWrong' }; @@ -105,3 +114,13 @@ export default async function({ id }) { fileMetadata } } + +export default async function ({ id }) { + let status = await download({ id }) + if (status.error) { + failedDailymotionStreamCount.inc() + } else { + successDailymotionStreamCount.inc() + } + return status +} \ No newline at end of file