mirror of
https://github.com/octoleo/syncthing.git
synced 2025-01-15 19:57:23 +00:00
add system status service and mock data
This commit is contained in:
parent
9fe0c30299
commit
b7f3425f36
59
src/app/mocks/mock-system-status.ts
Normal file
59
src/app/mocks/mock-system-status.ts
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
export const systemStatus = {
|
||||||
|
"alloc": 30618136,
|
||||||
|
"connectionServiceStatus": {
|
||||||
|
"dynamic+https://relays.syncthing.net/endpoint": {
|
||||||
|
"error": null,
|
||||||
|
"lanAddresses": [
|
||||||
|
"relay://23.92.71.120:443/?id=53STGR7-YBM6FCX-PAZ2RHM-YPY6OEJ-WYHVZO7-PCKQRCK-PZLTP7T-434XCAD&pingInterval=1m0s&networkTimeout=2m0s&sessionLimitBps=0&globalLimitBps=0&statusAddr=:22070&providedBy=canton7"
|
||||||
|
],
|
||||||
|
"wanAddresses": [
|
||||||
|
"relay://23.92.71.120:443/?id=53STGR7-YBM6FCX-PAZ2RHM-YPY6OEJ-WYHVZO7-PCKQRCK-PZLTP7T-434XCAD&pingInterval=1m0s&networkTimeout=2m0s&sessionLimitBps=0&globalLimitBps=0&statusAddr=:22070&providedBy=canton7"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"tcp://0.0.0.0:22000": {
|
||||||
|
"error": null,
|
||||||
|
"lanAddresses": [
|
||||||
|
"tcp://0.0.0.0:22000"
|
||||||
|
],
|
||||||
|
"wanAddresses": [
|
||||||
|
"tcp://0.0.0.0:22000"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"cpuPercent": 0,
|
||||||
|
"discoveryEnabled": true,
|
||||||
|
"discoveryErrors": {
|
||||||
|
"global@https://discovery-v4-1.syncthing.net/v2/": "500 Internal Server Error",
|
||||||
|
"global@https://discovery-v4-2.syncthing.net/v2/": "Post https://discovery-v4-2.syncthing.net/v2/: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)",
|
||||||
|
"global@https://discovery-v4-3.syncthing.net/v2/": "Post https://discovery-v4-3.syncthing.net/v2/: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)",
|
||||||
|
"global@https://discovery-v6-1.syncthing.net/v2/": "Post https://discovery-v6-1.syncthing.net/v2/: dial tcp [2001:470:28:4d6::5]:443: connect: no route to host",
|
||||||
|
"global@https://discovery-v6-2.syncthing.net/v2/": "Post https://discovery-v6-2.syncthing.net/v2/: dial tcp [2604:a880:800:10::182:a001]:443: connect: no route to host",
|
||||||
|
"global@https://discovery-v6-3.syncthing.net/v2/": "Post https://discovery-v6-3.syncthing.net/v2/: dial tcp [2400:6180:0:d0::d9:d001]:443: connect: no route to host"
|
||||||
|
},
|
||||||
|
"discoveryMethods": 8,
|
||||||
|
"goroutines": 49,
|
||||||
|
"lastDialStatus": {
|
||||||
|
"tcp://10.20.30.40": {
|
||||||
|
"when": "2019-05-16T07:41:23Z",
|
||||||
|
"error": "dial tcp 10.20.30.40:22000: i/o timeout"
|
||||||
|
},
|
||||||
|
"tcp://172.16.33.3:22000": {
|
||||||
|
"when": "2019-05-16T07:40:43Z",
|
||||||
|
"ok": true
|
||||||
|
},
|
||||||
|
"tcp://83.233.120.221:22000": {
|
||||||
|
"when": "2019-05-16T07:41:13Z",
|
||||||
|
"error": "dial tcp 83.233.120.221:22000: connect: connection refused"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"myID": "YZJBJFX-RDBL7WY-6ZGKJ2D-4MJB4E7-ZATSDUY-LD6Y3L3-MLFUYWE-AEMXJAC",
|
||||||
|
"pathSeparator": "/",
|
||||||
|
"startTime": "2016-06-06T19:41:43.039284753+02:00",
|
||||||
|
"sys": 42092792,
|
||||||
|
"themes": [
|
||||||
|
"default",
|
||||||
|
"dark"
|
||||||
|
],
|
||||||
|
"tilde": "/Users/jb",
|
||||||
|
"uptime": 2635
|
||||||
|
}
|
@ -5,6 +5,7 @@ import { SystemConfigService } from './system-config.service';
|
|||||||
import { SystemConnectionsService } from './system-connections.service';
|
import { SystemConnectionsService } from './system-connections.service';
|
||||||
import { DbCompletionService } from './db-completion.service';
|
import { DbCompletionService } from './db-completion.service';
|
||||||
import { SystemConnections } from '../connections';
|
import { SystemConnections } from '../connections';
|
||||||
|
import { SystemStatusService } from './system-status.service';
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root'
|
||||||
@ -12,11 +13,13 @@ import { SystemConnections } from '../connections';
|
|||||||
export class DeviceService {
|
export class DeviceService {
|
||||||
private devices: Device[];
|
private devices: Device[];
|
||||||
private sysConns: SystemConnections;
|
private sysConns: SystemConnections;
|
||||||
|
thisDevice: Device;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private systemConfigService: SystemConfigService,
|
private systemConfigService: SystemConfigService,
|
||||||
private systemConnectionsService: SystemConnectionsService,
|
private systemConnectionsService: SystemConnectionsService,
|
||||||
private dbCompletionService: DbCompletionService
|
private dbCompletionService: DbCompletionService,
|
||||||
|
private systemStatusService: SystemStatusService
|
||||||
) { }
|
) { }
|
||||||
|
|
||||||
getDeviceStatusInOrder(observer: Subscriber<Device>, startIndex: number) {
|
getDeviceStatusInOrder(observer: Subscriber<Device>, startIndex: number) {
|
||||||
@ -56,29 +59,42 @@ export class DeviceService {
|
|||||||
devices => {
|
devices => {
|
||||||
this.devices = devices;
|
this.devices = devices;
|
||||||
|
|
||||||
// Check folder devices to see if the device is used
|
// First check to see which device is local 'thisDevice'
|
||||||
this.systemConfigService.getFolders().subscribe(
|
this.systemStatusService.getSystemStatus().subscribe(
|
||||||
folders => {
|
status => {
|
||||||
// Loop through all folder devices to see if the device is used
|
|
||||||
this.devices.forEach(device => {
|
this.devices.forEach(device => {
|
||||||
folders.forEach(folder => {
|
if (device.deviceID === status.myID) {
|
||||||
folder.devices.forEach(fdevice => {
|
console.log("found thisDevice!", device);
|
||||||
if (device.deviceID === fdevice.deviceID) {
|
this.thisDevice = device;
|
||||||
device.used = true;
|
}
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// See if the connection is connected or undefined
|
// TODO Determine if it should ignore thisDevice
|
||||||
this.systemConnectionsService.getSystemConnections().subscribe(
|
|
||||||
c => {
|
|
||||||
this.sysConns = c;
|
|
||||||
|
|
||||||
// Synchronously get the status of each device
|
// Check folder devices to see if the device is used
|
||||||
this.getDeviceStatusInOrder(observer, 0);
|
this.systemConfigService.getFolders().subscribe(
|
||||||
}
|
folders => {
|
||||||
);
|
// Loop through all folder devices to see if the device is used
|
||||||
|
this.devices.forEach(device => {
|
||||||
|
folders.forEach(folder => {
|
||||||
|
folder.devices.forEach(fdevice => {
|
||||||
|
if (device.deviceID === fdevice.deviceID) {
|
||||||
|
device.used = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// See if the connection is connected or undefined
|
||||||
|
this.systemConnectionsService.getSystemConnections().subscribe(
|
||||||
|
c => {
|
||||||
|
this.sysConns = c;
|
||||||
|
|
||||||
|
// Synchronously get the status of each device
|
||||||
|
this.getDeviceStatusInOrder(observer, 0);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
|
@ -1,15 +1,16 @@
|
|||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { config } from '../mocks/mock-system-config'
|
import { config } from '../mocks/mock-system-config';
|
||||||
import { dbStatus } from '../mocks/mock-db-status'
|
import { dbStatus } from '../mocks/mock-db-status';
|
||||||
import { connections } from '../mocks/mock-system-connections'
|
import { connections } from '../mocks/mock-system-connections';
|
||||||
import { dbCompletion } from '../mocks/mock-db-completion'
|
import { dbCompletion } from '../mocks/mock-db-completion';
|
||||||
|
import { systemStatus } from '../mocks/mock-system-status';
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root'
|
||||||
})
|
})
|
||||||
export class InMemoryConfigDataService {
|
export class InMemoryConfigDataService {
|
||||||
createDb() {
|
createDb() {
|
||||||
return { config, dbStatus, connections, dbCompletion };
|
return { config, dbStatus, connections, dbCompletion, systemStatus };
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor() { }
|
constructor() { }
|
||||||
|
16
src/app/services/system-status.service.spec.ts
Normal file
16
src/app/services/system-status.service.spec.ts
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
import { TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
|
import { SystemStatusService } from './system-status.service';
|
||||||
|
|
||||||
|
describe('SystemStatusService', () => {
|
||||||
|
let service: SystemStatusService;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
TestBed.configureTestingModule({});
|
||||||
|
service = TestBed.inject(SystemStatusService);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should be created', () => {
|
||||||
|
expect(service).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
28
src/app/services/system-status.service.ts
Normal file
28
src/app/services/system-status.service.ts
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
import { Injectable } from '@angular/core';
|
||||||
|
import { environment } from 'src/environments/environment';
|
||||||
|
import { apiURL, apiRetry } from '../api-utils';
|
||||||
|
import { Observable } from 'rxjs';
|
||||||
|
import { HttpClient } from '@angular/common/http';
|
||||||
|
import { retry, map } from 'rxjs/operators';
|
||||||
|
import { SystemStatus } from '../system-status';
|
||||||
|
|
||||||
|
@Injectable({
|
||||||
|
providedIn: 'root'
|
||||||
|
})
|
||||||
|
export class SystemStatusService {
|
||||||
|
|
||||||
|
private systemStatusUrl = environment.production ? apiURL + 'rest/system/status' : 'api/systemStatus';
|
||||||
|
|
||||||
|
constructor(private http: HttpClient) { }
|
||||||
|
|
||||||
|
getSystemStatus(): Observable<SystemStatus> {
|
||||||
|
return this.http
|
||||||
|
.get<SystemStatus>(this.systemStatusUrl)
|
||||||
|
.pipe(
|
||||||
|
retry(apiRetry),
|
||||||
|
map(res => {
|
||||||
|
return res;
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
17
src/app/system-status.ts
Normal file
17
src/app/system-status.ts
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
export interface SystemStatus {
|
||||||
|
alloc: number;
|
||||||
|
connectionServiceStatus: any;
|
||||||
|
cpuPercent: number; // allows returns 0
|
||||||
|
discoveryEnabled: boolean;
|
||||||
|
discoveryErrors: any;
|
||||||
|
discoveryMethods: number;
|
||||||
|
goroutines: number;
|
||||||
|
lastDialStatus: any;
|
||||||
|
myID: string;
|
||||||
|
pathSeparator: string;
|
||||||
|
startTime: string;
|
||||||
|
sys: number;
|
||||||
|
themes: string[];
|
||||||
|
tilde: string;
|
||||||
|
uptime: number;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user