README.md 2.7 KB
Newer Older
류은제's avatar
류은제 committed
1
2
3
4
# bai-monitoring-api



류은제's avatar
류은제 committed
5
## 1. Install requirements.txt
류은제's avatar
류은제 committed
6

류은제's avatar
류은제 committed
7
Install "requirements.txt" on your enviroment before running these codes.
류은제's avatar
류은제 committed
8
9


류은제's avatar
류은제 committed
10
## 2. Config config.py
류은제's avatar
류은제 committed
11

류은제's avatar
류은제 committed
12
"config.py" is for "app.py".
류은제's avatar
류은제 committed
13

류은제's avatar
류은제 committed
14
15
Configure the factors like ADMIN_ACCESS_KEY, ADMIN_SECRET_KEY,,,etc
You can find them in [ Backend.ai Control Pannel ].
류은제's avatar
류은제 committed
16
17


류은제's avatar
류은제 committed
18
## 3. Explanations of app.py
류은제's avatar
류은제 committed
19

류은제's avatar
류은제 committed
20
This is a api app which returns Backend.ai agent's current utilizations through json format.
류은제's avatar
류은제 committed
21
22


류은제's avatar
류은제 committed
23
Graphql api is used for fetching data from [ Backend.ai manager hub server ]. 
류은제's avatar
류은제 committed
24

류은제's avatar
류은제 committed
25
26
27
28
"generate_signature()" function generates all the signature needed for the connections with Backend.ai manager hub server.
"query_agent_list()" function queries some fields like {'id','occupied_slots','available_slots','live_stat'} from Agent Class.
"extract_utilization()" function makes json results we want
"myfunction_api()" function includes the Flask framework. Flask could make this code to an api application.
류은제's avatar
류은제 committed
29
30


류은제's avatar
류은제 committed
31
32
33
- host= ‘0.0.0.0’  => This settings make possible to access api from outside.
- port=‘31000’ => Port number accords to kubernetes's general port range. Except the numbers you already using.
- debug=True
류은제's avatar
류은제 committed
34
35


류은제's avatar
류은제 committed
36
## 4. Run api server
류은제's avatar
류은제 committed
37
38


류은제's avatar
류은제 committed
39
[ python3 agent_list_api_flask.py ]
류은제's avatar
류은제 committed
40
41


류은제's avatar
류은제 committed
42
It is running as a debug mode, so that you could see the logs in the console whenever api server gets requests.
류은제's avatar
류은제 committed
43

류은제's avatar
류은제 committed
44
![8ACCFB37-5919-4695-B853-2D9AA1A94802.jpeg](https://s3-us-west-2.amazonaws.com/secure.notion-static.com/0b46333b-aad0-4ba7-a886-4cffa5f0c2b3/8ACCFB37-5919-4695-B853-2D9AA1A94802.jpeg)
류은제's avatar
류은제 committed
45
46
47



류은제's avatar
류은제 committed
48
## 5. api url : [http://10.231.238.231:31000/api/getMonitoring]
류은제's avatar
류은제 committed
49

류은제's avatar
류은제 committed
50
response example
류은제's avatar
류은제 committed
51

류은제's avatar
류은제 committed
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
{
  "results": {
    "item1": {
      "cpu": 3.94,
      "cuda": 99.12,
      "disk": "25.02",
      "id": "i-ai-1",
      "mem": "4.85"
    },
    "item2": {
      "cpu": 4.69,
      "cuda": 14.12,
      "disk": "8.44",
      "id": "i-ai-2",
      "mem": "5.29"
    },
    "item3": {
      "cpu": 2.08,
      "cuda": 12.5,
      "disk": "8.28",
      "id": "i-ai-3",
      "mem": "3.63"
    },
    "item4": {
      "cpu": 4.25,
      "cuda": 16.5,
      "disk": "8.35",
      "id": "i-ai-4",
      "mem": "5.49"
    },
    "item5": {
      "cpu": 0.84,
      "cuda": 24.38,
      "disk": "41.31",
      "id": "i-ai-5",
      "mem": "3.48"
    },
    "item6": {
      "cpu": 2.14,
      "cuda": 0.0,
      "disk": "79.48",
      "id": "i-ai-6",
      "mem": "3.55"
    },
    "time": "2023-03-14T11:20:44.488009+09:00"
  }
}
류은제's avatar
류은제 committed
99
100


류은제's avatar
류은제 committed
101
## 6. Further usage (running on k8s)
류은제's avatar
류은제 committed
102

류은제's avatar
류은제 committed
103
- This git repo is used for the Dockerfile.
류은제's avatar
류은제 committed
104

류은제's avatar
류은제 committed
105
106
107
108
109
110
111
- Build a custom docker image by using Dockerfile.

- The custom docker image is for making kubernetes pods.

- Deploy the pods and service in k8s Cluster.

- Finally api server is running on k8s pods. You access api url with [ http://<host ip>:<service nodePort> ]
류은제's avatar
류은제 committed
112