1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
# Copyright (C) 2020 Konsulko Group
# Author: Edi Feschiyan
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from pyagl.services.base import AGLBaseService, AFBResponse
import asyncio
import os
class TaskManagerService(AGLBaseService):
service = 'agl-service-taskmanager'
parser = AGLBaseService.getparser()
parser.add_argument('--get_process_list', action='store_true')
parser.add_argument('--get_netstat', action='store_true')
parser.add_argument('--get_load_avg', action='store_true')
def __init__(self, ip, port=None, service='agl-service-taskmanager'):
super().__init__(api='taskmanager', ip=ip, port=port, service=service)
async def get_process_list(self):
return await self.request('get_process_list')
async def get_load_avg(self):
return await self.request('get_load_avg')
async def get_netstat(self):
return await self.request('get_netstat')
async def agent_response(self):
pass
async def main(loop):
args = TaskManagerService.parser.parse_args()
tasks = await TaskManagerService(ip=args.ipaddr, port=args.port)
if args.get_process_list:
msgid = await tasks.get_process_list()
print(f'Sent status request with messageid {msgid}')
resp = await tasks.afbresponse()
print(resp.data)
if args.get_netstat:
msgid = await tasks.get_netstat()
print(f'Sent status request with messageid {msgid}')
resp = await tasks.afbresponse()
print(resp.data)
if args.get_load_avg:
msgid = await tasks.get_load_avg()
print(f'Sent status request with messageid {msgid}')
resp = await tasks.afbresponse()
print(resp.data)
if args.listener:
for response in nets.listener():
print(response)
if __name__ == '__main__':
loop = asyncio.get_event_loop()
loop.run_until_complete(main(loop))
|