-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmon.py
59 lines (43 loc) · 1.33 KB
/
mon.py
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
import signal
import sys
import _thread
# import time
from api.utilities.utilities import get_dir_path, create_dir, read_json
from fastapi import FastAPI, Response, Request
import uvicorn
# import virt_runtime.VirtMonitor
from monitor.monDaemon import VirtMonitor
_MON_PATH = get_dir_path()
mon_config = read_json("{}/config/monConfig.json".format(_MON_PATH))
PORT = mon_config['port']
HOST = mon_config['host']
ACTIVATE_LOGGER = mon_config["logger"]["active"]
LOG_PATH = mon_config["logger"]["path"]
MONITOR_POLLER_INTERVAL = mon_config["logger"]["interval"]
RLOAD = True
app = FastAPI()
vm = VirtMonitor(ACTIVATE_LOGGER, MONITOR_POLLER_INTERVAL, LOG_PATH);
@app.get("/")
async def root():
return { "message": "This is virtine monitor." }
@app.get("/numinstances")
async def num_inst():
return vm.num_instances()
@app.get("/stat")
async def stat_pid():
return vm.all_virt_stat()
@app.get("/stat/{pid}")
async def stat_pid(pid):
if not pid:
raise MissingArgumentError(pid)
return vm.stat_pid(pid)
@app.get("/ping")
async def get_pong():
return vm.get_pong()
def start_http_server(name):
uvicorn.run("mon:app", port = PORT, host = HOST, reload = RLOAD)
def start_daemon(name):
vm.start_monitor()
if __name__ == "__main__":
_thread.start_new_thread(start_daemon, ("vui-mon-daemon",) )
start_http_server("vui-mon-http-server");