2019-01-21 14:03:30 -05:00
|
|
|
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
2018-10-05 13:21:15 -04:00
|
|
|
import * as msg from "gen/msg_generated";
|
2018-10-17 13:04:28 -04:00
|
|
|
import * as flatbuffers from "./flatbuffers";
|
2018-10-05 13:21:15 -04:00
|
|
|
import { assert } from "./util";
|
|
|
|
import * as dispatch from "./dispatch";
|
|
|
|
|
|
|
|
interface Metrics {
|
|
|
|
opsDispatched: number;
|
|
|
|
opsCompleted: number;
|
|
|
|
bytesSentControl: number;
|
|
|
|
bytesSentData: number;
|
|
|
|
bytesReceived: number;
|
|
|
|
}
|
|
|
|
|
2018-10-14 16:29:50 -04:00
|
|
|
/** Receive metrics from the privileged side of Deno. */
|
2018-10-05 13:21:15 -04:00
|
|
|
export function metrics(): Metrics {
|
|
|
|
return res(dispatch.sendSync(...req()));
|
|
|
|
}
|
|
|
|
|
|
|
|
function req(): [flatbuffers.Builder, msg.Any, flatbuffers.Offset] {
|
2018-10-17 13:04:28 -04:00
|
|
|
const builder = flatbuffers.createBuilder();
|
2018-10-05 13:21:15 -04:00
|
|
|
msg.Metrics.startMetrics(builder);
|
|
|
|
const inner = msg.Metrics.endMetrics(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()
|
|
|
|
};
|
|
|
|
}
|