mirror of
https://github.com/OutlineFoundation/outline-server.git
synced 2026-08-28 12:21:11 +00:00
time_window
This commit is contained in:
parent
9b398a9a57
commit
a0fc6bde60
3 changed files with 10 additions and 4 deletions
|
|
@ -35,7 +35,7 @@ describe('PrometheusManagerMetrics', () => {
|
|||
const managerMetrics = new PrometheusManagerMetrics(
|
||||
new FakeTunnelTimePrometheusClient({US: 1000, CA: 2000})
|
||||
);
|
||||
const tunnelTime = await managerMetrics.getTunnelTimeByLocation({seconds: 0});
|
||||
const tunnelTime = await managerMetrics.getTunnelTimeByLocation({time_window: {seconds: 0}});
|
||||
expect(tunnelTime).toEqual([
|
||||
{location: 'US', asn: undefined, as_org: undefined, tunnel_time: {seconds: 1000}},
|
||||
{location: 'CA', asn: undefined, as_org: undefined, tunnel_time: {seconds: 2000}},
|
||||
|
|
|
|||
|
|
@ -18,7 +18,9 @@ import {DataUsageByUser, DataUsageTimeframe} from '../model/metrics';
|
|||
export type TunnelTimeDimension = 'access_key' | 'country' | 'asn';
|
||||
|
||||
interface TunnelTimeRequest {
|
||||
seconds: number;
|
||||
time_window: {
|
||||
seconds: number;
|
||||
};
|
||||
}
|
||||
|
||||
interface TunnelTimeResponse {
|
||||
|
|
@ -57,7 +59,9 @@ export class PrometheusManagerMetrics implements ManagerMetrics {
|
|||
return {bytesTransferredByUserId: usage};
|
||||
}
|
||||
|
||||
async getTunnelTimeByLocation({seconds}: TunnelTimeRequest): Promise<TunnelTimeResponse[]> {
|
||||
async getTunnelTimeByLocation({
|
||||
time_window: {seconds},
|
||||
}: TunnelTimeRequest): Promise<TunnelTimeResponse[]> {
|
||||
const {result} = await this.prometheusClient.query(
|
||||
`sum(increase(shadowsocks_tunnel_time_seconds_per_location[${seconds}s])) by (location, asn, asorg)`
|
||||
);
|
||||
|
|
|
|||
|
|
@ -605,7 +605,9 @@ export class ShadowsocksManagerService {
|
|||
try {
|
||||
logging.debug(`getTunnelTime request ${JSON.stringify(req.params)}`);
|
||||
const response = await this.managerMetrics.getTunnelTimeByLocation({
|
||||
seconds: 30 * 24 * 60 * 60,
|
||||
time_window: {
|
||||
seconds: 30 * 24 * 60 * 60,
|
||||
},
|
||||
});
|
||||
res.send(HttpSuccess.OK, response);
|
||||
logging.debug(`getTunnelTime response ${JSON.stringify(response)}`);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue