Skip to content
1 change: 1 addition & 0 deletions src/shadowbox/Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ tasks:
SB_PUBLIC_IP: localhost
SB_CERTIFICATE_FILE: '{{joinPath .RUN_DIR "/shadowbox-selfsigned-dev.crt"}}'
SB_PRIVATE_KEY_FILE: '{{joinPath .RUN_DIR "/shadowbox-selfsigned-dev.key"}}'
LOG_LEVEL: '{{.LOG_LEVEL}}'
cmds:
- echo Target platform is {{.TARGET_OS}}/{{.TARGET_ARCH}}
- echo "Using directory {{.RUN_DIR}}"
Expand Down
186 changes: 45 additions & 141 deletions src/shadowbox/server/manager_metrics.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,7 @@ describe('PrometheusManagerMetrics', () => {
const managerMetrics = new PrometheusManagerMetrics(
new QueryMapPrometheusClient(
{
'sum(rate(shadowsocks_data_bytes_per_location{dir=~"c<p|p>t"}[300s]))': {
resultType: 'vector',
result: [
{
metric: {
location: 'US',
asn: '49490',
asorg: 'Test AS Org',
},
value: [1739284734, '1234'],
},
],
},
'sum(increase(shadowsocks_data_bytes_per_location{dir=~"c<p|p>t"}[0s])) by (location, asn, asorg)':
'sum(increase(shadowsocks_tunnel_time_seconds_per_location[0s])) by (location, asn, asorg)':
{
resultType: 'vector',
result: [
Expand All @@ -68,60 +55,25 @@ describe('PrometheusManagerMetrics', () => {
},
],
},
'sum(increase(shadowsocks_tunnel_time_seconds_per_location[0s])) by (location, asn, asorg)':
},
{
'sum(increase(shadowsocks_data_bytes_per_location{dir=~"c<p|p>t"}[300s])) by (location, asn, asorg)':
{
resultType: 'vector',
resultType: 'matrix',
result: [
{
metric: {
location: 'US',
asn: '49490',
asorg: 'Test AS Org',
},
value: [1738959398, '1000'],
values: [
[1738959398, '9000'],
[1739284734, '3000'],
],
},
],
},
'sum(increase(shadowsocks_data_bytes{dir=~"c<p|p>t"}[0s])) by (access_key)': {
resultType: 'vector',
result: [
{
metric: {
access_key: '0',
},
value: [1738959398, '1000'],
},
],
},
'sum(increase(shadowsocks_tunnel_time_seconds[0s])) by (access_key)': {
resultType: 'vector',
result: [
{
metric: {
access_key: '0',
},
value: [1738959398, '1000'],
},
],
},
},
{
'sum(rate(shadowsocks_data_bytes_per_location{dir=~"c<p|p>t"}[300s]))': {
resultType: 'matrix',
result: [
{
metric: {
location: 'US',
asn: '49490',
asorg: 'Test AS Org',
},
values: [
[1738959398, '5678'],
[1739284734, '1234'],
],
},
],
},
'sum(increase(shadowsocks_data_bytes{dir=~"c<p|p>t"}[300s])) by (access_key)': {
resultType: 'matrix',
result: [
Expand All @@ -130,8 +82,8 @@ describe('PrometheusManagerMetrics', () => {
access_key: '0',
},
values: [
[1738959398, '1000'],
[1739284734, '2000'],
[1738959398, '9000'],
[1739284734, '3000'],
],
},
],
Expand All @@ -145,7 +97,7 @@ describe('PrometheusManagerMetrics', () => {
},
values: [
[1738959398, '1000'],
[1739284734, '0'],
[1738959398, '0'],
],
},
],
Expand All @@ -162,18 +114,18 @@ describe('PrometheusManagerMetrics', () => {
"seconds": 1000
},
"dataTransferred": {
"bytes": 1000
"bytes": 12000
},
"bandwidth": {
"current": {
"data": {
"bytes": 1234
"bytes": 10
},
"timestamp": 1739284734
},
"peak": {
"data": {
"bytes": 5678
"bytes": 30
},
"timestamp": 1738959398
}
Expand All @@ -184,7 +136,7 @@ describe('PrometheusManagerMetrics', () => {
"asn": 49490,
"asOrg": "Test AS Org",
"dataTransferred": {
"bytes": 1000
"bytes": 12000
},
"tunnelTime": {
"seconds": 1000
Expand All @@ -196,7 +148,7 @@ describe('PrometheusManagerMetrics', () => {
{
"accessKeyId": 0,
"dataTransferred": {
"bytes": 1000
"bytes": 12000
},
"tunnelTime": {
"seconds": 1000
Expand All @@ -214,24 +166,11 @@ describe('PrometheusManagerMetrics', () => {
done();
});

it('getServerMetrics - does a full outer join on metric data', async (done) => {
it('getServerMetrics - combines sources', async (done) => {
const managerMetrics = new PrometheusManagerMetrics(
new QueryMapPrometheusClient(
{
'sum(rate(shadowsocks_data_bytes_per_location{dir=~"c<p|p>t"}[300s]))': {
resultType: 'vector',
result: [
{
metric: {
location: 'US',
asn: '49490',
asorg: 'Test AS Org',
},
value: [1739284734, '1234'],
},
],
},
'sum(increase(shadowsocks_data_bytes_per_location{dir=~"c<p|p>t"}[0s])) by (location, asn, asorg)':
'sum(increase(shadowsocks_tunnel_time_seconds_per_location[0s])) by (location, asn, asorg)':
{
resultType: 'vector',
result: [
Expand All @@ -245,58 +184,23 @@ describe('PrometheusManagerMetrics', () => {
},
],
},
'sum(increase(shadowsocks_tunnel_time_seconds_per_location[0s])) by (location, asn, asorg)':
},
{
'sum(increase(shadowsocks_data_bytes_per_location{dir=~"c<p|p>t"}[300s])) by (location, asn, asorg)':
{
resultType: 'vector',
resultType: 'matrix',
result: [
{
metric: {
location: 'CA',
},
value: [1738959398, '1000'],
values: [
[1738959398, '9000'],
[1739284734, '3000'],
],
},
],
},
'sum(increase(shadowsocks_data_bytes{dir=~"c<p|p>t"}[0s])) by (access_key)': {
resultType: 'vector',
result: [
{
metric: {
access_key: '0',
},
value: [1738959398, '1000'],
},
],
},
'sum(increase(shadowsocks_tunnel_time_seconds[0s])) by (access_key)': {
resultType: 'vector',
result: [
{
metric: {
access_key: '1',
},
value: [1738959398, '1000'],
},
],
},
},
{
'sum(rate(shadowsocks_data_bytes_per_location{dir=~"c<p|p>t"}[300s]))': {
resultType: 'matrix',
result: [
{
metric: {
location: 'US',
asn: '49490',
asorg: 'Test AS Org',
},
values: [
[1738959398, '5678'],
[1739284734, '1234'],
],
},
],
},
'sum(increase(shadowsocks_data_bytes{dir=~"c<p|p>t"}[300s])) by (access_key)': {
resultType: 'matrix',
result: [
Expand All @@ -305,8 +209,8 @@ describe('PrometheusManagerMetrics', () => {
access_key: '0',
},
values: [
[1738959398, '1000'],
[1738959398, '2000'],
[1738959398, '9000'],
[1739284734, '3000'],
],
},
],
Expand All @@ -316,7 +220,7 @@ describe('PrometheusManagerMetrics', () => {
result: [
{
metric: {
access_key: '0',
access_key: '1',
},
values: [
[1738959398, '1000'],
Expand All @@ -337,18 +241,18 @@ describe('PrometheusManagerMetrics', () => {
"seconds": 1000
},
"dataTransferred": {
"bytes": 1000
"bytes": 12000
},
"bandwidth": {
"current": {
"data": {
"bytes": 1234
"bytes": 10
},
"timestamp": 1739284734
},
"peak": {
"data": {
"bytes": 5678
"bytes": 30
},
"timestamp": 1738959398
}
Expand All @@ -359,52 +263,52 @@ describe('PrometheusManagerMetrics', () => {
"asn": null,
"asOrg": null,
"dataTransferred": {
"bytes": 0
"bytes": 12000
},
"tunnelTime": {
"seconds": 1000
"seconds": 0
}
},
{
"location": "US",
"asn": 49490,
"asOrg": "Test AS Org",
"dataTransferred": {
"bytes": 1000
"bytes": 0
},
"tunnelTime": {
"seconds": 0
"seconds": 1000
}
}
]
},
"accessKeys": [
{
"accessKeyId": 1,
"accessKeyId": 0,
"dataTransferred": {
"bytes": 0
"bytes": 12000
},
"tunnelTime": {
"seconds": 1000
"seconds": 0
},
"connection": {
"lastTrafficSeen": null,
"lastTrafficSeen": 1739284734,
"peakDeviceCount": {
"data": 0,
"timestamp": null
}
}
},
{
"accessKeyId": 0,
"accessKeyId": 1,
"dataTransferred": {
"bytes": 1000
"bytes": 0
},
"tunnelTime": {
"seconds": 0
"seconds": 1000
},
"connection": {
"lastTrafficSeen": 1738959398,
"lastTrafficSeen": null,
"peakDeviceCount": {
"data": 4,
"timestamp": 1738959398
Expand Down
Loading
Loading