plugins: mark entrypoint as index

This commit is contained in:
undefined committed 2022-10-05 18:07:16 +08:00
1 parent 1210957a2a
commit 833b960a48
14 files changed
+81 -81

No files matched your search

+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "@hydrooj/center",
"version": "0.1.3",
"main": "package.json",
"main": "index.ts",
"repository": "https://github.com/hydro-dev/Hydro.git",
"author": "undefined <i@undefined.moe>",
"license": "AGPL-3.0-or-later",
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "@hydrooj/elastic-search",
"version": "1.0.8",
"main": "package.json",
"main": "index.ts",
"repository": "https://github.com/hydro-dev/Hydro",
"author": "undefined <i@undefined.moe>",
"license": "AGPL-3.0-or-later",
+1 -1
View File
@@ -2,7 +2,7 @@
"name": "@hydrooj/import-qduoj",
"version": "1.3.4",
"description": "Import QDUOJ problem export",
"main": "package.json",
"main": "index.ts",
"repository": "https://github.com/hydro-dev/Hydro.git",
"author": "undefined <i@undefined.moe>",
"license": "AGPL-3.0-or-later",
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "@hydrooj/login-with-github",
"version": "0.1.6",
"main": "package.json",
"main": "index.ts",
"repository": "git@github.com:hydro-dev/Hydro.git",
"author": "undefined <i@undefined.moe>",
"license": "AGPL-3.0-or-later",
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "@hydrooj/login-with-google",
"version": "0.1.1",
"main": "package.json",
"main": "index.ts",
"repository": "git@github.com:hydro-dev/Hydro.git",
"author": "undefined <i@undefined.moe>",
"license": "AGPL-3.0-or-later",
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "@hydrooj/migrate",
"version": "0.1.5",
"main": "package.json",
"main": "index.ts",
"repository": "git@github.com:hydro-dev/Hydro.git",
"author": "undefined <i@undefined.moe>",
"license": "AGPL-3.0-or-later",
File renamed without changes.
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "@hydrooj/onlyoffice",
"version": "1.2.0",
"main": "package.json",
"main": "index.ts",
"repository": "git@github.com:hydro-dev/Hydro.git",
"author": "undefined <i@undefined.moe>",
"preferUnplugged": true,
@@ -1,13 +1,11 @@
import { AggregatorRegistry, metric } from 'prom-client';
import { Context, Handler, SystemModel } from 'hydrooj';
import { registry } from './metrics';
import { createRegistry } from './metrics';
declare module 'hydrooj' {
interface EventMap {
metrics: (id: string, metrics: any) => void;
}
}
declare module 'hydrooj' {
interface SystemKeys {
'prom-client.name': string;
'prom-client.password': string;
@@ -41,6 +39,7 @@ class MetricsHandler extends Handler {
}
export function apply(ctx: Context) {
const registry = createRegistry(ctx);
ctx.on('metrics', (id, metrics) => { instances[id] = metrics; });
ctx.setInterval(async () => {
ctx.broadcast('metrics', process.env.NODE_APP_INSTANCE!, await registry.getMetricsAsJSON());
+60 -57
View File
@@ -1,62 +1,65 @@
import {
collectDefaultMetrics, Counter, Gauge, Metric, Registry,
} from 'prom-client';
import { db } from 'hydrooj';
import * as bus from 'hydrooj/src/service/bus';
import { Context, db } from 'hydrooj';
export const registry = new Registry();
registry.setDefaultLabels({ instanceid: process.env.NODE_APP_INSTANCE });
function createMetric<Q extends string, T extends (new (a: any) => Metric<Q>)>(
C: T, name: string, help: string, extra?: T extends new (a: infer R) => any ? Partial<R> : never,
): T extends (new (a) => Gauge<Q>) ? Gauge<Q> : T extends (new (a) => Counter<Q>) ? Counter<Q> : Metric<Q> {
const metric = new C({ name, help, ...(extra || {}) });
registry.registerMetric(metric);
return metric as any;
export function createRegistry(ctx: Context) {
const registry = new Registry();
registry.setDefaultLabels({ instanceid: process.env.NODE_APP_INSTANCE });
function createMetric<Q extends string, T extends (new (a: any) => Metric<Q>)>(
C: T, name: string, help: string, extra?: T extends new (a: infer R) => any ? Partial<R> : never,
): T extends (new (a) => Gauge<Q>) ? Gauge<Q> : T extends (new (a) => Counter<Q>) ? Counter<Q> : Metric<Q> {
const metric = new C({ name, help, ...(extra || {}) });
registry.registerMetric(metric);
return metric as any;
}
const reqCounter = createMetric(Counter, 'hydro_reqcount', 'reqcount', {
labelNames: ['domainId'],
});
ctx.on('handler/create', (h) => reqCounter.inc({ domainId: h.args.domainId }));
const judgeCounter = createMetric(Counter, 'hydro_judgecount', 'judgecount');
ctx.on('record/judge', () => judgeCounter.inc());
createMetric(Gauge, 'hydro_regcount', 'regcount', {
async collect() {
this.set({}, await db.collection('user').countDocuments());
},
});
const submissionCounter = createMetric(Counter, 'hydro_submission', 'submissioncount', {
labelNames: ['lang', 'domainId'],
});
ctx.on('handler/after/ProblemSubmit', (that) => {
submissionCounter.inc({ lang: that.args.lang, domainId: that.args.domainId });
});
const connectionGauge = createMetric(Gauge, 'hydro_connection', 'connectioncount', {
labelNames: ['domainId'],
});
ctx.on('connection/active', (h) => {
connectionGauge.inc({ domainId: h.args.domainId });
});
ctx.on('connection/close', (h) => {
connectionGauge.dec({ domainId: h.args.domainId });
});
const taskColl = db.collection('task');
createMetric(Gauge, 'hydro_task', 'taskcount', {
async collect() {
const data = await taskColl.aggregate([
{ $group: { _id: '$type', count: { $sum: 1 } } },
]).toArray();
this.reset();
for (const line of data) {
this.set({ type: line._id as unknown as string }, line.count);
}
},
labelNames: ['type'],
});
collectDefaultMetrics({ register: registry });
return registry;
}
const reqCounter = createMetric(Counter, 'hydro_reqcount', 'reqcount', {
labelNames: ['domainId'],
});
bus.on('handler/create', (h) => reqCounter.inc({ domainId: h.args.domainId }));
const judgeCounter = createMetric(Counter, 'hydro_judgecount', 'judgecount');
bus.on('record/judge', () => judgeCounter.inc());
createMetric(Gauge, 'hydro_regcount', 'regcount', {
async collect() {
this.set({}, await db.collection('user').countDocuments());
},
});
const submissionCounter = createMetric(Counter, 'hydro_submission', 'submissioncount', {
labelNames: ['lang', 'domainId'],
});
bus.on('handler/after/ProblemSubmit', (that) => {
submissionCounter.inc({ lang: that.args.lang, domainId: that.args.domainId });
});
const connectionGauge = createMetric(Gauge, 'hydro_connection', 'connectioncount', {
labelNames: ['domainId'],
});
bus.on('connection/active', (h) => {
connectionGauge.inc({ domainId: h.args.domainId });
});
bus.on('connection/close', (h) => {
connectionGauge.dec({ domainId: h.args.domainId });
});
const taskColl = db.collection('task');
createMetric(Gauge, 'hydro_task', 'taskcount', {
async collect() {
const data = await taskColl.aggregate([
{ $group: { _id: '$type', count: { $sum: 1 } } },
]).toArray();
this.reset();
for (const line of data) {
this.set({ type: line._id as unknown as string }, line.count);
}
},
labelNames: ['type'],
});
collectDefaultMetrics({ register: registry });
+1
View File
@@ -1,6 +1,7 @@
{
"name": "@hydrooj/prom-client",
"version": "0.0.4",
"main": "index.ts",
"dependencies": {
"prom-client": "^14.1.0"
}
+1 -1
View File
@@ -2,7 +2,7 @@
"name": "@hydrooj/recaptcha",
"version": "1.1.0",
"description": "Google reCAPTCHA",
"main": "package.json",
"main": "index.ts",
"repository": "https://github.com/hydro-dev/Hydro.git",
"author": "undefined",
"license": "AGPL-3.0-or-later",
+1 -1
View File
@@ -2,7 +2,7 @@
"name": "@hydrooj/sonic",
"version": "1.2.7",
"description": "Sonic search service",
"main": "service.ts",
"main": "index.ts",
"preferUnplugged": true,
"repository": "https://github.com/hydro-dev/Hydro.git",
"author": "undefined <i@undefined.moe>",
+9 -12
View File
@@ -121,17 +121,6 @@ class Service {
}
}
async function loadAccounts() {
// Only start a single daemon
if (process.env.NODE_APP_INSTANCE !== '0') return;
const accounts = await coll.find().toArray();
for (const account of accounts) {
if (!providers[account.type]) continue;
if (account.enableOn && !account.enableOn.includes(os.hostname())) continue;
Pool[`${account.type}/${account.handle}`] = new Service(providers[account.type], account);
}
}
declare module 'hydrooj' {
interface Model {
vjudge: VJudgeModel;
@@ -151,5 +140,13 @@ class VJudgeModel {
global.Hydro.model.vjudge = VJudgeModel;
export function apply(ctx: Context) {
ctx.on('ready', loadAccounts);
if (process.env.NODE_APP_INSTANCE !== '0') return;
ctx.on('ready', async () => {
const accounts = await coll.find().toArray();
for (const account of accounts) {
if (!providers[account.type]) continue;
if (account.enableOn && !account.enableOn.includes(os.hostname())) continue;
Pool[`${account.type}/${account.handle}`] = new Service(providers[account.type], account);
}
});
}