start adding service successful/failed processing counts

This commit is contained in:
timelesnesses 2024-04-23 04:21:00 +07:00
parent aa56653483
commit 4cc0054eb9
No known key found for this signature in database
GPG Key ID: 85E31BB232268F65
3 changed files with 48 additions and 8 deletions

View File

@ -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) => {

View File

@ -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' };
}

View File

@ -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
}