Add LowCollector & rename Supervisor to Monitoring
[src/xds/xds-agent.git] / webapp / src / app / @core-xds / services / monitoring.service.ts
1 /**
2 * @license
3 * Copyright (C) 2018-2019 "IoT.bzh"
4 * Author Sebastien Douheret <sebastien@iot.bzh>
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 *   http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19 import { Injectable } from '@angular/core';
20 import { Observable } from 'rxjs/Observable';
21
22 import { XDSAgentService } from './xdsagent.service';
23 import { map } from 'rxjs/operators';
24
25 export interface AglTopology {
26   name: string;
27   pid: number;
28   disabled: boolean;
29   isClient: boolean;
30   isServer: boolean;
31   ws_clients: string[];
32   ws_servers: string[];
33   apis: any;
34 }
35
36 export interface AglLowCollectorConfig {
37   time?: number;
38 }
39
40 @Injectable()
41 export class MonitoringService {
42
43   constructor(private xdsSvr: XDSAgentService) {
44     /*
45     this.xdsSvr.XdsConfig$.subscribe(cfg => {
46       if (!cfg || cfg.servers.length < 1) {
47         return;
48       }
49     });
50     */
51   }
52
53   getTopo(): Observable<AglTopology[]> {
54     return this.xdsSvr.getTopoMonitoring().pipe(
55       map((tp: AglTopology[]) => {
56         // FIXME - move filter on backend side
57         const ignored: string[] = [
58           'agl-low-collector',
59           'harvester',
60         ];
61
62         tp.forEach(el => {
63           el.disabled = false;
64           ignored.forEach(iel => {
65             if (el.name.indexOf(iel) !== -1) {
66               el.disabled = true;
67             }
68           });
69
70           // replace unix:/run/xxx/ws by nothing
71           const wsc: string[] = [];
72           el.ws_clients.forEach(s => {
73             s = s.replace('unix:/run/platform/apis/ws/', '');
74             s = s.replace('unix:/run/user/1001/apis/ws/', '');
75             s = s.replace('unix:/run/user/0/apis/ws/', '');
76             wsc.push(s);
77           });
78           el.ws_clients = wsc;
79           // replace sd: by nothing
80           const wss: string[] = [];
81           el.ws_servers.forEach(s => {
82             wss.push(s.replace('sd:', ''));
83           });
84           el.ws_servers = wss;
85         });
86         return tp;
87       })
88     );
89   }
90
91   startTrace(cfg: any): Observable<any> {
92     return this.xdsSvr.startTraceMonitoring(cfg);
93   }
94
95   stopTrace(cfg: any): Observable<any> {
96     return this.xdsSvr.stopTraceMonitoring(cfg);
97   }
98
99   startLowCollector(cfg: AglLowCollectorConfig): Observable<any> {
100     return this.xdsSvr.startLowCollector(cfg);
101   }
102
103   stopLowCollector(): Observable<any> {
104     return this.xdsSvr.stopLowCollector();
105   }
106 }