jaseci 1.4.2.6__py3-none-any.whl → 2.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of jaseci might be problematic. Click here for more details.
- jaseci/__init__.py +3 -37
- jaseci-2.0.0.dist-info/METADATA +65 -0
- jaseci-2.0.0.dist-info/RECORD +4 -0
- {jaseci-1.4.2.6.dist-info → jaseci-2.0.0.dist-info}/WHEEL +1 -2
- jaseci/VERSION +0 -1
- jaseci/cli_tools/__init__.py +0 -0
- jaseci/cli_tools/book_tools.py +0 -457
- jaseci/cli_tools/jsctl.py +0 -500
- jaseci/cli_tools/tests/__init__.py +0 -0
- jaseci/cli_tools/tests/test_jsctl.py +0 -556
- jaseci/extens/__init__.py +0 -0
- jaseci/extens/act_lib/__init__.py +0 -0
- jaseci/extens/act_lib/date.py +0 -118
- jaseci/extens/act_lib/elastic.py +0 -87
- jaseci/extens/act_lib/file.py +0 -77
- jaseci/extens/act_lib/file_handler.py +0 -190
- jaseci/extens/act_lib/internal.py +0 -19
- jaseci/extens/act_lib/jaseci.py +0 -62
- jaseci/extens/act_lib/mail.py +0 -10
- jaseci/extens/act_lib/maths.py +0 -168
- jaseci/extens/act_lib/net.py +0 -192
- jaseci/extens/act_lib/rand.py +0 -83
- jaseci/extens/act_lib/regex.py +0 -85
- jaseci/extens/act_lib/request.py +0 -170
- jaseci/extens/act_lib/std.py +0 -236
- jaseci/extens/act_lib/storage.py +0 -53
- jaseci/extens/act_lib/stripe.py +0 -338
- jaseci/extens/act_lib/task.py +0 -14
- jaseci/extens/act_lib/tests/__init__.py +0 -0
- jaseci/extens/act_lib/tests/std_test_code.py +0 -37
- jaseci/extens/act_lib/tests/test_date.py +0 -26
- jaseci/extens/act_lib/tests/test_elastic.py +0 -159
- jaseci/extens/act_lib/tests/test_file.py +0 -116
- jaseci/extens/act_lib/tests/test_file_lib.py +0 -40
- jaseci/extens/act_lib/tests/test_mail_lib.py +0 -33
- jaseci/extens/act_lib/tests/test_maths.py +0 -147
- jaseci/extens/act_lib/tests/test_net_lib.py +0 -62
- jaseci/extens/act_lib/tests/test_regex.py +0 -61
- jaseci/extens/act_lib/tests/test_std.py +0 -51
- jaseci/extens/act_lib/tests/test_std_lib.py +0 -36
- jaseci/extens/act_lib/tests/test_url.py +0 -32
- jaseci/extens/act_lib/tests/test_vector.py +0 -36
- jaseci/extens/act_lib/tests/test_webtool.py +0 -44
- jaseci/extens/act_lib/tests/test_zlib.py +0 -24
- jaseci/extens/act_lib/url.py +0 -80
- jaseci/extens/act_lib/vector.py +0 -158
- jaseci/extens/act_lib/webtool.py +0 -29
- jaseci/extens/act_lib/zip.py +0 -34
- jaseci/extens/api/__init__.py +0 -0
- jaseci/extens/api/actions_api.py +0 -171
- jaseci/extens/api/alias_api.py +0 -140
- jaseci/extens/api/architype_api.py +0 -197
- jaseci/extens/api/config_api.py +0 -129
- jaseci/extens/api/global_api.py +0 -85
- jaseci/extens/api/graph_api.py +0 -168
- jaseci/extens/api/health_api.py +0 -21
- jaseci/extens/api/interface.py +0 -269
- jaseci/extens/api/jac_api.py +0 -172
- jaseci/extens/api/jsorc_api.py +0 -317
- jaseci/extens/api/logger_api.py +0 -90
- jaseci/extens/api/master_api.py +0 -134
- jaseci/extens/api/object_api.py +0 -102
- jaseci/extens/api/prometheus_api.py +0 -75
- jaseci/extens/api/queue_api.py +0 -141
- jaseci/extens/api/sentinel_api.py +0 -271
- jaseci/extens/api/share_api.py +0 -64
- jaseci/extens/api/super_api.py +0 -65
- jaseci/extens/api/tests/__init__.py +0 -0
- jaseci/extens/api/tests/test_architype_api.py +0 -66
- jaseci/extens/api/tests/test_global_api.py +0 -179
- jaseci/extens/api/tests/test_graph_api.py +0 -64
- jaseci/extens/api/tests/test_logger_api.py +0 -43
- jaseci/extens/api/tests/test_object_api.py +0 -20
- jaseci/extens/api/tests/test_sentinel_api.py +0 -66
- jaseci/extens/api/tests/test_uncommon.py +0 -107
- jaseci/extens/api/tests/test_user_api.py +0 -32
- jaseci/extens/api/tests/test_walker_api.py +0 -316
- jaseci/extens/api/user_api.py +0 -166
- jaseci/extens/api/walker_api.py +0 -299
- jaseci/extens/api/webhook_api.py +0 -77
- jaseci/extens/svc/__init__.py +0 -0
- jaseci/extens/svc/elastic_svc.py +0 -366
- jaseci/extens/svc/kube_svc.py +0 -432
- jaseci/extens/svc/mail_svc.py +0 -156
- jaseci/extens/svc/prome_svc.py +0 -378
- jaseci/extens/svc/redis_svc.py +0 -63
- jaseci/extens/svc/storage_svc.py +0 -193
- jaseci/extens/svc/stripe_svc.py +0 -51
- jaseci/extens/svc/task_svc.py +0 -155
- jaseci/extens/svc/tasks.py +0 -302
- jaseci/jac/__init__.py +0 -0
- jaseci/jac/interpreter/__init__.py +0 -0
- jaseci/jac/interpreter/architype_interp.py +0 -219
- jaseci/jac/interpreter/interp.py +0 -1784
- jaseci/jac/interpreter/sentinel_interp.py +0 -260
- jaseci/jac/interpreter/tests/__init__.py +0 -0
- jaseci/jac/interpreter/tests/test_interp.py +0 -42
- jaseci/jac/interpreter/walker_interp.py +0 -249
- jaseci/jac/ir/__init__.py +0 -0
- jaseci/jac/ir/ast.py +0 -73
- jaseci/jac/ir/ast_builder.py +0 -249
- jaseci/jac/ir/jac_code.py +0 -151
- jaseci/jac/ir/passes/__init__.py +0 -6
- jaseci/jac/ir/passes/ast_prune_pass.py +0 -9
- jaseci/jac/ir/passes/codegen_pass.py +0 -244
- jaseci/jac/ir/passes/ir_pass.py +0 -29
- jaseci/jac/ir/passes/printer_pass.py +0 -23
- jaseci/jac/ir/passes/pt_prune_pass.py +0 -29
- jaseci/jac/ir/passes/schedule.py +0 -23
- jaseci/jac/ir/passes/stats_pass.py +0 -16
- jaseci/jac/jac.g4 +0 -450
- jaseci/jac/jac_parse/__init__.py +0 -0
- jaseci/jac/jac_parse/jacLexer.py +0 -809
- jaseci/jac/jac_parse/jacListener.py +0 -853
- jaseci/jac/jac_parse/jacParser.py +0 -9192
- jaseci/jac/jac_set.py +0 -120
- jaseci/jac/jsci_vm/__init__.py +0 -0
- jaseci/jac/jsci_vm/disasm.py +0 -94
- jaseci/jac/jsci_vm/inst_ptr.py +0 -31
- jaseci/jac/jsci_vm/machine.py +0 -188
- jaseci/jac/jsci_vm/op_codes.py +0 -82
- jaseci/jac/jsci_vm/tests/__init__.py +0 -0
- jaseci/jac/jsci_vm/tests/test_codegen.py +0 -31
- jaseci/jac/machine/__init__.py +0 -0
- jaseci/jac/machine/jac_scope.py +0 -86
- jaseci/jac/machine/jac_value.py +0 -227
- jaseci/jac/machine/machine_state.py +0 -386
- jaseci/jac/tests/__init__.py +0 -0
- jaseci/jac/tests/book_code.py +0 -624
- jaseci/jac/tests/test_book.py +0 -380
- jaseci/jac/tests/test_lang_14.py +0 -49
- jaseci/jsorc/__init__.py +0 -7
- jaseci/jsorc/jsorc.py +0 -642
- jaseci/jsorc/jsorc_settings.py +0 -211
- jaseci/jsorc/jsorc_utils.py +0 -298
- jaseci/jsorc/live_actions.py +0 -365
- jaseci/jsorc/manifests/__init__.py +0 -0
- jaseci/jsorc/manifests/database.yaml +0 -109
- jaseci/jsorc/manifests/elastic.yaml +0 -6029
- jaseci/jsorc/manifests/prometheus.yaml +0 -1383
- jaseci/jsorc/manifests/redis.yaml +0 -64
- jaseci/jsorc/memory.py +0 -258
- jaseci/jsorc/redis.py +0 -140
- jaseci/jsorc/remote_actions.py +0 -158
- jaseci/jsorc/tests/__init__.py +0 -0
- jaseci/jsorc/tests/test_actions.py +0 -542
- jaseci/jsorc/tests/test_jsorc.py +0 -112
- jaseci/prim/__init__.py +0 -0
- jaseci/prim/ability.py +0 -94
- jaseci/prim/architype.py +0 -90
- jaseci/prim/edge.py +0 -173
- jaseci/prim/element.py +0 -233
- jaseci/prim/graph.py +0 -27
- jaseci/prim/master.py +0 -67
- jaseci/prim/node.py +0 -533
- jaseci/prim/obj_mixins.py +0 -238
- jaseci/prim/sentinel.py +0 -282
- jaseci/prim/super_master.py +0 -31
- jaseci/prim/walker.py +0 -261
- jaseci/svc/__init__.py +0 -0
- jaseci/tests/__init__.py +0 -0
- jaseci/tests/infer.py +0 -39
- jaseci/tests/jac_test_code.py +0 -1293
- jaseci/tests/jac_test_progs.py +0 -774
- jaseci/tests/test_core.py +0 -153
- jaseci/tests/test_jac.py +0 -824
- jaseci/tests/test_node.py +0 -89
- jaseci/tests/test_progs.py +0 -702
- jaseci/tests/test_stack.py +0 -220
- jaseci/tests/test_stripe.py +0 -225
- jaseci/utils/__init__.py +0 -0
- jaseci/utils/actions/__init__.py +0 -0
- jaseci/utils/actions/actions_manager.py +0 -254
- jaseci/utils/actions/actions_optimizer.py +0 -517
- jaseci/utils/actions/actions_state.py +0 -95
- jaseci/utils/file_handler.py +0 -171
- jaseci/utils/gprof2dot.py +0 -3786
- jaseci/utils/id_list.py +0 -169
- jaseci/utils/json_handler.py +0 -70
- jaseci/utils/log_utils.py +0 -57
- jaseci/utils/test_core.py +0 -62
- jaseci/utils/utils.py +0 -387
- jaseci-1.4.2.6.dist-info/LICENSE +0 -21
- jaseci-1.4.2.6.dist-info/METADATA +0 -39
- jaseci-1.4.2.6.dist-info/RECORD +0 -185
- jaseci-1.4.2.6.dist-info/entry_points.txt +0 -3
- jaseci-1.4.2.6.dist-info/top_level.txt +0 -1
jaseci/extens/svc/prome_svc.py
DELETED
|
@@ -1,378 +0,0 @@
|
|
|
1
|
-
import time
|
|
2
|
-
from prometheus_api_client import PrometheusConnect
|
|
3
|
-
from jaseci.jsorc.jsorc import JsOrc
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
class MetricValue:
|
|
7
|
-
node = None
|
|
8
|
-
pod = None
|
|
9
|
-
|
|
10
|
-
def __init__(self, _node: dict, _pod: dict):
|
|
11
|
-
self.node = _node
|
|
12
|
-
self.pod = _pod
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
@JsOrc.service(name="prome", config="PROME_CONFIG", manifest="PROME_MANIFEST")
|
|
16
|
-
class PrometheusService(JsOrc.CommonService):
|
|
17
|
-
###################################################
|
|
18
|
-
# BUILDER #
|
|
19
|
-
###################################################
|
|
20
|
-
|
|
21
|
-
def run(self):
|
|
22
|
-
self.app = PrometheusConnect(url=self.config.get("url"), disable_ssl=True)
|
|
23
|
-
self.ping()
|
|
24
|
-
self.cpu = Cpu(self.app)
|
|
25
|
-
self.memory = Memory(self.app)
|
|
26
|
-
self.network = Network(self.app)
|
|
27
|
-
self.disk = Disk(self.app)
|
|
28
|
-
|
|
29
|
-
###################################################
|
|
30
|
-
# COMMON UTILS #
|
|
31
|
-
###################################################
|
|
32
|
-
|
|
33
|
-
def ping(self) -> bool:
|
|
34
|
-
prom = self.app
|
|
35
|
-
response = prom._session.get(
|
|
36
|
-
"{0}/".format(prom.url),
|
|
37
|
-
verify=prom.ssl_verification,
|
|
38
|
-
headers=prom.headers,
|
|
39
|
-
timeout=2,
|
|
40
|
-
)
|
|
41
|
-
return response.ok
|
|
42
|
-
|
|
43
|
-
def all_metrics(self) -> list:
|
|
44
|
-
return self.app.all_metrics()
|
|
45
|
-
|
|
46
|
-
def pods(self, namespace: str = "", exclude_prom: bool = False) -> dict:
|
|
47
|
-
if namespace == "":
|
|
48
|
-
util = self.app.get_current_metric_value("kube_pod_info")
|
|
49
|
-
else:
|
|
50
|
-
util = self.app.get_current_metric_value(
|
|
51
|
-
f"kube_pod_info{{namespace='{namespace}'}}"
|
|
52
|
-
)
|
|
53
|
-
res = {}
|
|
54
|
-
for pod in util:
|
|
55
|
-
info = pod["metric"]
|
|
56
|
-
node = info["node"]
|
|
57
|
-
pod = info["pod"]
|
|
58
|
-
if exclude_prom and "prometheus" in pod:
|
|
59
|
-
continue
|
|
60
|
-
if res.get(node) is None:
|
|
61
|
-
res[node] = []
|
|
62
|
-
res[node].append(pod)
|
|
63
|
-
return res
|
|
64
|
-
|
|
65
|
-
def node_info(
|
|
66
|
-
self,
|
|
67
|
-
namespace: str = "",
|
|
68
|
-
exclude_prom: bool = False,
|
|
69
|
-
timestamp: int = 0,
|
|
70
|
-
duration: int = 0,
|
|
71
|
-
) -> dict:
|
|
72
|
-
if namespace == "":
|
|
73
|
-
util = self.app.get_current_metric_value("kube_node_info")
|
|
74
|
-
else:
|
|
75
|
-
util = self.app.get_current_metric_value(
|
|
76
|
-
f"kube_node_info{{namespace='{namespace}'}}"
|
|
77
|
-
)
|
|
78
|
-
|
|
79
|
-
res = {}
|
|
80
|
-
disk_read = self.disk.read()
|
|
81
|
-
disk_write = self.disk.write()
|
|
82
|
-
|
|
83
|
-
node_names = [nodes["metric"]["node"] for nodes in util]
|
|
84
|
-
|
|
85
|
-
for node_name in node_names:
|
|
86
|
-
res[node_name] = {}
|
|
87
|
-
|
|
88
|
-
for node_name in node_names:
|
|
89
|
-
res[node_name]["disk_read_bytes"] = disk_read.get(node_name, 0)
|
|
90
|
-
|
|
91
|
-
for node_name in node_names:
|
|
92
|
-
res[node_name]["disk_write_bytes"] = disk_write.get(node_name, 0)
|
|
93
|
-
|
|
94
|
-
return res
|
|
95
|
-
|
|
96
|
-
def pod_info(
|
|
97
|
-
self,
|
|
98
|
-
namespace: str = "",
|
|
99
|
-
exclude_prom: bool = False,
|
|
100
|
-
timestamp: int = 0,
|
|
101
|
-
duration: int = 0,
|
|
102
|
-
) -> dict:
|
|
103
|
-
if namespace == "":
|
|
104
|
-
util = self.app.get_current_metric_value("kube_pod_info")
|
|
105
|
-
else:
|
|
106
|
-
util = self.app.get_current_metric_value(
|
|
107
|
-
f"kube_pod_info{{namespace='{namespace}'}}"
|
|
108
|
-
)
|
|
109
|
-
|
|
110
|
-
res = {}
|
|
111
|
-
|
|
112
|
-
for pod in util:
|
|
113
|
-
pod_name = pod["metric"]["pod"]
|
|
114
|
-
if exclude_prom and "prometheus" in pod_name:
|
|
115
|
-
continue
|
|
116
|
-
|
|
117
|
-
for pod in util:
|
|
118
|
-
pod_name = pod["metric"]["pod"]
|
|
119
|
-
if exclude_prom and "prometheus" in pod_name:
|
|
120
|
-
continue
|
|
121
|
-
# res[pod_name] = pod["metric"]
|
|
122
|
-
res[pod_name] = {}
|
|
123
|
-
|
|
124
|
-
if timestamp != 0 and duration != 0:
|
|
125
|
-
cpu = self.cpu.utilization_per_pod_cores(ts=timestamp, duration=duration)
|
|
126
|
-
else:
|
|
127
|
-
cpu = self.cpu.utilization_per_pod_cores()
|
|
128
|
-
for pod in util:
|
|
129
|
-
pod_name = pod["metric"]["pod"]
|
|
130
|
-
if exclude_prom and "prometheus" in pod_name:
|
|
131
|
-
continue
|
|
132
|
-
pod_cpu = cpu.get(pod_name, 0)
|
|
133
|
-
|
|
134
|
-
res[pod_name]["cpu_utilization_cores"] = pod_cpu
|
|
135
|
-
if timestamp != 0 and duration != 0:
|
|
136
|
-
cpu = self.cpu.utilization_per_pod_cores(ts=timestamp, duration=duration)
|
|
137
|
-
else:
|
|
138
|
-
cpu = self.cpu.utilization_per_pod_cores()
|
|
139
|
-
for pod in util:
|
|
140
|
-
pod_name = pod["metric"]["pod"]
|
|
141
|
-
if exclude_prom and "prometheus" in pod_name:
|
|
142
|
-
continue
|
|
143
|
-
pod_cpu = cpu.get(pod_name, 0)
|
|
144
|
-
|
|
145
|
-
res[pod_name]["cpu_utilization_cores"] = pod_cpu
|
|
146
|
-
|
|
147
|
-
mem = self.memory.utilization_per_pod_bytes()
|
|
148
|
-
for pod in util:
|
|
149
|
-
pod_name = pod["metric"]["pod"]
|
|
150
|
-
pod_mem = mem.get(pod_name, 0)
|
|
151
|
-
res[pod_name]["mem_utilization_bytes"] = pod_mem
|
|
152
|
-
|
|
153
|
-
if timestamp != 0 and duration != 0:
|
|
154
|
-
recv = self.network.receive_per_pod_bytes(ts=timestamp, duration=duration)
|
|
155
|
-
else:
|
|
156
|
-
recv = self.network.receive_per_pod_bytes()
|
|
157
|
-
for pod in util:
|
|
158
|
-
pod_name = pod["metric"]["pod"]
|
|
159
|
-
if exclude_prom and "prometheus" in pod_name:
|
|
160
|
-
continue
|
|
161
|
-
pod_recv = recv.get(pod_name, 0)
|
|
162
|
-
res[pod_name]["network_recv_bytes"] = pod_recv
|
|
163
|
-
|
|
164
|
-
if timestamp != 0 and duration != 0:
|
|
165
|
-
tran = self.network.transmit_per_pod_bytes(ts=timestamp, duration=duration)
|
|
166
|
-
else:
|
|
167
|
-
tran = self.network.transmit_per_pod_bytes()
|
|
168
|
-
for pod in util:
|
|
169
|
-
pod_name = pod["metric"]["pod"]
|
|
170
|
-
if exclude_prom and "prometheus" in pod_name:
|
|
171
|
-
continue
|
|
172
|
-
pod_tran = tran.get(pod_name, 0)
|
|
173
|
-
res[pod_name]["network_tran_bytes"] = pod_tran
|
|
174
|
-
|
|
175
|
-
return res
|
|
176
|
-
|
|
177
|
-
def info(
|
|
178
|
-
self,
|
|
179
|
-
namespace: str = "",
|
|
180
|
-
exclude_prom: bool = False,
|
|
181
|
-
timestamp: int = 0,
|
|
182
|
-
duration: int = 0,
|
|
183
|
-
) -> MetricValue:
|
|
184
|
-
node_value = self.node_info(
|
|
185
|
-
namespace=namespace,
|
|
186
|
-
exclude_prom=exclude_prom,
|
|
187
|
-
timestamp=timestamp,
|
|
188
|
-
duration=duration,
|
|
189
|
-
)
|
|
190
|
-
pod_value = self.pod_info(
|
|
191
|
-
namespace=namespace,
|
|
192
|
-
exclude_prom=exclude_prom,
|
|
193
|
-
timestamp=timestamp,
|
|
194
|
-
duration=duration,
|
|
195
|
-
)
|
|
196
|
-
return MetricValue(_node=node_value, _pod=pod_value)
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
class Info:
|
|
200
|
-
def __init__(self, app):
|
|
201
|
-
self.app = app
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
class Cpu(Info):
|
|
205
|
-
def utilization_core(self) -> dict:
|
|
206
|
-
util = self.app.get_current_metric_value(
|
|
207
|
-
'sum(irate(node_cpu_seconds_total{mode!="idle"}[10m])) by (node)'
|
|
208
|
-
)
|
|
209
|
-
res = {}
|
|
210
|
-
for node in util:
|
|
211
|
-
node_name = node["metric"]["node"]
|
|
212
|
-
node_util = float(node["value"][1])
|
|
213
|
-
res[node_name] = node_util
|
|
214
|
-
return res
|
|
215
|
-
|
|
216
|
-
def utilization_percentage(self) -> dict:
|
|
217
|
-
util = self.app.get_current_metric_value(
|
|
218
|
-
'(sum(irate(node_cpu_seconds_total{mode!="idle"}[10m])) by '
|
|
219
|
-
'(node)) / (sum(irate(node_cpu_seconds_total{mode!=""}[10m])) by '
|
|
220
|
-
"(node)) * 100"
|
|
221
|
-
)
|
|
222
|
-
res = {}
|
|
223
|
-
for node in util:
|
|
224
|
-
node_name = node["metric"]["node"]
|
|
225
|
-
node_util = float(node["value"][1])
|
|
226
|
-
res[node_name] = node_util
|
|
227
|
-
return res
|
|
228
|
-
|
|
229
|
-
def utilization_per_pod_cores(self, ts=int(time.time()), duration=10) -> dict:
|
|
230
|
-
query_str = f'sum(rate(container_cpu_usage_seconds_total{{pod!=""}}[{duration}s] @ {ts})) by (pod)'
|
|
231
|
-
util = self.app.get_current_metric_value(query_str)
|
|
232
|
-
res = {}
|
|
233
|
-
for pod in util:
|
|
234
|
-
pod_name = pod["metric"]["pod"]
|
|
235
|
-
value = float(pod["value"][1])
|
|
236
|
-
res[pod_name] = float(value)
|
|
237
|
-
return res
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
class Memory(Info):
|
|
241
|
-
def total_bytes(self) -> dict:
|
|
242
|
-
util = self.app.get_current_metric_value(
|
|
243
|
-
"sum(node_memory_MemTotal_bytes) by (node)"
|
|
244
|
-
)
|
|
245
|
-
res = {}
|
|
246
|
-
for node in util:
|
|
247
|
-
node_name = node["metric"]["node"]
|
|
248
|
-
node_util = float(node["value"][1])
|
|
249
|
-
res[node_name] = node_util
|
|
250
|
-
return res
|
|
251
|
-
|
|
252
|
-
def utilization_bytes(self) -> dict:
|
|
253
|
-
util = self.app.get_current_metric_value(
|
|
254
|
-
"sum(node_memory_Active_bytes) by (node)"
|
|
255
|
-
)
|
|
256
|
-
res = {}
|
|
257
|
-
for node in util:
|
|
258
|
-
node_name = node["metric"]["node"]
|
|
259
|
-
node_util = float(node["value"][1])
|
|
260
|
-
res[node_name] = node_util
|
|
261
|
-
return res
|
|
262
|
-
|
|
263
|
-
def utilization_percentage(self) -> dict:
|
|
264
|
-
util = self.app.get_current_metric_value(
|
|
265
|
-
"sum(node_memory_Active_bytes / node_memory_MemTotal_bytes * 100 ) by "
|
|
266
|
-
"(node)"
|
|
267
|
-
)
|
|
268
|
-
res = {}
|
|
269
|
-
for node in util:
|
|
270
|
-
node_name = node["metric"]["node"]
|
|
271
|
-
node_util = float(node["value"][1])
|
|
272
|
-
res[node_name] = node_util
|
|
273
|
-
return res
|
|
274
|
-
|
|
275
|
-
def utilization_per_pod_bytes(self) -> dict:
|
|
276
|
-
util = self.app.get_current_metric_value(
|
|
277
|
-
'sum(container_memory_working_set_bytes{pod!=""}) by (pod)'
|
|
278
|
-
)
|
|
279
|
-
res = {}
|
|
280
|
-
for pod in util:
|
|
281
|
-
pod_name = pod["metric"]["pod"]
|
|
282
|
-
value = float(pod["value"][1])
|
|
283
|
-
res[pod_name] = float(value)
|
|
284
|
-
return res
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
class Network(Info):
|
|
288
|
-
def receive_bytes(self) -> dict:
|
|
289
|
-
util = self.app.get_current_metric_value(
|
|
290
|
-
"sum (rate (node_network_receive_bytes_total{}[10m])) by (node)"
|
|
291
|
-
)
|
|
292
|
-
res = {}
|
|
293
|
-
for node in util:
|
|
294
|
-
node_name = node["metric"]["node"]
|
|
295
|
-
node_util = float(node["value"][1])
|
|
296
|
-
res[node_name] = node_util
|
|
297
|
-
return res
|
|
298
|
-
|
|
299
|
-
def receive_per_pod_bytes(self, ts: int = int(time.time()), duration: int = 10):
|
|
300
|
-
util = self.app.get_current_metric_value(
|
|
301
|
-
f'sum (rate (container_network_receive_bytes_total{{pod!=""}}[{duration}s] @ {ts})) by (pod)'
|
|
302
|
-
)
|
|
303
|
-
res = {}
|
|
304
|
-
for pod in util:
|
|
305
|
-
pod_name = pod["metric"]["pod"]
|
|
306
|
-
value = pod["value"][1]
|
|
307
|
-
res[pod_name] = float(value)
|
|
308
|
-
return res
|
|
309
|
-
|
|
310
|
-
def transmit_bytes(self) -> dict:
|
|
311
|
-
util = self.app.get_current_metric_value(
|
|
312
|
-
"sum (rate (node_network_transmit_bytes_total{}[10m])) by (node)"
|
|
313
|
-
)
|
|
314
|
-
res = {}
|
|
315
|
-
for node in util:
|
|
316
|
-
node_name = node["metric"]["node"]
|
|
317
|
-
node_util = float(node["value"][1])
|
|
318
|
-
res[node_name] = node_util
|
|
319
|
-
return res
|
|
320
|
-
|
|
321
|
-
def transmit_per_pod_bytes(self, ts: int = int(time.time()), duration: int = 10):
|
|
322
|
-
util = self.app.get_current_metric_value(
|
|
323
|
-
f'sum (rate (container_network_transmit_bytes_total{{pod!=""}}[{duration}s] @ {ts})) by (pod)'
|
|
324
|
-
)
|
|
325
|
-
res = {}
|
|
326
|
-
for pod in util:
|
|
327
|
-
pod_name = pod["metric"]["pod"]
|
|
328
|
-
value = pod["value"][1]
|
|
329
|
-
res[pod_name] = float(value)
|
|
330
|
-
return res
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
class Disk(Info):
|
|
334
|
-
def total_bytes(self) -> dict:
|
|
335
|
-
util = self.app.get_current_metric_value(
|
|
336
|
-
'sum(avg (node_filesystem_size_bytes{mountpoint!="/boot", '
|
|
337
|
-
'fstype!="tmpfs"}) without (mountpoint)) by (node)'
|
|
338
|
-
)
|
|
339
|
-
res = {}
|
|
340
|
-
for node in util:
|
|
341
|
-
node_name = node["metric"]["node"]
|
|
342
|
-
node_util = float(node["value"][1])
|
|
343
|
-
res[node_name] = node_util
|
|
344
|
-
return res
|
|
345
|
-
|
|
346
|
-
def free_bytes(self) -> dict:
|
|
347
|
-
util = self.app.get_current_metric_value(
|
|
348
|
-
'sum(avg (node_filesystem_free_bytes{mountpoint!="/boot", '
|
|
349
|
-
'fstype!="tmpfs"}) without (mountpoint)) by (node)'
|
|
350
|
-
)
|
|
351
|
-
res = {}
|
|
352
|
-
for node in util:
|
|
353
|
-
node_name = node["metric"]["node"]
|
|
354
|
-
node_util = float(node["value"][1])
|
|
355
|
-
res[node_name] = node_util
|
|
356
|
-
return res
|
|
357
|
-
|
|
358
|
-
def read(self) -> dict:
|
|
359
|
-
util = self.app.get_current_metric_value(
|
|
360
|
-
"sum (rate (node_disk_read_bytes_total{}[10m])) by (node)"
|
|
361
|
-
)
|
|
362
|
-
res = {}
|
|
363
|
-
for node in util:
|
|
364
|
-
node_name = node["metric"]["node"]
|
|
365
|
-
node_util = float(node["value"][1])
|
|
366
|
-
res[node_name] = node_util
|
|
367
|
-
return res
|
|
368
|
-
|
|
369
|
-
def write(self) -> dict:
|
|
370
|
-
util = self.app.get_current_metric_value(
|
|
371
|
-
"sum (rate (node_disk_written_bytes_total{}[10m])) by (node)"
|
|
372
|
-
)
|
|
373
|
-
res = {}
|
|
374
|
-
for node in util:
|
|
375
|
-
node_name = node["metric"]["node"]
|
|
376
|
-
node_util = float(node["value"][1])
|
|
377
|
-
res[node_name] = node_util
|
|
378
|
-
return res
|
jaseci/extens/svc/redis_svc.py
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
from jaseci.jsorc.jsorc import JsOrc
|
|
2
|
-
from redis import Redis
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
@JsOrc.service(
|
|
6
|
-
name="redis",
|
|
7
|
-
config="REDIS_CONFIG",
|
|
8
|
-
manifest="REDIS_MANIFEST",
|
|
9
|
-
priority=0,
|
|
10
|
-
proxy=True,
|
|
11
|
-
)
|
|
12
|
-
class RedisService(JsOrc.CommonService):
|
|
13
|
-
def run(self):
|
|
14
|
-
self.app = Redis(**self.config, decode_responses=True)
|
|
15
|
-
self.app.ping()
|
|
16
|
-
|
|
17
|
-
###################################################
|
|
18
|
-
# COMMONS #
|
|
19
|
-
###################################################
|
|
20
|
-
|
|
21
|
-
def get(self, name):
|
|
22
|
-
return self.app.get(name)
|
|
23
|
-
|
|
24
|
-
def set(self, name, val):
|
|
25
|
-
self.app.set(name, val)
|
|
26
|
-
|
|
27
|
-
def exists(self, name):
|
|
28
|
-
return self.app.exists(name)
|
|
29
|
-
|
|
30
|
-
def delete(self, name):
|
|
31
|
-
self.app.delete(name)
|
|
32
|
-
|
|
33
|
-
def hget(self, name, key):
|
|
34
|
-
return self.app.hget(name, key)
|
|
35
|
-
|
|
36
|
-
def hset(self, name, key, val):
|
|
37
|
-
self.app.hset(name, key, val)
|
|
38
|
-
|
|
39
|
-
def hexists(self, name, key):
|
|
40
|
-
return self.app.hexists(name, key)
|
|
41
|
-
|
|
42
|
-
def hdel(self, name, key):
|
|
43
|
-
self.app.hdel(name, key)
|
|
44
|
-
|
|
45
|
-
def hkeys(self, name):
|
|
46
|
-
return self.app.hkeys(name)
|
|
47
|
-
|
|
48
|
-
###################################################
|
|
49
|
-
# CLEANER #
|
|
50
|
-
###################################################
|
|
51
|
-
|
|
52
|
-
def clear(self, all=True):
|
|
53
|
-
if self.is_running():
|
|
54
|
-
if all:
|
|
55
|
-
self.app.flushall()
|
|
56
|
-
else:
|
|
57
|
-
self.app.flushdb()
|
|
58
|
-
|
|
59
|
-
# ---------------- PROXY EVENTS ----------------- #
|
|
60
|
-
|
|
61
|
-
def on_delete(self):
|
|
62
|
-
if self.is_running():
|
|
63
|
-
self.app.close()
|
jaseci/extens/svc/storage_svc.py
DELETED
|
@@ -1,193 +0,0 @@
|
|
|
1
|
-
from datetime import datetime, timedelta
|
|
2
|
-
|
|
3
|
-
from jaseci.jsorc.jsorc import JsOrc
|
|
4
|
-
from jaseci.utils.file_handler import FileHandler
|
|
5
|
-
|
|
6
|
-
from libcloud.storage.types import Provider, ObjectDoesNotExistError
|
|
7
|
-
from libcloud.storage.providers import get_driver as _get_driver
|
|
8
|
-
from libcloud.storage.base import StorageDriver, Object, Container
|
|
9
|
-
from libcloud.storage.drivers.azure_blobs import AzureBlobsStorageDriver
|
|
10
|
-
|
|
11
|
-
from azure.storage.blob import generate_blob_sas
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
@JsOrc.service(
|
|
15
|
-
name="store",
|
|
16
|
-
config="STORE_CONFIG",
|
|
17
|
-
manifest="STORE_MANIFEST",
|
|
18
|
-
priority=0,
|
|
19
|
-
proxy=True,
|
|
20
|
-
)
|
|
21
|
-
class StorageService(JsOrc.CommonService):
|
|
22
|
-
def run(self):
|
|
23
|
-
self.app = StorageHandler(self.config["providers"], self.config.get("default"))
|
|
24
|
-
|
|
25
|
-
# Testing
|
|
26
|
-
# obj = self.upload(FileHandler.fromPath("test.txt"))
|
|
27
|
-
# self.download(obj["name"])
|
|
28
|
-
|
|
29
|
-
def upload(
|
|
30
|
-
self, file: FileHandler, provider: str = None, container: str = None
|
|
31
|
-
) -> dict:
|
|
32
|
-
provider = self.app.get_storage(provider)
|
|
33
|
-
buffer = file.open(mode="rb", encoding=None, detached=True)
|
|
34
|
-
|
|
35
|
-
metadata = {
|
|
36
|
-
"id": file.id,
|
|
37
|
-
"name": file.name,
|
|
38
|
-
"created": datetime.utcnow().isoformat(),
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
# metadata doesn't support empty value
|
|
42
|
-
if file.content_type:
|
|
43
|
-
metadata["content_type"] = file.content_type
|
|
44
|
-
|
|
45
|
-
# metadata doesn't support empty value
|
|
46
|
-
if file.field:
|
|
47
|
-
metadata["field"] = file.field
|
|
48
|
-
|
|
49
|
-
if container:
|
|
50
|
-
container = provider["driver"].get_container(container_name=container)
|
|
51
|
-
|
|
52
|
-
obj: Object = provider["driver"].upload_object_via_stream(
|
|
53
|
-
iterator=buffer,
|
|
54
|
-
container=container or provider["container"],
|
|
55
|
-
object_name=file.absolute_name,
|
|
56
|
-
extra={"meta_data": metadata},
|
|
57
|
-
)
|
|
58
|
-
|
|
59
|
-
buffer.close()
|
|
60
|
-
|
|
61
|
-
return obj.get_cdn_url()
|
|
62
|
-
|
|
63
|
-
def download(
|
|
64
|
-
self, file: str, provider: str = None, container: str = None
|
|
65
|
-
) -> FileHandler:
|
|
66
|
-
provider = self.app.get_storage(provider)
|
|
67
|
-
|
|
68
|
-
obj: Object = provider["driver"].get_object(
|
|
69
|
-
container_name=container or provider["container"].name, object_name=file
|
|
70
|
-
)
|
|
71
|
-
|
|
72
|
-
temp_file = FileHandler(file)
|
|
73
|
-
temp_file.open(mode="wb", encoding=None)
|
|
74
|
-
for chunk in provider["driver"].download_object_as_stream(obj):
|
|
75
|
-
temp_file.write(chunk)
|
|
76
|
-
temp_file.close()
|
|
77
|
-
|
|
78
|
-
return temp_file
|
|
79
|
-
|
|
80
|
-
def cdn_url(
|
|
81
|
-
self, file: str, provider: str = None, container: str = None, **kwargs
|
|
82
|
-
) -> str:
|
|
83
|
-
provider = self.app.get_storage(provider)
|
|
84
|
-
driver = provider["driver"]
|
|
85
|
-
|
|
86
|
-
return driver.get_object_cdn_url(
|
|
87
|
-
driver.get_object(
|
|
88
|
-
container_name=container or provider["container"].name, object_name=file
|
|
89
|
-
),
|
|
90
|
-
**kwargs,
|
|
91
|
-
)
|
|
92
|
-
|
|
93
|
-
def delete(self, file: str, provider: str = None, container: str = None) -> bool:
|
|
94
|
-
provider = self.app.get_storage(provider)
|
|
95
|
-
|
|
96
|
-
try:
|
|
97
|
-
obj: Object = provider["driver"].get_object(
|
|
98
|
-
container_name=container or provider["container"].name, object_name=file
|
|
99
|
-
)
|
|
100
|
-
except ObjectDoesNotExistError:
|
|
101
|
-
return True
|
|
102
|
-
|
|
103
|
-
return provider["driver"].delete_object(obj)
|
|
104
|
-
|
|
105
|
-
def create_container(self, name: str, provider: str = None) -> Container:
|
|
106
|
-
provider = self.app.get_storage(provider)
|
|
107
|
-
|
|
108
|
-
return provider["driver"].create_container(container_name=name)
|
|
109
|
-
|
|
110
|
-
def has_container(self, name: str, provider: str = None) -> bool:
|
|
111
|
-
provider = self.app.get_storage(provider)
|
|
112
|
-
|
|
113
|
-
return isinstance(
|
|
114
|
-
provider["driver"].get_container(container_name=name), Container
|
|
115
|
-
)
|
|
116
|
-
|
|
117
|
-
def delete_container(self, name: str, provider: str = None) -> bool:
|
|
118
|
-
provider = self.app.get_storage(provider)
|
|
119
|
-
|
|
120
|
-
return provider["driver"].delete_container(
|
|
121
|
-
provider["driver"].get_container(container_name=name)
|
|
122
|
-
)
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
class StorageHandler:
|
|
126
|
-
def __init__(self, providers: dict, default: str = None):
|
|
127
|
-
self.default = default
|
|
128
|
-
self.storage = {}
|
|
129
|
-
|
|
130
|
-
for key, value in providers.items():
|
|
131
|
-
try:
|
|
132
|
-
driver = get_driver(value["provider"])(**value["credentials"])
|
|
133
|
-
container = driver.get_container(container_name=value["container"])
|
|
134
|
-
self.storage[key] = {
|
|
135
|
-
"source": value,
|
|
136
|
-
"driver": driver,
|
|
137
|
-
"container": container,
|
|
138
|
-
}
|
|
139
|
-
self.storage[key]
|
|
140
|
-
except Exception as e:
|
|
141
|
-
self.storage[key] = {"source": value, "error": str(e)}
|
|
142
|
-
|
|
143
|
-
def get_storage(self, provider: str = None) -> StorageDriver:
|
|
144
|
-
if provider:
|
|
145
|
-
return self.storage[provider]
|
|
146
|
-
elif self.default:
|
|
147
|
-
return self.storage[self.default]
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
#############################################################################################
|
|
151
|
-
# ----------------------------------- PROVIDER OVERRIDE ----------------------------------- #
|
|
152
|
-
#############################################################################################
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
class AzureBlobsStorageDriverOverride(AzureBlobsStorageDriver):
|
|
156
|
-
AZURE_STORAGE_CDN_URL_DATE_FORMAT = "%Y-%m-%dT%HH:%M:%SZ"
|
|
157
|
-
|
|
158
|
-
def __init__(
|
|
159
|
-
self,
|
|
160
|
-
key,
|
|
161
|
-
secret=None,
|
|
162
|
-
**kwargs,
|
|
163
|
-
):
|
|
164
|
-
self.secret_raw = secret
|
|
165
|
-
super().__init__(key, secret, **kwargs)
|
|
166
|
-
|
|
167
|
-
def get_object_cdn_url(self, obj: Object, ex_expiry: float = 24, **kwargs):
|
|
168
|
-
sas = generate_blob_sas(
|
|
169
|
-
self.key,
|
|
170
|
-
obj.container.name,
|
|
171
|
-
obj.name,
|
|
172
|
-
account_key=self.secret_raw,
|
|
173
|
-
permission="r",
|
|
174
|
-
expiry=datetime.utcnow() + timedelta(hours=ex_expiry),
|
|
175
|
-
**kwargs,
|
|
176
|
-
)
|
|
177
|
-
|
|
178
|
-
return "{scheme}://{host}:{port}{action}?{sas_token}".format(
|
|
179
|
-
scheme="https" if self.secure else "http",
|
|
180
|
-
host=self.connection.host,
|
|
181
|
-
port=self.connection.port,
|
|
182
|
-
action=self.connection.morph_action_hook(
|
|
183
|
-
self._get_object_path(obj.container, obj.name)
|
|
184
|
-
),
|
|
185
|
-
sas_token=sas,
|
|
186
|
-
)
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
overrided_providers = {Provider.AZURE_BLOBS: AzureBlobsStorageDriverOverride}
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
def get_driver(provider):
|
|
193
|
-
return overrided_providers.get(provider) or _get_driver(provider)
|
jaseci/extens/svc/stripe_svc.py
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import stripe
|
|
2
|
-
from jaseci.jsorc.jsorc import JsOrc
|
|
3
|
-
|
|
4
|
-
#################################################
|
|
5
|
-
# STRIPE APP #
|
|
6
|
-
#################################################
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
@JsOrc.service("stripe", config="STRIPE_CONFIG")
|
|
10
|
-
class StripeService(JsOrc.CommonService):
|
|
11
|
-
###################################################
|
|
12
|
-
# BUILDER #
|
|
13
|
-
###################################################
|
|
14
|
-
|
|
15
|
-
def run(self):
|
|
16
|
-
self.app = stripe
|
|
17
|
-
if not self.config.get("api_key"):
|
|
18
|
-
raise Exception("api_key is required!")
|
|
19
|
-
self.app.api_key = self.config.get("api_key")
|
|
20
|
-
|
|
21
|
-
if not self.config.get("webhook_key"):
|
|
22
|
-
raise Exception("webhook_key is required!")
|
|
23
|
-
self.webhook_key = self.config.get("webhook_key")
|
|
24
|
-
|
|
25
|
-
self.fallback_walker = self.config.get("fallback_walker")
|
|
26
|
-
if not self.fallback_walker:
|
|
27
|
-
raise Exception("fallback_walker is required!")
|
|
28
|
-
|
|
29
|
-
self.event_walker = self.config.get("event_walker", {})
|
|
30
|
-
|
|
31
|
-
####################################################
|
|
32
|
-
# COMMON GETTER/SETTER #
|
|
33
|
-
####################################################
|
|
34
|
-
|
|
35
|
-
def get_walker(self, event):
|
|
36
|
-
return self.event_walker.get(event) or self.fallback_walker
|
|
37
|
-
|
|
38
|
-
def get_event(self, body, headers):
|
|
39
|
-
return stripe.Webhook.construct_event(
|
|
40
|
-
body,
|
|
41
|
-
headers.get("Stripe-Signature"),
|
|
42
|
-
self.webhook_key,
|
|
43
|
-
)
|
|
44
|
-
|
|
45
|
-
####################################################
|
|
46
|
-
# OVERRIDDEN #
|
|
47
|
-
####################################################
|
|
48
|
-
|
|
49
|
-
def reset(self, hook, start=True):
|
|
50
|
-
stripe.api_key = None
|
|
51
|
-
super().reset(hook, start)
|