@theia/metrics 1.45.1 → 1.46.0-next.72
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +30 -30
- package/lib/browser/metrics-frontend-application-contribution.d.ts +12 -12
- package/lib/browser/metrics-frontend-application-contribution.js +66 -66
- package/lib/browser/metrics-frontend-module.d.ts +3 -3
- package/lib/browser/metrics-frontend-module.js +28 -28
- package/lib/common/index.d.ts +1 -1
- package/lib/common/index.js +28 -28
- package/lib/common/measurement-notification-service.d.ts +11 -11
- package/lib/common/measurement-notification-service.js +20 -20
- package/lib/node/extensions-metrics-contribution.d.ts +8 -8
- package/lib/node/extensions-metrics-contribution.js +62 -62
- package/lib/node/index.d.ts +5 -5
- package/lib/node/index.js +32 -32
- package/lib/node/measurement-metrics-contribution.d.ts +17 -17
- package/lib/node/measurement-metrics-contribution.js +83 -83
- package/lib/node/metrics-backend-application-contribution.d.ts +15 -15
- package/lib/node/metrics-backend-application-contribution.js +59 -59
- package/lib/node/metrics-backend-module.d.ts +3 -3
- package/lib/node/metrics-backend-module.js +35 -35
- package/lib/node/metrics-contribution.d.ts +5 -5
- package/lib/node/metrics-contribution.js +19 -19
- package/lib/node/node-metrics-contribution.d.ts +5 -5
- package/lib/node/node-metrics-contribution.js +40 -40
- package/lib/node/prometheus.d.ts +2 -2
- package/lib/node/prometheus.js +27 -27
- package/lib/node/prometheus.spec.d.ts +1 -1
- package/lib/node/prometheus.spec.js +40 -40
- package/package.json +4 -4
- package/src/browser/metrics-frontend-application-contribution.ts +51 -51
- package/src/browser/metrics-frontend-module.ts +28 -28
- package/src/common/index.ts +17 -17
- package/src/common/measurement-notification-service.ts +29 -29
- package/src/node/extensions-metrics-contribution.ts +51 -51
- package/src/node/index.ts +21 -21
- package/src/node/measurement-metrics-contribution.ts +75 -75
- package/src/node/metrics-backend-application-contribution.ts +50 -50
- package/src/node/metrics-backend-module.ts +40 -40
- package/src/node/metrics-contribution.ts +20 -20
- package/src/node/node-metrics-contribution.ts +33 -33
- package/src/node/prometheus.spec.ts +49 -49
- package/src/node/prometheus.ts +25 -25
package/src/node/index.ts
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
// *****************************************************************************
|
|
2
|
-
// Copyright (C) 2018 Ericsson and others.
|
|
3
|
-
//
|
|
4
|
-
// This program and the accompanying materials are made available under the
|
|
5
|
-
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
-
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
-
//
|
|
8
|
-
// This Source Code may also be made available under the following Secondary
|
|
9
|
-
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
-
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
-
// with the GNU Classpath Exception which is available at
|
|
12
|
-
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
-
//
|
|
14
|
-
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
-
// *****************************************************************************
|
|
16
|
-
|
|
17
|
-
export * from './metrics-backend-application-contribution';
|
|
18
|
-
export * from './metrics-contribution';
|
|
19
|
-
export * from './node-metrics-contribution';
|
|
20
|
-
export * from './extensions-metrics-contribution';
|
|
21
|
-
export * from './prometheus';
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2018 Ericsson and others.
|
|
3
|
+
//
|
|
4
|
+
// This program and the accompanying materials are made available under the
|
|
5
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
//
|
|
8
|
+
// This Source Code may also be made available under the following Secondary
|
|
9
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
// with the GNU Classpath Exception which is available at
|
|
12
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
//
|
|
14
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
|
|
17
|
+
export * from './metrics-backend-application-contribution';
|
|
18
|
+
export * from './metrics-contribution';
|
|
19
|
+
export * from './node-metrics-contribution';
|
|
20
|
+
export * from './extensions-metrics-contribution';
|
|
21
|
+
export * from './prometheus';
|
|
@@ -1,75 +1,75 @@
|
|
|
1
|
-
// *****************************************************************************
|
|
2
|
-
// Copyright (C) 2023 STMicroelectronics and others.
|
|
3
|
-
//
|
|
4
|
-
// This program and the accompanying materials are made available under the
|
|
5
|
-
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
-
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
-
//
|
|
8
|
-
// This Source Code may also be made available under the following Secondary
|
|
9
|
-
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
-
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
-
// with the GNU Classpath Exception which is available at
|
|
12
|
-
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
-
//
|
|
14
|
-
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
-
// *****************************************************************************
|
|
16
|
-
import { inject, injectable, } from '@theia/core/shared/inversify';
|
|
17
|
-
import { MetricsContribution } from './metrics-contribution';
|
|
18
|
-
import { LogLevel, MeasurementResult, Stopwatch } from '@theia/core';
|
|
19
|
-
import { MeasurementNotificationService } from '../common';
|
|
20
|
-
import { LogLevelCliContribution } from '@theia/core/lib/node/logger-cli-contribution';
|
|
21
|
-
|
|
22
|
-
const backendId = 'backend';
|
|
23
|
-
const metricsName = 'theia_measurements';
|
|
24
|
-
|
|
25
|
-
@injectable()
|
|
26
|
-
export class MeasurementMetricsBackendContribution implements MetricsContribution, MeasurementNotificationService {
|
|
27
|
-
@inject(Stopwatch)
|
|
28
|
-
protected backendStopwatch: Stopwatch;
|
|
29
|
-
|
|
30
|
-
@inject(LogLevelCliContribution)
|
|
31
|
-
protected logLevelCli: LogLevelCliContribution;
|
|
32
|
-
|
|
33
|
-
protected metrics = '';
|
|
34
|
-
protected frontendCounters = new Map<string, string>();
|
|
35
|
-
|
|
36
|
-
startCollecting(): void {
|
|
37
|
-
if (this.logLevelCli.defaultLogLevel !== LogLevel.DEBUG) {
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
this.metrics += `# HELP ${metricsName} Theia stopwatch measurement results.\n`;
|
|
41
|
-
this.metrics += `# TYPE ${metricsName} gauge\n`;
|
|
42
|
-
this.backendStopwatch.storedMeasurements.forEach(result => this.onBackendMeasurement(result));
|
|
43
|
-
this.backendStopwatch.onDidAddMeasurementResult(result => this.onBackendMeasurement(result));
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
getMetrics(): string {
|
|
47
|
-
return this.metrics;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
protected appendMetricsValue(id: string, result: MeasurementResult): void {
|
|
51
|
-
const { name, elapsed, startTime, owner } = result;
|
|
52
|
-
const labels: string = `id="${id}", name="${name}", startTime="${startTime}", owner="${owner}"`;
|
|
53
|
-
const metricsValue = `${metricsName}{${labels}} ${elapsed}`;
|
|
54
|
-
this.metrics += (metricsValue + '\n');
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
protected onBackendMeasurement(result: MeasurementResult): void {
|
|
58
|
-
this.appendMetricsValue(backendId, result);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
protected createFrontendCounterId(frontendId: string): string {
|
|
62
|
-
const counterId = `frontend-${this.frontendCounters.size + 1}`;
|
|
63
|
-
this.frontendCounters.set(frontendId, counterId);
|
|
64
|
-
return counterId;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
protected toCounterId(frontendId: string): string {
|
|
68
|
-
return this.frontendCounters.get(frontendId) ?? this.createFrontendCounterId(frontendId);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
onFrontendMeasurement(frontendId: string, result: MeasurementResult): void {
|
|
72
|
-
this.appendMetricsValue(this.toCounterId(frontendId), result);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
}
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2023 STMicroelectronics and others.
|
|
3
|
+
//
|
|
4
|
+
// This program and the accompanying materials are made available under the
|
|
5
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
//
|
|
8
|
+
// This Source Code may also be made available under the following Secondary
|
|
9
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
// with the GNU Classpath Exception which is available at
|
|
12
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
//
|
|
14
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
import { inject, injectable, } from '@theia/core/shared/inversify';
|
|
17
|
+
import { MetricsContribution } from './metrics-contribution';
|
|
18
|
+
import { LogLevel, MeasurementResult, Stopwatch } from '@theia/core';
|
|
19
|
+
import { MeasurementNotificationService } from '../common';
|
|
20
|
+
import { LogLevelCliContribution } from '@theia/core/lib/node/logger-cli-contribution';
|
|
21
|
+
|
|
22
|
+
const backendId = 'backend';
|
|
23
|
+
const metricsName = 'theia_measurements';
|
|
24
|
+
|
|
25
|
+
@injectable()
|
|
26
|
+
export class MeasurementMetricsBackendContribution implements MetricsContribution, MeasurementNotificationService {
|
|
27
|
+
@inject(Stopwatch)
|
|
28
|
+
protected backendStopwatch: Stopwatch;
|
|
29
|
+
|
|
30
|
+
@inject(LogLevelCliContribution)
|
|
31
|
+
protected logLevelCli: LogLevelCliContribution;
|
|
32
|
+
|
|
33
|
+
protected metrics = '';
|
|
34
|
+
protected frontendCounters = new Map<string, string>();
|
|
35
|
+
|
|
36
|
+
startCollecting(): void {
|
|
37
|
+
if (this.logLevelCli.defaultLogLevel !== LogLevel.DEBUG) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
this.metrics += `# HELP ${metricsName} Theia stopwatch measurement results.\n`;
|
|
41
|
+
this.metrics += `# TYPE ${metricsName} gauge\n`;
|
|
42
|
+
this.backendStopwatch.storedMeasurements.forEach(result => this.onBackendMeasurement(result));
|
|
43
|
+
this.backendStopwatch.onDidAddMeasurementResult(result => this.onBackendMeasurement(result));
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
getMetrics(): string {
|
|
47
|
+
return this.metrics;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
protected appendMetricsValue(id: string, result: MeasurementResult): void {
|
|
51
|
+
const { name, elapsed, startTime, owner } = result;
|
|
52
|
+
const labels: string = `id="${id}", name="${name}", startTime="${startTime}", owner="${owner}"`;
|
|
53
|
+
const metricsValue = `${metricsName}{${labels}} ${elapsed}`;
|
|
54
|
+
this.metrics += (metricsValue + '\n');
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
protected onBackendMeasurement(result: MeasurementResult): void {
|
|
58
|
+
this.appendMetricsValue(backendId, result);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
protected createFrontendCounterId(frontendId: string): string {
|
|
62
|
+
const counterId = `frontend-${this.frontendCounters.size + 1}`;
|
|
63
|
+
this.frontendCounters.set(frontendId, counterId);
|
|
64
|
+
return counterId;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
protected toCounterId(frontendId: string): string {
|
|
68
|
+
return this.frontendCounters.get(frontendId) ?? this.createFrontendCounterId(frontendId);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
onFrontendMeasurement(frontendId: string, result: MeasurementResult): void {
|
|
72
|
+
this.appendMetricsValue(this.toCounterId(frontendId), result);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
}
|
|
@@ -1,50 +1,50 @@
|
|
|
1
|
-
// *****************************************************************************
|
|
2
|
-
// Copyright (C) 2017-2018 Ericsson and others.
|
|
3
|
-
//
|
|
4
|
-
// This program and the accompanying materials are made available under the
|
|
5
|
-
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
-
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
-
//
|
|
8
|
-
// This Source Code may also be made available under the following Secondary
|
|
9
|
-
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
-
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
-
// with the GNU Classpath Exception which is available at
|
|
12
|
-
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
-
//
|
|
14
|
-
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
-
// *****************************************************************************
|
|
16
|
-
|
|
17
|
-
import { injectable, inject, named } from '@theia/core/shared/inversify';
|
|
18
|
-
import * as http from 'http';
|
|
19
|
-
import * as https from 'https';
|
|
20
|
-
import * as express from '@theia/core/shared/express';
|
|
21
|
-
import { ContributionProvider } from '@theia/core/lib/common';
|
|
22
|
-
import { BackendApplicationContribution } from '@theia/core/lib/node';
|
|
23
|
-
import { MetricsContribution } from './metrics-contribution';
|
|
24
|
-
|
|
25
|
-
@injectable()
|
|
26
|
-
export class MetricsBackendApplicationContribution implements BackendApplicationContribution {
|
|
27
|
-
constructor(
|
|
28
|
-
@inject(ContributionProvider) @named(MetricsContribution)
|
|
29
|
-
protected readonly metricsProviders: ContributionProvider<MetricsContribution>
|
|
30
|
-
) {
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
configure(app: express.Application): void {
|
|
34
|
-
app.get('/metrics', (req, res) => {
|
|
35
|
-
const lastMetrics = this.fetchMetricsFromProviders();
|
|
36
|
-
res.send(lastMetrics);
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
onStart(server: http.Server | https.Server): void {
|
|
41
|
-
this.metricsProviders.getContributions().forEach(contribution => {
|
|
42
|
-
contribution.startCollecting();
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
fetchMetricsFromProviders(): string {
|
|
47
|
-
return this.metricsProviders.getContributions().reduce((total, contribution) =>
|
|
48
|
-
total += contribution.getMetrics() + '\n', '');
|
|
49
|
-
}
|
|
50
|
-
}
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2017-2018 Ericsson and others.
|
|
3
|
+
//
|
|
4
|
+
// This program and the accompanying materials are made available under the
|
|
5
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
//
|
|
8
|
+
// This Source Code may also be made available under the following Secondary
|
|
9
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
// with the GNU Classpath Exception which is available at
|
|
12
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
//
|
|
14
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
|
|
17
|
+
import { injectable, inject, named } from '@theia/core/shared/inversify';
|
|
18
|
+
import * as http from 'http';
|
|
19
|
+
import * as https from 'https';
|
|
20
|
+
import * as express from '@theia/core/shared/express';
|
|
21
|
+
import { ContributionProvider } from '@theia/core/lib/common';
|
|
22
|
+
import { BackendApplicationContribution } from '@theia/core/lib/node';
|
|
23
|
+
import { MetricsContribution } from './metrics-contribution';
|
|
24
|
+
|
|
25
|
+
@injectable()
|
|
26
|
+
export class MetricsBackendApplicationContribution implements BackendApplicationContribution {
|
|
27
|
+
constructor(
|
|
28
|
+
@inject(ContributionProvider) @named(MetricsContribution)
|
|
29
|
+
protected readonly metricsProviders: ContributionProvider<MetricsContribution>
|
|
30
|
+
) {
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
configure(app: express.Application): void {
|
|
34
|
+
app.get('/metrics', (req, res) => {
|
|
35
|
+
const lastMetrics = this.fetchMetricsFromProviders();
|
|
36
|
+
res.send(lastMetrics);
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
onStart(server: http.Server | https.Server): void {
|
|
41
|
+
this.metricsProviders.getContributions().forEach(contribution => {
|
|
42
|
+
contribution.startCollecting();
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
fetchMetricsFromProviders(): string {
|
|
47
|
+
return this.metricsProviders.getContributions().reduce((total, contribution) =>
|
|
48
|
+
total += contribution.getMetrics() + '\n', '');
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -1,40 +1,40 @@
|
|
|
1
|
-
// *****************************************************************************
|
|
2
|
-
// Copyright (C) 2017-2018 Ericsson and others.
|
|
3
|
-
//
|
|
4
|
-
// This program and the accompanying materials are made available under the
|
|
5
|
-
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
-
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
-
//
|
|
8
|
-
// This Source Code may also be made available under the following Secondary
|
|
9
|
-
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
-
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
-
// with the GNU Classpath Exception which is available at
|
|
12
|
-
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
-
//
|
|
14
|
-
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
-
// *****************************************************************************
|
|
16
|
-
|
|
17
|
-
import { ContainerModule } from '@theia/core/shared/inversify';
|
|
18
|
-
import { BackendApplicationContribution } from '@theia/core/lib/node';
|
|
19
|
-
import { ConnectionHandler, RpcConnectionHandler, bindContributionProvider } from '@theia/core/lib/common';
|
|
20
|
-
import { MetricsContribution } from './metrics-contribution';
|
|
21
|
-
import { NodeMetricsContribution } from './node-metrics-contribution';
|
|
22
|
-
import { ExtensionMetricsContribution } from './extensions-metrics-contribution';
|
|
23
|
-
import { MetricsBackendApplicationContribution } from './metrics-backend-application-contribution';
|
|
24
|
-
import { measurementNotificationServicePath } from '../common';
|
|
25
|
-
import { MeasurementMetricsBackendContribution } from './measurement-metrics-contribution';
|
|
26
|
-
|
|
27
|
-
export default new ContainerModule(bind => {
|
|
28
|
-
bindContributionProvider(bind, MetricsContribution);
|
|
29
|
-
bind(MetricsContribution).to(NodeMetricsContribution).inSingletonScope();
|
|
30
|
-
bind(MetricsContribution).to(ExtensionMetricsContribution).inSingletonScope();
|
|
31
|
-
|
|
32
|
-
bind(MeasurementMetricsBackendContribution).toSelf().inSingletonScope();
|
|
33
|
-
bind(MetricsContribution).toService(MeasurementMetricsBackendContribution);
|
|
34
|
-
bind(ConnectionHandler).toDynamicValue(ctx =>
|
|
35
|
-
new RpcConnectionHandler(measurementNotificationServicePath,
|
|
36
|
-
() => ctx.container.get(MeasurementMetricsBackendContribution)));
|
|
37
|
-
|
|
38
|
-
bind(BackendApplicationContribution).to(MetricsBackendApplicationContribution).inSingletonScope();
|
|
39
|
-
|
|
40
|
-
});
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2017-2018 Ericsson and others.
|
|
3
|
+
//
|
|
4
|
+
// This program and the accompanying materials are made available under the
|
|
5
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
//
|
|
8
|
+
// This Source Code may also be made available under the following Secondary
|
|
9
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
// with the GNU Classpath Exception which is available at
|
|
12
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
//
|
|
14
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
|
|
17
|
+
import { ContainerModule } from '@theia/core/shared/inversify';
|
|
18
|
+
import { BackendApplicationContribution } from '@theia/core/lib/node';
|
|
19
|
+
import { ConnectionHandler, RpcConnectionHandler, bindContributionProvider } from '@theia/core/lib/common';
|
|
20
|
+
import { MetricsContribution } from './metrics-contribution';
|
|
21
|
+
import { NodeMetricsContribution } from './node-metrics-contribution';
|
|
22
|
+
import { ExtensionMetricsContribution } from './extensions-metrics-contribution';
|
|
23
|
+
import { MetricsBackendApplicationContribution } from './metrics-backend-application-contribution';
|
|
24
|
+
import { measurementNotificationServicePath } from '../common';
|
|
25
|
+
import { MeasurementMetricsBackendContribution } from './measurement-metrics-contribution';
|
|
26
|
+
|
|
27
|
+
export default new ContainerModule(bind => {
|
|
28
|
+
bindContributionProvider(bind, MetricsContribution);
|
|
29
|
+
bind(MetricsContribution).to(NodeMetricsContribution).inSingletonScope();
|
|
30
|
+
bind(MetricsContribution).to(ExtensionMetricsContribution).inSingletonScope();
|
|
31
|
+
|
|
32
|
+
bind(MeasurementMetricsBackendContribution).toSelf().inSingletonScope();
|
|
33
|
+
bind(MetricsContribution).toService(MeasurementMetricsBackendContribution);
|
|
34
|
+
bind(ConnectionHandler).toDynamicValue(ctx =>
|
|
35
|
+
new RpcConnectionHandler(measurementNotificationServicePath,
|
|
36
|
+
() => ctx.container.get(MeasurementMetricsBackendContribution)));
|
|
37
|
+
|
|
38
|
+
bind(BackendApplicationContribution).to(MetricsBackendApplicationContribution).inSingletonScope();
|
|
39
|
+
|
|
40
|
+
});
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
// *****************************************************************************
|
|
2
|
-
// Copyright (C) 2018 Ericsson and others.
|
|
3
|
-
//
|
|
4
|
-
// This program and the accompanying materials are made available under the
|
|
5
|
-
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
-
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
-
//
|
|
8
|
-
// This Source Code may also be made available under the following Secondary
|
|
9
|
-
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
-
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
-
// with the GNU Classpath Exception which is available at
|
|
12
|
-
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
-
//
|
|
14
|
-
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
-
// *****************************************************************************
|
|
16
|
-
export const MetricsContribution = Symbol('MetricsContribution');
|
|
17
|
-
export interface MetricsContribution {
|
|
18
|
-
startCollecting(): void;
|
|
19
|
-
getMetrics(): string;
|
|
20
|
-
}
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2018 Ericsson and others.
|
|
3
|
+
//
|
|
4
|
+
// This program and the accompanying materials are made available under the
|
|
5
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
//
|
|
8
|
+
// This Source Code may also be made available under the following Secondary
|
|
9
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
// with the GNU Classpath Exception which is available at
|
|
12
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
//
|
|
14
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
export const MetricsContribution = Symbol('MetricsContribution');
|
|
17
|
+
export interface MetricsContribution {
|
|
18
|
+
startCollecting(): void;
|
|
19
|
+
getMetrics(): string;
|
|
20
|
+
}
|
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
// *****************************************************************************
|
|
2
|
-
// Copyright (C) 2018 Ericsson and others.
|
|
3
|
-
//
|
|
4
|
-
// This program and the accompanying materials are made available under the
|
|
5
|
-
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
-
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
-
//
|
|
8
|
-
// This Source Code may also be made available under the following Secondary
|
|
9
|
-
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
-
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
-
// with the GNU Classpath Exception which is available at
|
|
12
|
-
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
-
//
|
|
14
|
-
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
-
// *****************************************************************************
|
|
16
|
-
|
|
17
|
-
import * as prom from 'prom-client';
|
|
18
|
-
import { injectable } from '@theia/core/shared/inversify';
|
|
19
|
-
import { MetricsContribution } from './metrics-contribution';
|
|
20
|
-
|
|
21
|
-
@injectable()
|
|
22
|
-
export class NodeMetricsContribution implements MetricsContribution {
|
|
23
|
-
getMetrics(): string {
|
|
24
|
-
return prom.register.metrics().toString();
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
startCollecting(): void {
|
|
28
|
-
const collectDefaultMetrics = prom.collectDefaultMetrics;
|
|
29
|
-
|
|
30
|
-
// Probe every 5th second.
|
|
31
|
-
collectDefaultMetrics({ timeout: 5000 });
|
|
32
|
-
}
|
|
33
|
-
}
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2018 Ericsson and others.
|
|
3
|
+
//
|
|
4
|
+
// This program and the accompanying materials are made available under the
|
|
5
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
//
|
|
8
|
+
// This Source Code may also be made available under the following Secondary
|
|
9
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
// with the GNU Classpath Exception which is available at
|
|
12
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
//
|
|
14
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
|
|
17
|
+
import * as prom from 'prom-client';
|
|
18
|
+
import { injectable } from '@theia/core/shared/inversify';
|
|
19
|
+
import { MetricsContribution } from './metrics-contribution';
|
|
20
|
+
|
|
21
|
+
@injectable()
|
|
22
|
+
export class NodeMetricsContribution implements MetricsContribution {
|
|
23
|
+
getMetrics(): string {
|
|
24
|
+
return prom.register.metrics().toString();
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
startCollecting(): void {
|
|
28
|
+
const collectDefaultMetrics = prom.collectDefaultMetrics;
|
|
29
|
+
|
|
30
|
+
// Probe every 5th second.
|
|
31
|
+
collectDefaultMetrics({ timeout: 5000 });
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -1,49 +1,49 @@
|
|
|
1
|
-
// *****************************************************************************
|
|
2
|
-
// Copyright (C) 2018 Ericsson and others.
|
|
3
|
-
//
|
|
4
|
-
// This program and the accompanying materials are made available under the
|
|
5
|
-
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
-
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
-
//
|
|
8
|
-
// This Source Code may also be made available under the following Secondary
|
|
9
|
-
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
-
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
-
// with the GNU Classpath Exception which is available at
|
|
12
|
-
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
-
//
|
|
14
|
-
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
-
// *****************************************************************************
|
|
16
|
-
|
|
17
|
-
import * as chai from 'chai';
|
|
18
|
-
import { PROMETHEUS_REGEXP, toPrometheusValidName } from './prometheus';
|
|
19
|
-
|
|
20
|
-
const expect = chai.expect;
|
|
21
|
-
|
|
22
|
-
describe('Prometheus helper module', () => {
|
|
23
|
-
/* According to https://prometheus.io/docs/concepts/data_model/ */
|
|
24
|
-
|
|
25
|
-
const validName = 'theia_extension3242-:';
|
|
26
|
-
const invalidTheiaName = '@theia/something';
|
|
27
|
-
const validTheiaName = 'theia_something';
|
|
28
|
-
const invalidName2 = '@theia/?$%^ ';
|
|
29
|
-
|
|
30
|
-
it('Should correctly validate a metric name', () => {
|
|
31
|
-
expect(PROMETHEUS_REGEXP.test(validName)).to.be.true;
|
|
32
|
-
|
|
33
|
-
expect(PROMETHEUS_REGEXP.test(invalidTheiaName)).to.be.false;
|
|
34
|
-
|
|
35
|
-
expect(PROMETHEUS_REGEXP.test(invalidName2)).to.be.false;
|
|
36
|
-
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
it('Should correctly return a valid name from an otherwise invalid prometheus string', () => {
|
|
40
|
-
expect(PROMETHEUS_REGEXP.test(invalidTheiaName)).to.be.false;
|
|
41
|
-
|
|
42
|
-
const newName = toPrometheusValidName(invalidTheiaName);
|
|
43
|
-
expect(PROMETHEUS_REGEXP.test(newName)).to.be.true;
|
|
44
|
-
expect(newName).to.be.equal(validTheiaName);
|
|
45
|
-
|
|
46
|
-
const newName2 = toPrometheusValidName(invalidName2);
|
|
47
|
-
expect(PROMETHEUS_REGEXP.test(newName2)).to.be.true;
|
|
48
|
-
});
|
|
49
|
-
});
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2018 Ericsson and others.
|
|
3
|
+
//
|
|
4
|
+
// This program and the accompanying materials are made available under the
|
|
5
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
//
|
|
8
|
+
// This Source Code may also be made available under the following Secondary
|
|
9
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
// with the GNU Classpath Exception which is available at
|
|
12
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
//
|
|
14
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
|
|
17
|
+
import * as chai from 'chai';
|
|
18
|
+
import { PROMETHEUS_REGEXP, toPrometheusValidName } from './prometheus';
|
|
19
|
+
|
|
20
|
+
const expect = chai.expect;
|
|
21
|
+
|
|
22
|
+
describe('Prometheus helper module', () => {
|
|
23
|
+
/* According to https://prometheus.io/docs/concepts/data_model/ */
|
|
24
|
+
|
|
25
|
+
const validName = 'theia_extension3242-:';
|
|
26
|
+
const invalidTheiaName = '@theia/something';
|
|
27
|
+
const validTheiaName = 'theia_something';
|
|
28
|
+
const invalidName2 = '@theia/?$%^ ';
|
|
29
|
+
|
|
30
|
+
it('Should correctly validate a metric name', () => {
|
|
31
|
+
expect(PROMETHEUS_REGEXP.test(validName)).to.be.true;
|
|
32
|
+
|
|
33
|
+
expect(PROMETHEUS_REGEXP.test(invalidTheiaName)).to.be.false;
|
|
34
|
+
|
|
35
|
+
expect(PROMETHEUS_REGEXP.test(invalidName2)).to.be.false;
|
|
36
|
+
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('Should correctly return a valid name from an otherwise invalid prometheus string', () => {
|
|
40
|
+
expect(PROMETHEUS_REGEXP.test(invalidTheiaName)).to.be.false;
|
|
41
|
+
|
|
42
|
+
const newName = toPrometheusValidName(invalidTheiaName);
|
|
43
|
+
expect(PROMETHEUS_REGEXP.test(newName)).to.be.true;
|
|
44
|
+
expect(newName).to.be.equal(validTheiaName);
|
|
45
|
+
|
|
46
|
+
const newName2 = toPrometheusValidName(invalidName2);
|
|
47
|
+
expect(PROMETHEUS_REGEXP.test(newName2)).to.be.true;
|
|
48
|
+
});
|
|
49
|
+
});
|
package/src/node/prometheus.ts
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
// *****************************************************************************
|
|
2
|
-
// Copyright (C) 2018 Ericsson and others.
|
|
3
|
-
//
|
|
4
|
-
// This program and the accompanying materials are made available under the
|
|
5
|
-
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
-
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
-
//
|
|
8
|
-
// This Source Code may also be made available under the following Secondary
|
|
9
|
-
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
-
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
-
// with the GNU Classpath Exception which is available at
|
|
12
|
-
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
-
//
|
|
14
|
-
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
-
// *****************************************************************************
|
|
16
|
-
|
|
17
|
-
export function toPrometheusValidName(name: string): string {
|
|
18
|
-
/* Make sure that start of name is valid and respect [a-zA-Z_:] */
|
|
19
|
-
const validFirstCharString = name.replace(/(^[^a-zA-Z_:]+)/gi, '');
|
|
20
|
-
/* Make sure that rest of the name respect [a-zA-Z0-9_:]* */
|
|
21
|
-
const validPrometheusName = validFirstCharString.replace(/([^a-zA-Z0-9_:])/gi, '_');
|
|
22
|
-
return validPrometheusName;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export const PROMETHEUS_REGEXP = /^[a-zA-Z_:][a-zA-Z0-9_:]*/;
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2018 Ericsson and others.
|
|
3
|
+
//
|
|
4
|
+
// This program and the accompanying materials are made available under the
|
|
5
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
//
|
|
8
|
+
// This Source Code may also be made available under the following Secondary
|
|
9
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
// with the GNU Classpath Exception which is available at
|
|
12
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
//
|
|
14
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
|
|
17
|
+
export function toPrometheusValidName(name: string): string {
|
|
18
|
+
/* Make sure that start of name is valid and respect [a-zA-Z_:] */
|
|
19
|
+
const validFirstCharString = name.replace(/(^[^a-zA-Z_:]+)/gi, '');
|
|
20
|
+
/* Make sure that rest of the name respect [a-zA-Z0-9_:]* */
|
|
21
|
+
const validPrometheusName = validFirstCharString.replace(/([^a-zA-Z0-9_:])/gi, '_');
|
|
22
|
+
return validPrometheusName;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export const PROMETHEUS_REGEXP = /^[a-zA-Z_:][a-zA-Z0-9_:]*/;
|