Skip to content

Commit

Permalink
0.1.5
Browse files Browse the repository at this point in the history
  • Loading branch information
ovx committed Feb 11, 2024
1 parent 287786d commit f8f343d
Show file tree
Hide file tree
Showing 39 changed files with 431 additions and 334 deletions.
20 changes: 20 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"env": {
"browser": true,
"es2021": true
},
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
},
"plugins": [
"@typescript-eslint"
],
"rules": {
}
}
53 changes: 53 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: ci
on:
push:
branches: [main, next]
pull_request:
branches: ['*']

jobs:
main:
name: 'Main'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20.x
- run: npm install --frozen-lockfile
- run: NODE_OPTIONS="--no-warnings" npm test

# deno:
# name: 'Deno'
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v4
# - uses: denoland/setup-deno@v1
# with:
# deno-version: v1.x
# - run: npm run test:deno

bun:
name: 'Bun'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v1
with:
bun-version: '1.0.26'
- run: bun install
- run: bun run test

node:
name: 'Node.js v${{ matrix.node }}'
runs-on: ubuntu-latest
strategy:
matrix:
node: ['16.x', '18.x', '20.x']
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
- run: npm install --frozen-lockfile
- run: npm run test
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ package-lock.json

# app
/example/node_modules
/example/redis
/.specs
.TODO
.http
7 changes: 5 additions & 2 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{
"singleQuote": true
}
"semi": true,
"singleQuote": true,
"tabWidth": 2,
"trailingComma": "es5"
}
7 changes: 4 additions & 3 deletions dist/base.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@ export declare abstract class BaseInstrument<Value = any> extends EventEmitter {
active: boolean;
disabled: boolean;
constructor(name: InspectorInstruments, store: Store, disabled?: boolean);
bindStore(): void;
getEntryLabel(value: Value): string;
getEntryTime(value: Value): number;
serializeValue(value: Value): any;
activate(): boolean;
deactivate(): boolean;
push(value: Value, label?: string, time?: number): Promise<void>;
query(store: Store, query: Query): Promise<StoreQueryResult>;
subscribe(fn: (time: number, label: string, value: any) => void, options?: any): () => void;
query(query: Query): Promise<StoreQueryResult>;
putToStore(time: number, label: string, value: any): Promise<void>;
queryFromStore(query: Query): Promise<StoreQueryResult>;
subscribe(fn: (time: number, label: string, value: any) => void, options?: unknown): () => void;
}
export declare abstract class SensorBase extends EventEmitter {
#private;
Expand Down
23 changes: 14 additions & 9 deletions dist/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,9 @@ export class BaseInstrument extends EventEmitter {
this.name = name;
this.store = store;
this.disabled = disabled;
this.bindStore();
}
bindStore() {
this.on('push', (time, label, value) => {
this.store.setAdd(this.name, time, value, label);
});
if (!this.disabled) {
this.active = true;
}
}
getEntryLabel(value) {
return '';
Expand All @@ -37,11 +34,19 @@ export class BaseInstrument extends EventEmitter {
}
async push(value, label = this.getEntryLabel(value), time = this.getEntryTime(value)) {
if (this.active) {
this.emit('push', time, label, this.serializeValue(value));
const serialized = this.serializeValue(value);
await this.putToStore(time, label, serialized);
this.emit('push', time, label, serialized);
}
}
async query(store, query) {
return store.setQuery(this.name, query.startTime, query.endTime, query.limit);
async query(query) {
return this.queryFromStore(query);
}
async putToStore(time, label, value) {
return this.store.setAdd(this.name, time, label, value);
}
async queryFromStore(query) {
return this.store.setQuery(this.name, query.startTime, query.endTime, query.limit);
}
subscribe(fn, options) {
this.on('push', fn);
Expand Down
10 changes: 5 additions & 5 deletions dist/default-dashboards.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ declare const _default: {
'response:3xx': string;
'response:4xx': string;
'response:5xx': string;
responsetime?: undefined;
'response:latency'?: undefined;
cpu?: undefined;
'memory:heap'?: undefined;
'memory:rss'?: undefined;
Expand All @@ -49,7 +49,7 @@ declare const _default: {
} | {
colspan: number;
legend: {
responsetime: string;
'response:latency': string;
'response:1xx'?: undefined;
'response:2xx'?: undefined;
'response:3xx'?: undefined;
Expand Down Expand Up @@ -77,7 +77,7 @@ declare const _default: {
'response:3xx'?: undefined;
'response:4xx'?: undefined;
'response:5xx'?: undefined;
responsetime?: undefined;
'response:latency'?: undefined;
'memory:heap'?: undefined;
'memory:rss'?: undefined;
eventloop?: undefined;
Expand All @@ -100,7 +100,7 @@ declare const _default: {
'response:3xx'?: undefined;
'response:4xx'?: undefined;
'response:5xx'?: undefined;
responsetime?: undefined;
'response:latency'?: undefined;
cpu?: undefined;
eventloop?: undefined;
};
Expand All @@ -121,7 +121,7 @@ declare const _default: {
'response:3xx'?: undefined;
'response:4xx'?: undefined;
'response:5xx'?: undefined;
responsetime?: undefined;
'response:latency'?: undefined;
cpu?: undefined;
'memory:heap'?: undefined;
'memory:rss'?: undefined;
Expand Down
12 changes: 6 additions & 6 deletions dist/default-dashboards.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@ export default [
name: 'Monitoring',
measurements: [
{
interval: 5000,
interval: 10000,
key: 'cpu',
sensor: 'cpu',
},
{
interval: 5000,
interval: 10000,
key: 'memory:rss',
sensor: 'memory-rss',
},
{
interval: 5000,
interval: 10000,
key: 'memory:heap',
sensor: 'memory-heap',
},
{
interval: 5000,
interval: 10000,
key: 'eventloop',
sensor: 'event-loop-delay',
},
Expand Down Expand Up @@ -81,7 +81,7 @@ export default [
{
colspan: 6,
legend: {
responsetime: 'Response time',
'response:latency': 'Latency',
},
title: 'Response time',
measurements: ['response:latency.avg'],
Expand All @@ -93,7 +93,7 @@ export default [
{
colspan: 4,
legend: {
cpu: 'CPU usage',
cpu: 'CPU',
},
title: 'CPU',
measurements: ['cpu.avg'],
Expand Down
6 changes: 3 additions & 3 deletions dist/inspector.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { Session } from './session.js';
import { ErrorsInstrument } from './instruments/errors.js';
import { LogsInstrument } from './instruments/logs.js';
import { MeasurementsInstrument } from './instruments/measurements.js';
import { MetricsInstrument } from './instruments/metrics.js';
import { NetworkInstrument } from './instruments/network.js';
import { TracesInstrument } from './instruments/traces.js';
import type { Dashboard, InspectorInit, SessionInit } from './types.js';
Expand All @@ -12,7 +12,7 @@ export declare class Inspector {
instruments: {
errors: ErrorsInstrument;
logs: LogsInstrument;
measurements: MeasurementsInstrument;
metrics: MetricsInstrument;
network: NetworkInstrument;
traces: TracesInstrument;
};
Expand All @@ -38,5 +38,5 @@ export declare class Inspector {
activate(): void;
deactivate(): void;
createSessions(init?: SessionInit): Session;
getInstrument(instrument: keyof typeof this.instruments): TracesInstrument | ErrorsInstrument | LogsInstrument | MeasurementsInstrument | NetworkInstrument;
getInstrument(instrument: keyof typeof this.instruments): TracesInstrument | ErrorsInstrument | LogsInstrument | MetricsInstrument | NetworkInstrument;
}
4 changes: 2 additions & 2 deletions dist/inspector.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import proc from 'node:process';
import { Session } from './session.js';
import { ErrorsInstrument } from './instruments/errors.js';
import { LogsInstrument } from './instruments/logs.js';
import { MeasurementsInstrument } from './instruments/measurements.js';
import { MetricsInstrument } from './instruments/metrics.js';
import { NetworkInstrument } from './instruments/network.js';
import { TracesInstrument } from './instruments/traces.js';
import defaultDashboards from './default-dashboards.js';
Expand Down Expand Up @@ -41,7 +41,7 @@ export class Inspector {
this.instruments = {
errors: new ErrorsInstrument(store, instruments.errors),
logs: new LogsInstrument(store, instruments.logs),
measurements: new MeasurementsInstrument(store, instruments.measurements),
metrics: new MetricsInstrument(store, instruments.metrics),
network: new NetworkInstrument(store, instruments.network),
traces: new TracesInstrument(store, instruments.traces),
};
Expand Down
4 changes: 3 additions & 1 deletion dist/instruments/errors.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { BaseInstrument } from '../base.js';
import type { BaseInstrumentInit, ErrorsInstrumentValue } from '../types.js';
import type { BaseInstrumentInit, ErrorsInstrumentValue, Query } from '../types.js';
import type { Store } from '@exotjs/measurements/types';
export declare class ErrorsInstrument extends BaseInstrument<ErrorsInstrumentValue> {
constructor(store: Store, init?: BaseInstrumentInit);
putToStore(time: number, label: string, value: any): Promise<void>;
queryFromStore(query: Query): Promise<import("@exotjs/measurements/types").StoreQueryResult>;
getEntryLabel(value: ErrorsInstrumentValue): "client" | "server";
serializeValue(value: ErrorsInstrumentValue): string;
}
6 changes: 6 additions & 0 deletions dist/instruments/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ export class ErrorsInstrument extends BaseInstrument {
const { disabled = false } = init;
super('errors', store, disabled);
}
async putToStore(time, label, value) {
return this.store.listAdd(this.name, time, label, value);
}
async queryFromStore(query) {
return this.store.listQuery(this.name, query.startTime, query.endTime, query.limit);
}
getEntryLabel(value) {
return value.server === false ? 'client' : 'server';
}
Expand Down
4 changes: 3 additions & 1 deletion dist/instruments/logs.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { BaseInstrument } from '../base.js';
import type { Store } from '@exotjs/measurements/types';
import type { BaseInstrumentInit } from '../types.js';
import type { BaseInstrumentInit, Query } from '../types.js';
export declare class LogsInstrument extends BaseInstrument {
constructor(store: Store, init?: BaseInstrumentInit);
putToStore(time: number, label: string, value: any): Promise<void>;
queryFromStore(query: Query): Promise<import("@exotjs/measurements/types").StoreQueryResult>;
activate(): boolean;
deactivate(): boolean;
mountStdout(): void;
Expand Down
6 changes: 6 additions & 0 deletions dist/instruments/logs.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ export class LogsInstrument extends BaseInstrument {
const { disabled = false } = init;
super('logs', store, disabled);
}
async putToStore(time, label, value) {
return this.store.listAdd(this.name, time, label, value);
}
async queryFromStore(query) {
return this.store.listQuery(this.name, query.startTime, query.endTime, query.limit);
}
activate() {
this.mountStdout();
return super.activate();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { Store, StoreEntry } from '@exotjs/measurements/types';
import { BaseInstrument, SensorBase } from '../base.js';
import type { Dashboard, MeasurementsInstrumentInit, Query, TrackResponse } from '../types.js';
export declare class MeasurementsInstrument extends BaseInstrument {
import type { Dashboard, MetricsInstrumentInit, Query, TrackResponse } from '../types.js';
export declare class MetricsInstrument extends BaseInstrument {
#private;
dashboards: Dashboard[];
sensors: SensorBase[];
constructor(store: Store, init?: MeasurementsInstrumentInit);
constructor(store: Store, init?: MetricsInstrumentInit);
trackResponse(response: TrackResponse): void;
activate(): boolean;
deactivate(): boolean;
query(store: Store, query: Query & {
query(query: Query & {
keys: string[];
}): Promise<{
entries: StoreEntry[];
Expand Down

0 comments on commit f8f343d

Please sign in to comment.