2019-01-21 14:03:30 -05:00
|
|
|
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
2019-08-24 16:20:48 -04:00
|
|
|
import { assert } from "./util";
|
|
|
|
import { sendSync, msg, flatbuffers } from "./dispatch_flatbuffers";
|
2018-10-05 13:21:15 -04:00
|
|
|
|
2019-02-13 08:50:15 -05:00
|
|
|
export interface Metrics {
|
2018-10-05 13:21:15 -04:00
|
|
|
opsDispatched: number;
|
|
|
|
opsCompleted: number;
|
|
|
|
bytesSentControl: number;
|
|
|
|
bytesSentData: number;
|
|
|
|
bytesReceived: number;
|
|
|
|
}
|
|
|
|
|
2019-08-24 16:20:48 -04:00
|
|
|
function req(): [flatbuffers.Builder, msg.Any, flatbuffers.Offset] {
|
|
|
|
const builder = flatbuffers.createBuilder();
|
|
|
|
const inner = msg.Metrics.createMetrics(builder);
|
|
|
|
return [builder, msg.Any.Metrics, inner];
|
|
|
|
}
|
|
|
|
|
|
|
|
function res(baseRes: null | msg.Base): Metrics {
|
|
|
|
assert(baseRes !== null);
|
|
|
|
assert(msg.Any.MetricsRes === baseRes!.innerType());
|
|
|
|
const res = new msg.MetricsRes();
|
|
|
|
assert(baseRes!.inner(res) !== null);
|
|
|
|
|
|
|
|
return {
|
|
|
|
opsDispatched: res.opsDispatched().toFloat64(),
|
|
|
|
opsCompleted: res.opsCompleted().toFloat64(),
|
|
|
|
bytesSentControl: res.bytesSentControl().toFloat64(),
|
|
|
|
bytesSentData: res.bytesSentData().toFloat64(),
|
|
|
|
bytesReceived: res.bytesReceived().toFloat64()
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-03-20 12:39:47 -04:00
|
|
|
/** Receive metrics from the privileged side of Deno.
|
|
|
|
*
|
2019-04-03 08:53:54 -04:00
|
|
|
* > console.table(Deno.metrics())
|
|
|
|
* ┌──────────────────┬────────┐
|
|
|
|
* │ (index) │ Values │
|
|
|
|
* ├──────────────────┼────────┤
|
|
|
|
* │ opsDispatched │ 9 │
|
|
|
|
* │ opsCompleted │ 9 │
|
|
|
|
* │ bytesSentControl │ 504 │
|
|
|
|
* │ bytesSentData │ 0 │
|
|
|
|
* │ bytesReceived │ 856 │
|
|
|
|
* └──────────────────┴────────┘
|
2019-03-20 12:39:47 -04:00
|
|
|
*/
|
2019-03-09 12:30:38 -05:00
|
|
|
export function metrics(): Metrics {
|
2019-08-24 16:20:48 -04:00
|
|
|
return res(sendSync(...req()));
|
2019-03-09 12:30:38 -05:00
|
|
|
}
|