mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
plugins: mark entrypoint as index
This commit is contained in:
1 parent
1210957a2a
commit
833b960a48
14 files changed
+81
-81
No files matched your search
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@hydrooj/center",
|
"name": "@hydrooj/center",
|
||||||
"version": "0.1.3",
|
"version": "0.1.3",
|
||||||
"main": "package.json",
|
"main": "index.ts",
|
||||||
"repository": "https://github.com/hydro-dev/Hydro.git",
|
"repository": "https://github.com/hydro-dev/Hydro.git",
|
||||||
"author": "undefined <i@undefined.moe>",
|
"author": "undefined <i@undefined.moe>",
|
||||||
"license": "AGPL-3.0-or-later",
|
"license": "AGPL-3.0-or-later",
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@hydrooj/elastic-search",
|
"name": "@hydrooj/elastic-search",
|
||||||
"version": "1.0.8",
|
"version": "1.0.8",
|
||||||
"main": "package.json",
|
"main": "index.ts",
|
||||||
"repository": "https://github.com/hydro-dev/Hydro",
|
"repository": "https://github.com/hydro-dev/Hydro",
|
||||||
"author": "undefined <i@undefined.moe>",
|
"author": "undefined <i@undefined.moe>",
|
||||||
"license": "AGPL-3.0-or-later",
|
"license": "AGPL-3.0-or-later",
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
"name": "@hydrooj/import-qduoj",
|
"name": "@hydrooj/import-qduoj",
|
||||||
"version": "1.3.4",
|
"version": "1.3.4",
|
||||||
"description": "Import QDUOJ problem export",
|
"description": "Import QDUOJ problem export",
|
||||||
"main": "package.json",
|
"main": "index.ts",
|
||||||
"repository": "https://github.com/hydro-dev/Hydro.git",
|
"repository": "https://github.com/hydro-dev/Hydro.git",
|
||||||
"author": "undefined <i@undefined.moe>",
|
"author": "undefined <i@undefined.moe>",
|
||||||
"license": "AGPL-3.0-or-later",
|
"license": "AGPL-3.0-or-later",
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@hydrooj/login-with-github",
|
"name": "@hydrooj/login-with-github",
|
||||||
"version": "0.1.6",
|
"version": "0.1.6",
|
||||||
"main": "package.json",
|
"main": "index.ts",
|
||||||
"repository": "git@github.com:hydro-dev/Hydro.git",
|
"repository": "git@github.com:hydro-dev/Hydro.git",
|
||||||
"author": "undefined <i@undefined.moe>",
|
"author": "undefined <i@undefined.moe>",
|
||||||
"license": "AGPL-3.0-or-later",
|
"license": "AGPL-3.0-or-later",
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@hydrooj/login-with-google",
|
"name": "@hydrooj/login-with-google",
|
||||||
"version": "0.1.1",
|
"version": "0.1.1",
|
||||||
"main": "package.json",
|
"main": "index.ts",
|
||||||
"repository": "git@github.com:hydro-dev/Hydro.git",
|
"repository": "git@github.com:hydro-dev/Hydro.git",
|
||||||
"author": "undefined <i@undefined.moe>",
|
"author": "undefined <i@undefined.moe>",
|
||||||
"license": "AGPL-3.0-or-later",
|
"license": "AGPL-3.0-or-later",
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@hydrooj/migrate",
|
"name": "@hydrooj/migrate",
|
||||||
"version": "0.1.5",
|
"version": "0.1.5",
|
||||||
"main": "package.json",
|
"main": "index.ts",
|
||||||
"repository": "git@github.com:hydro-dev/Hydro.git",
|
"repository": "git@github.com:hydro-dev/Hydro.git",
|
||||||
"author": "undefined <i@undefined.moe>",
|
"author": "undefined <i@undefined.moe>",
|
||||||
"license": "AGPL-3.0-or-later",
|
"license": "AGPL-3.0-or-later",
|
||||||
|
|||||||
File renamed without changes.
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@hydrooj/onlyoffice",
|
"name": "@hydrooj/onlyoffice",
|
||||||
"version": "1.2.0",
|
"version": "1.2.0",
|
||||||
"main": "package.json",
|
"main": "index.ts",
|
||||||
"repository": "git@github.com:hydro-dev/Hydro.git",
|
"repository": "git@github.com:hydro-dev/Hydro.git",
|
||||||
"author": "undefined <i@undefined.moe>",
|
"author": "undefined <i@undefined.moe>",
|
||||||
"preferUnplugged": true,
|
"preferUnplugged": true,
|
||||||
|
|||||||
@@ -1,13 +1,11 @@
|
|||||||
import { AggregatorRegistry, metric } from 'prom-client';
|
import { AggregatorRegistry, metric } from 'prom-client';
|
||||||
import { Context, Handler, SystemModel } from 'hydrooj';
|
import { Context, Handler, SystemModel } from 'hydrooj';
|
||||||
import { registry } from './metrics';
|
import { createRegistry } from './metrics';
|
||||||
|
|
||||||
declare module 'hydrooj' {
|
declare module 'hydrooj' {
|
||||||
interface EventMap {
|
interface EventMap {
|
||||||
metrics: (id: string, metrics: any) => void;
|
metrics: (id: string, metrics: any) => void;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
declare module 'hydrooj' {
|
|
||||||
interface SystemKeys {
|
interface SystemKeys {
|
||||||
'prom-client.name': string;
|
'prom-client.name': string;
|
||||||
'prom-client.password': string;
|
'prom-client.password': string;
|
||||||
@@ -41,6 +39,7 @@ class MetricsHandler extends Handler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function apply(ctx: Context) {
|
export function apply(ctx: Context) {
|
||||||
|
const registry = createRegistry(ctx);
|
||||||
ctx.on('metrics', (id, metrics) => { instances[id] = metrics; });
|
ctx.on('metrics', (id, metrics) => { instances[id] = metrics; });
|
||||||
ctx.setInterval(async () => {
|
ctx.setInterval(async () => {
|
||||||
ctx.broadcast('metrics', process.env.NODE_APP_INSTANCE!, await registry.getMetricsAsJSON());
|
ctx.broadcast('metrics', process.env.NODE_APP_INSTANCE!, await registry.getMetricsAsJSON());
|
||||||
@@ -1,62 +1,65 @@
|
|||||||
import {
|
import {
|
||||||
collectDefaultMetrics, Counter, Gauge, Metric, Registry,
|
collectDefaultMetrics, Counter, Gauge, Metric, Registry,
|
||||||
} from 'prom-client';
|
} from 'prom-client';
|
||||||
import { db } from 'hydrooj';
|
import { Context, db } from 'hydrooj';
|
||||||
import * as bus from 'hydrooj/src/service/bus';
|
|
||||||
|
|
||||||
export const registry = new Registry();
|
export function createRegistry(ctx: Context) {
|
||||||
registry.setDefaultLabels({ instanceid: process.env.NODE_APP_INSTANCE });
|
const registry = new Registry();
|
||||||
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,
|
registry.setDefaultLabels({ instanceid: process.env.NODE_APP_INSTANCE });
|
||||||
): T extends (new (a) => Gauge<Q>) ? Gauge<Q> : T extends (new (a) => Counter<Q>) ? Counter<Q> : Metric<Q> {
|
function createMetric<Q extends string, T extends (new (a: any) => Metric<Q>)>(
|
||||||
const metric = new C({ name, help, ...(extra || {}) });
|
C: T, name: string, help: string, extra?: T extends new (a: infer R) => any ? Partial<R> : never,
|
||||||
registry.registerMetric(metric);
|
): T extends (new (a) => Gauge<Q>) ? Gauge<Q> : T extends (new (a) => Counter<Q>) ? Counter<Q> : Metric<Q> {
|
||||||
return metric as any;
|
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,6 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@hydrooj/prom-client",
|
"name": "@hydrooj/prom-client",
|
||||||
"version": "0.0.4",
|
"version": "0.0.4",
|
||||||
|
"main": "index.ts",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"prom-client": "^14.1.0"
|
"prom-client": "^14.1.0"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
"name": "@hydrooj/recaptcha",
|
"name": "@hydrooj/recaptcha",
|
||||||
"version": "1.1.0",
|
"version": "1.1.0",
|
||||||
"description": "Google reCAPTCHA",
|
"description": "Google reCAPTCHA",
|
||||||
"main": "package.json",
|
"main": "index.ts",
|
||||||
"repository": "https://github.com/hydro-dev/Hydro.git",
|
"repository": "https://github.com/hydro-dev/Hydro.git",
|
||||||
"author": "undefined",
|
"author": "undefined",
|
||||||
"license": "AGPL-3.0-or-later",
|
"license": "AGPL-3.0-or-later",
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
"name": "@hydrooj/sonic",
|
"name": "@hydrooj/sonic",
|
||||||
"version": "1.2.7",
|
"version": "1.2.7",
|
||||||
"description": "Sonic search service",
|
"description": "Sonic search service",
|
||||||
"main": "service.ts",
|
"main": "index.ts",
|
||||||
"preferUnplugged": true,
|
"preferUnplugged": true,
|
||||||
"repository": "https://github.com/hydro-dev/Hydro.git",
|
"repository": "https://github.com/hydro-dev/Hydro.git",
|
||||||
"author": "undefined <i@undefined.moe>",
|
"author": "undefined <i@undefined.moe>",
|
||||||
|
|||||||
@@ -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' {
|
declare module 'hydrooj' {
|
||||||
interface Model {
|
interface Model {
|
||||||
vjudge: VJudgeModel;
|
vjudge: VJudgeModel;
|
||||||
@@ -151,5 +140,13 @@ class VJudgeModel {
|
|||||||
global.Hydro.model.vjudge = VJudgeModel;
|
global.Hydro.model.vjudge = VJudgeModel;
|
||||||
|
|
||||||
export function apply(ctx: Context) {
|
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);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user