django-restit 4.2.104__py3-none-any.whl → 4.2.106__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.
- {django_restit-4.2.104.dist-info → django_restit-4.2.106.dist-info}/METADATA +1 -1
- {django_restit-4.2.104.dist-info → django_restit-4.2.106.dist-info}/RECORD +9 -8
- metrics/providers/aws.py +37 -6
- metrics/rpc.py +26 -13
- rest/extra/hostinfo.py +122 -0
- rest/rpc.py +14 -112
- taskqueue/periodic.py +9 -0
- {django_restit-4.2.104.dist-info → django_restit-4.2.106.dist-info}/LICENSE.md +0 -0
- {django_restit-4.2.104.dist-info → django_restit-4.2.106.dist-info}/WHEEL +0 -0
@@ -354,8 +354,8 @@ metrics/migrations/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuF
|
|
354
354
|
metrics/models.py,sha256=lD9nVzfwdav70ENulqJ8rE8Ui8EWlzdVp05rg8bAlMA,13444
|
355
355
|
metrics/periodic.py,sha256=VmL0YG05D6k5fcNsF4QqPEU-BBPbZXjbOrp3b8EHZ-U,651
|
356
356
|
metrics/providers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
357
|
-
metrics/providers/aws.py,sha256=
|
358
|
-
metrics/rpc.py,sha256=
|
357
|
+
metrics/providers/aws.py,sha256=vhz0w6xE_V_V050g3V2uKEUPRIaI_o48MFkfsHjLzQU,8307
|
358
|
+
metrics/rpc.py,sha256=yIv1ZVnlY_RYI693pX5iptH3gnVAC1DQ2nJQ5vLZQyw,21657
|
359
359
|
metrics/settings.py,sha256=wwHA9Z7BAHNeu3tFVn8Fh5j46KR-eGx0E8r5dzCFlAU,132
|
360
360
|
metrics/tq.py,sha256=WHBRYSinmTuxF9l-_-lx0yfzEYkb0ffVMt_uvCj9bYo,825
|
361
361
|
metrics/utils.py,sha256=PSydxeI983udULUTcbeWG-_ulPSOac6Q_t_8k_Vjn1I,12606
|
@@ -386,6 +386,7 @@ rest/decorators.py,sha256=ig0LATc3-2mhEJPAWHRbIRM-ZOFyjm6e_F9RhpRWidE,15082
|
|
386
386
|
rest/encryption.py,sha256=x6Kiez0tVqfxK26MSsRL3k8OS05ni1gEX2aj3I0S9V0,788
|
387
387
|
rest/errors.py,sha256=uKwG9OkLme36etabqK54DMjMQc1fgEoUIAUxXa7WFQw,612
|
388
388
|
rest/extra/__init__.py,sha256=YzmNsch5H5FFLkUK9mIAKyoRK_rJCA9HGb0kubp4h30,54
|
389
|
+
rest/extra/hostinfo.py,sha256=bAj-6XjY9sJPLHqLxZZLHjmlzSFDJK1L18w81Zb_1ec,3081
|
389
390
|
rest/extra/json_metadata.py,sha256=p_ffzmANmOFix_oC3voR6_NNTjcn7-T7aXcH-I4_Npg,1078
|
390
391
|
rest/fields.py,sha256=_v1TJVc6vyWlqmwFRJ6mtuR5Fo-lS0KcUhPWIrzKZUo,9719
|
391
392
|
rest/forms.py,sha256=66Wm5cdy8tKib_mGicjq_yd-gNVMFWRECnrDksnNnwU,6316
|
@@ -412,7 +413,7 @@ rest/models/metadata.py,sha256=1nQ7CYo9bJHoaXE_hVNaj1-Y7yqhHlf2ZlaD1IfTzic,12904
|
|
412
413
|
rest/net.py,sha256=LcB2QV6VNRtsSdmiQvYZgwQUDwOPMn_VBdRiZ6OpI-I,2974
|
413
414
|
rest/regexes.yaml,sha256=VoGb4E-P_K9f82Yzcpltgzekpt9usRtwu9PYlo46nUw,149463
|
414
415
|
rest/requestex.py,sha256=N56056vV3zWkAP-QrYsCu7SdpPzE5kLuPoxGIuZAKt0,16127
|
415
|
-
rest/rpc.py,sha256=
|
416
|
+
rest/rpc.py,sha256=lHJkZXOxLJJoD4LVPDMXZGk5jV6Yltu7Lu4pMxMpq38,1764
|
416
417
|
rest/search.py,sha256=QVjk2b5tZLgf1zM2MHvJTyRjwUbY5ZD7HXSTmSPXtvU,8362
|
417
418
|
rest/serializers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
418
419
|
rest/serializers/collection.py,sha256=V9O4qxw26VX9dSYdbsN0-RNnXEi347Ln8eFLZ003LhA,4646
|
@@ -456,7 +457,7 @@ taskqueue/admin.py,sha256=E6zXoToS_ea3MdoGjZzF1JiepWFtDSoZUQdan8H-pXI,208
|
|
456
457
|
taskqueue/migrations/0001_initial.py,sha256=JwYib8CK5ftSXlfxKZUcKEEVsXktNB5q3h-2tu9inGk,4738
|
457
458
|
taskqueue/migrations/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
458
459
|
taskqueue/models.py,sha256=i8v0vQqlz4X3rVFVJsUSldA-26NEPWnsMZF2Kly_1Qo,22398
|
459
|
-
taskqueue/periodic.py,sha256=
|
460
|
+
taskqueue/periodic.py,sha256=mife_2TnzIqR3HTLcA66aEJeiQTpEkd_1n2qYGTCrak,3844
|
460
461
|
taskqueue/rpc.py,sha256=Lf5VUoqCRkfWUAIvx_s508mjAtDPwpiWyxg0ryqWbQA,5793
|
461
462
|
taskqueue/tq.py,sha256=PzSoDrawYcqZylruEgsK95gcJ4J_VhdM6rxg9V6_X8E,942
|
462
463
|
taskqueue/transports/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
@@ -508,7 +509,7 @@ ws4redis/servers/uwsgi.py,sha256=VyhoCI1DnVFqBiJYHoxqn5Idlf6uJPHvfBKgkjs34mo,172
|
|
508
509
|
ws4redis/settings.py,sha256=K0yBiLUuY81iDM4Yr-k8hbvjn5VVHu5zQhmMK8Dtz0s,1536
|
509
510
|
ws4redis/utf8validator.py,sha256=S0OlfjeGRP75aO6CzZsF4oTjRQAgR17OWE9rgZdMBZA,5122
|
510
511
|
ws4redis/websocket.py,sha256=R0TUyPsoVRD7Y_oU7w2I6NL4fPwiz5Vl94-fUkZgLHA,14848
|
511
|
-
django_restit-4.2.
|
512
|
-
django_restit-4.2.
|
513
|
-
django_restit-4.2.
|
514
|
-
django_restit-4.2.
|
512
|
+
django_restit-4.2.106.dist-info/LICENSE.md,sha256=VHN4hhEeVOoFjtG-5fVv4jesA4SWi0Z-KgOzzN6a1ps,1068
|
513
|
+
django_restit-4.2.106.dist-info/METADATA,sha256=ezVVUPt2DBptvRUCvZP42DgZHm7C--HkHTDgZpnu7A4,7663
|
514
|
+
django_restit-4.2.106.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
515
|
+
django_restit-4.2.106.dist-info/RECORD,,
|
metrics/providers/aws.py
CHANGED
@@ -2,7 +2,7 @@ import boto3
|
|
2
2
|
from datetime import datetime, timedelta
|
3
3
|
from rest import settings
|
4
4
|
from objict import objict
|
5
|
-
import
|
5
|
+
from rest.extra import hostinfo
|
6
6
|
|
7
7
|
|
8
8
|
METRIC_MAP = {
|
@@ -19,10 +19,20 @@ METRIC_MAP = {
|
|
19
19
|
"cache_cons": "CurrConnections",
|
20
20
|
"max": "Maximum",
|
21
21
|
"min": "Minimum",
|
22
|
-
"avg": "Average"
|
22
|
+
"avg": "Average",
|
23
|
+
"ec2_cons": "EstablishedConnections"
|
23
24
|
}
|
24
25
|
|
25
26
|
|
27
|
+
def publishLocalMetrics():
|
28
|
+
# this will publish any local metrics to cloudwatch
|
29
|
+
instance = getLocalEC2()
|
30
|
+
pushMetric(
|
31
|
+
METRIC_MAP["ec2_cons"],
|
32
|
+
hostinfo.getTcpEstablishedCount(),
|
33
|
+
"Count", instance)
|
34
|
+
|
35
|
+
|
26
36
|
def getLocalEC2():
|
27
37
|
"""
|
28
38
|
{
|
@@ -43,9 +53,7 @@ def getLocalEC2():
|
|
43
53
|
"zone": "us-west-2d"
|
44
54
|
}
|
45
55
|
"""
|
46
|
-
|
47
|
-
priv_ip = socket.gethostbyname(hostname)
|
48
|
-
return getEC2ByIP(priv_ip)
|
56
|
+
return getEC2ByIP(hostinfo.getHostIP())
|
49
57
|
|
50
58
|
|
51
59
|
def getClient(region=settings.AWS_REGION, service="cloudwatch"):
|
@@ -54,6 +62,29 @@ def getClient(region=settings.AWS_REGION, service="cloudwatch"):
|
|
54
62
|
return boto3.client(service, aws_access_key_id=key, aws_secret_access_key=secret, region_name=region)
|
55
63
|
|
56
64
|
|
65
|
+
def pushMetric(name, value, unit="Count", instance=None):
|
66
|
+
"""Push the custom metric to CloudWatch."""
|
67
|
+
cloudwatch = getClient(service="cloudwatch")
|
68
|
+
if instance is None:
|
69
|
+
instance = getLocalEC2()
|
70
|
+
return cloudwatch.put_metric_data(
|
71
|
+
Namespace = 'CustomMetrics',
|
72
|
+
MetricData = [
|
73
|
+
{
|
74
|
+
'MetricName': name,
|
75
|
+
'Dimensions': [
|
76
|
+
{
|
77
|
+
'Name': 'InstanceId',
|
78
|
+
'Value': instance.id
|
79
|
+
},
|
80
|
+
],
|
81
|
+
'Value': value,
|
82
|
+
'Unit': unit
|
83
|
+
},
|
84
|
+
]
|
85
|
+
)
|
86
|
+
|
87
|
+
|
57
88
|
def buildQuery(id, instance, period=300, metric="cpu", namespace="rds", stat="max"):
|
58
89
|
dname = "DBInstanceIdentifier"
|
59
90
|
if namespace == "ec2":
|
@@ -135,7 +166,7 @@ def getAllEC2(just_ids=False, region=settings.AWS_REGION):
|
|
135
166
|
|
136
167
|
def getEC2ByIP(ip):
|
137
168
|
# retreives the local ec2 instance details by private ip
|
138
|
-
client = getClient("ec2")
|
169
|
+
client = getClient(service="ec2")
|
139
170
|
filters = [dict(Name="private-ip-address", Values=[ip])]
|
140
171
|
resp = client.describe_instances(Filters=filters)["Reservations"]
|
141
172
|
try:
|
metrics/rpc.py
CHANGED
@@ -287,7 +287,7 @@ def getPeriods(period, duration):
|
|
287
287
|
|
288
288
|
@rd.urlGET('restit/domains')
|
289
289
|
@rd.login_required
|
290
|
-
def rest_on_ec2_domains(request
|
290
|
+
def rest_on_ec2_domains(request):
|
291
291
|
if not settings.DOMAIN_WATCH:
|
292
292
|
return rv.restPermissionDenied(request)
|
293
293
|
|
@@ -300,7 +300,7 @@ def rest_on_ec2_domains(request, pk=None):
|
|
300
300
|
|
301
301
|
@rd.urlGET('restit/servers')
|
302
302
|
@rd.login_required
|
303
|
-
def rest_on_ec2_restit_stats(request
|
303
|
+
def rest_on_ec2_restit_stats(request):
|
304
304
|
hostname = settings.SERVER_ROOT
|
305
305
|
if hostname is None:
|
306
306
|
hostname = settings.SERVER_NAME
|
@@ -332,19 +332,19 @@ def rest_on_ec2_restit_stats(request, pk=None):
|
|
332
332
|
|
333
333
|
@rd.urlGET('aws/ec2/list/details')
|
334
334
|
@rd.login_required
|
335
|
-
def rest_on_ec2_list(request
|
335
|
+
def rest_on_ec2_list(request):
|
336
336
|
return rv.restReturn(request, dict(data=aws.getAllEC2()))
|
337
337
|
|
338
338
|
|
339
339
|
@rd.urlGET('aws/ec2/list/ids')
|
340
340
|
@rd.login_required
|
341
|
-
def rest_on_ec2_list_ids(request
|
341
|
+
def rest_on_ec2_list_ids(request):
|
342
342
|
return rv.restReturn(request, dict(data=aws.getAllEC2(True)))
|
343
343
|
|
344
344
|
|
345
345
|
@rd.urlGET('aws/ec2/cpu')
|
346
346
|
@rd.requires_params(["ids"])
|
347
|
-
def rest_on_ec2_metrics_cpu(request
|
347
|
+
def rest_on_ec2_metrics_cpu(request):
|
348
348
|
ids = request.DATA.getlist("ids")
|
349
349
|
period = request.DATA.get("period", 300, field_type=int)
|
350
350
|
duration = request.DATA.get("duration", period*8, field_type=int)
|
@@ -383,9 +383,22 @@ def rest_on_ec2_metrics_cpu(request, pk=None):
|
|
383
383
|
return rv.restReturn(request, dict(data=data))
|
384
384
|
|
385
385
|
|
386
|
+
@rd.urlGET('aws/ec2/network/established')
|
387
|
+
@rd.requires_params(["ids"])
|
388
|
+
def rest_on_ec2_metrics_net_established(request):
|
389
|
+
data = aws.getMetrics(
|
390
|
+
request.DATA.getlist("ids"),
|
391
|
+
period=request.DATA.get("period", 300, field_type=int),
|
392
|
+
duration_seconds=request.DATA.get("duration", 900, field_type=int),
|
393
|
+
metric="EstablishedConnections",
|
394
|
+
namespace="CustomMetrics",
|
395
|
+
stat="max")
|
396
|
+
return rv.restReturn(request, dict(data=data))
|
397
|
+
|
398
|
+
|
386
399
|
@rd.urlGET('aws/ec2/network/in')
|
387
400
|
@rd.requires_params(["ids"])
|
388
|
-
def rest_on_ec2_metrics_netin(request
|
401
|
+
def rest_on_ec2_metrics_netin(request):
|
389
402
|
data = aws.getMetrics(
|
390
403
|
request.DATA.getlist("ids"),
|
391
404
|
period=request.DATA.get("period", 300, field_type=int),
|
@@ -398,7 +411,7 @@ def rest_on_ec2_metrics_netin(request, pk=None):
|
|
398
411
|
|
399
412
|
@rd.urlGET('aws/ec2/network/out')
|
400
413
|
@rd.requires_params(["ids"])
|
401
|
-
def rest_on_ec2_metrics_netout(request
|
414
|
+
def rest_on_ec2_metrics_netout(request):
|
402
415
|
ids = request.DATA.getlist("ids")
|
403
416
|
period = request.DATA.get("period", 300, field_type=int)
|
404
417
|
duration = request.DATA.get("duration", period*8, field_type=int)
|
@@ -426,7 +439,7 @@ def rest_on_ec2_metrics_netout(request, pk=None):
|
|
426
439
|
|
427
440
|
@rd.urlGET('aws/rds/cpu')
|
428
441
|
@rd.requires_params(["ids"])
|
429
|
-
def rest_on_ec2_metrics_cpu(request
|
442
|
+
def rest_on_ec2_metrics_cpu(request):
|
430
443
|
ids = request.DATA.getlist("ids")
|
431
444
|
period = request.DATA.get("period", 300, field_type=int)
|
432
445
|
duration = request.DATA.get("duration", period*8, field_type=int)
|
@@ -446,7 +459,7 @@ def rest_on_ec2_metrics_cpu(request, pk=None):
|
|
446
459
|
|
447
460
|
@rd.urlGET('aws/rds/memory')
|
448
461
|
@rd.requires_params(["ids"])
|
449
|
-
def rest_on_rds_metrics_memory(request
|
462
|
+
def rest_on_rds_metrics_memory(request):
|
450
463
|
ids = request.DATA.getlist("ids")
|
451
464
|
period = request.DATA.get("period", 300, field_type=int)
|
452
465
|
duration = request.DATA.get("duration", period*8, field_type=int)
|
@@ -466,7 +479,7 @@ def rest_on_rds_metrics_memory(request, pk=None):
|
|
466
479
|
|
467
480
|
@rd.urlGET('aws/rds/cons')
|
468
481
|
@rd.requires_params(["ids"])
|
469
|
-
def rest_on_rds_metrics_cons(request
|
482
|
+
def rest_on_rds_metrics_cons(request):
|
470
483
|
ids = request.DATA.getlist("ids")
|
471
484
|
period = request.DATA.get("period", 300, field_type=int)
|
472
485
|
duration = request.DATA.get("duration", period*8, field_type=int)
|
@@ -486,19 +499,19 @@ def rest_on_rds_metrics_cons(request, pk=None):
|
|
486
499
|
|
487
500
|
@rd.urlGET('aws/redis/cpu')
|
488
501
|
@rd.requires_params(["ids"])
|
489
|
-
def rest_on_redis_metrics_cpu(request
|
502
|
+
def rest_on_redis_metrics_cpu(request):
|
490
503
|
return get_redis_metrics(request, "cpu")
|
491
504
|
|
492
505
|
|
493
506
|
@rd.urlGET('aws/redis/cons')
|
494
507
|
@rd.requires_params(["ids"])
|
495
|
-
def rest_on_redis_metrics_cons(request
|
508
|
+
def rest_on_redis_metrics_cons(request):
|
496
509
|
return get_redis_metrics(request, "cache_cons")
|
497
510
|
|
498
511
|
|
499
512
|
@rd.urlGET('aws/redis/memory')
|
500
513
|
@rd.requires_params(["ids"])
|
501
|
-
def rest_on_redis_metrics_mem(request
|
514
|
+
def rest_on_redis_metrics_mem(request):
|
502
515
|
return get_redis_metrics(request, "cache_usage")
|
503
516
|
|
504
517
|
|
rest/extra/hostinfo.py
ADDED
@@ -0,0 +1,122 @@
|
|
1
|
+
from datetime import datetime
|
2
|
+
import time
|
3
|
+
from rest import helpers
|
4
|
+
from django.conf import settings
|
5
|
+
import django
|
6
|
+
import version
|
7
|
+
import platform
|
8
|
+
import socket
|
9
|
+
|
10
|
+
|
11
|
+
try:
|
12
|
+
import psutil
|
13
|
+
except Exception:
|
14
|
+
print("no psutil")
|
15
|
+
|
16
|
+
SOFTWARE_VERSIONS = getattr(settings, 'SOFTWARE_VERSIONS', None)
|
17
|
+
|
18
|
+
|
19
|
+
def getHostIP():
|
20
|
+
hostname = socket.gethostname()
|
21
|
+
return socket.gethostbyname(hostname)
|
22
|
+
|
23
|
+
|
24
|
+
def getTcpEstablishedCount():
|
25
|
+
return len(getTcpEstablished())
|
26
|
+
|
27
|
+
|
28
|
+
def getTcpEstablished():
|
29
|
+
cons = psutil.net_connections(kind="tcp")
|
30
|
+
established = []
|
31
|
+
for c in cons:
|
32
|
+
if c.status == "ESTABLISHED":
|
33
|
+
established.append(c)
|
34
|
+
return established
|
35
|
+
|
36
|
+
|
37
|
+
def getVersions(out=None):
|
38
|
+
if out is None:
|
39
|
+
out = {}
|
40
|
+
for key in SOFTWARE_VERSIONS:
|
41
|
+
if key == "django":
|
42
|
+
out[key] = django.__version__
|
43
|
+
else:
|
44
|
+
out[key] = safe_cmd(SOFTWARE_VERSIONS[key])
|
45
|
+
return out
|
46
|
+
|
47
|
+
|
48
|
+
def getHostInfo(include_versions=False, include_blocked=False):
|
49
|
+
mem = psutil.virtual_memory()
|
50
|
+
disk = psutil.disk_usage('/')
|
51
|
+
net = psutil.net_io_counters()
|
52
|
+
|
53
|
+
out = {
|
54
|
+
"time": time.time(),
|
55
|
+
"datetime": str(datetime.now()),
|
56
|
+
"version": version.VERSION,
|
57
|
+
"os": {
|
58
|
+
"system": platform.system(),
|
59
|
+
"version": platform.version(),
|
60
|
+
"hostname": platform.node(),
|
61
|
+
"release": platform.release(),
|
62
|
+
"processor": platform.processor(),
|
63
|
+
"machine": platform.machine()
|
64
|
+
},
|
65
|
+
"boot_time": psutil.boot_time(),
|
66
|
+
"cpu_load": psutil.cpu_percent(),
|
67
|
+
"cpus_load": psutil.cpu_percent(percpu=True),
|
68
|
+
"memory": {
|
69
|
+
"total": mem.total,
|
70
|
+
"used": mem.used,
|
71
|
+
"available": mem.available,
|
72
|
+
"percent": mem.percent
|
73
|
+
},
|
74
|
+
"disk": {
|
75
|
+
"total": disk.total,
|
76
|
+
"used": disk.used,
|
77
|
+
"free": disk.free,
|
78
|
+
"percent": disk.percent
|
79
|
+
},
|
80
|
+
"users": psutil.users()
|
81
|
+
}
|
82
|
+
|
83
|
+
try:
|
84
|
+
out["cpu"] = {
|
85
|
+
"count": psutil.cpu_count(),
|
86
|
+
"freq": psutil.cpu_freq(),
|
87
|
+
}
|
88
|
+
except Exception:
|
89
|
+
pass
|
90
|
+
|
91
|
+
try:
|
92
|
+
out["network"] = {
|
93
|
+
"tcp_cons": getTcpEstablishedCount(),
|
94
|
+
"bytes_sent": net.bytes_sent,
|
95
|
+
"bytes_recv": net.bytes_recv,
|
96
|
+
"packets_sent": net.packets_sent,
|
97
|
+
"packets_recv": net.packets_recv,
|
98
|
+
"errin": net.errin,
|
99
|
+
"errout": net.errout,
|
100
|
+
"dropin": net.dropin,
|
101
|
+
"dropout": net.dropout
|
102
|
+
}
|
103
|
+
except Exception:
|
104
|
+
pass
|
105
|
+
|
106
|
+
if include_versions and SOFTWARE_VERSIONS:
|
107
|
+
out["versions"] = getVersions()
|
108
|
+
if include_blocked:
|
109
|
+
out["blocked"] = helpers.getBlockedHosts()
|
110
|
+
return out
|
111
|
+
|
112
|
+
|
113
|
+
def safe_cmd(cmd, *args):
|
114
|
+
try:
|
115
|
+
cmd_args = [cmd]
|
116
|
+
if len(args):
|
117
|
+
cmd_args.extend(list(args))
|
118
|
+
return helpers.toString(subprocess.check_output(cmd_args, shell=True).strip())
|
119
|
+
except Exception as err:
|
120
|
+
return str(err)
|
121
|
+
# print( str(err))
|
122
|
+
return None
|
rest/rpc.py
CHANGED
@@ -1,10 +1,6 @@
|
|
1
1
|
from . import views
|
2
2
|
|
3
3
|
import version
|
4
|
-
import time
|
5
|
-
from datetime import datetime
|
6
|
-
import platform
|
7
|
-
import subprocess
|
8
4
|
from . import joke
|
9
5
|
from . import helpers
|
10
6
|
|
@@ -13,33 +9,30 @@ from django.conf import settings
|
|
13
9
|
|
14
10
|
|
15
11
|
from .decorators import url
|
16
|
-
|
17
|
-
try:
|
18
|
-
import psutil
|
19
|
-
except Exception:
|
20
|
-
print("no psutil")
|
12
|
+
from rest.extra import hostinfo
|
21
13
|
|
22
14
|
|
23
15
|
URL_PREFIX = ""
|
24
16
|
|
25
17
|
SOFTWARE_VERSIONS = getattr(settings, 'SOFTWARE_VERSIONS', None)
|
26
18
|
ALLOW_PUBLIC_SYS_INFO = getattr(settings, 'ALLOW_PUBLIC_SYS_INFO', False)
|
19
|
+
SYS_INFO_KEY = getattr(settings, 'SYS_INFO_KEY', None)
|
27
20
|
# SOFTWARE_VERSIONS_ACTUAL = {}
|
28
21
|
|
29
22
|
|
30
|
-
@url(
|
23
|
+
@url('version')
|
31
24
|
def on_get_version(request):
|
32
25
|
return views.restStatus(request, True, {"data": version.VERSION, "ip": request.ip})
|
33
26
|
|
34
27
|
|
35
|
-
@url(
|
28
|
+
@url('versions')
|
36
29
|
def on_get_version(request):
|
37
30
|
from rest import __version__ as restit_version
|
38
31
|
versions = dict(
|
39
32
|
project=version.VERSION,
|
40
33
|
restit=restit_version)
|
41
34
|
if request.DATA.get("detailed") and SOFTWARE_VERSIONS:
|
42
|
-
getVersions(versions)
|
35
|
+
hostinfo.getVersions(versions)
|
43
36
|
return views.restStatus(request, True, {"data": versions})
|
44
37
|
|
45
38
|
|
@@ -51,110 +44,19 @@ def on_get_my_session(request):
|
|
51
44
|
return views.restReturn(request, dict(echo=request.session.get("echo", "not set")))
|
52
45
|
|
53
46
|
|
54
|
-
@url(
|
47
|
+
@url('joke')
|
55
48
|
def on_get_joke(request):
|
56
49
|
return views.restGet(request, {"joke": joke.getRandomJoke()})
|
57
50
|
|
58
51
|
|
59
|
-
|
60
|
-
return len(getTcpEstablished())
|
61
|
-
|
62
|
-
|
63
|
-
def getTcpEstablished():
|
64
|
-
cons = psutil.net_connections(kind="tcp")
|
65
|
-
established = []
|
66
|
-
for c in cons:
|
67
|
-
if c.status == "ESTABLISHED":
|
68
|
-
established.append(c)
|
69
|
-
return established
|
70
|
-
|
71
|
-
|
72
|
-
@url(r'^system/info$')
|
52
|
+
@url('system/info')
|
73
53
|
def on_get_system_info(request):
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
"time": time.time(),
|
82
|
-
"datetime": str(datetime.now()),
|
83
|
-
"version": version.VERSION,
|
84
|
-
"os": {
|
85
|
-
"system": platform.system(),
|
86
|
-
"version": platform.version(),
|
87
|
-
"hostname": platform.node(),
|
88
|
-
"release": platform.release(),
|
89
|
-
"processor": platform.processor(),
|
90
|
-
"machine": platform.machine()
|
91
|
-
},
|
92
|
-
"boot_time": psutil.boot_time(),
|
93
|
-
"cpu_load": psutil.cpu_percent(),
|
94
|
-
"cpus_load": psutil.cpu_percent(percpu=True),
|
95
|
-
"memory": {
|
96
|
-
"total": mem.total,
|
97
|
-
"used": mem.used,
|
98
|
-
"available": mem.available,
|
99
|
-
"percent": mem.percent
|
100
|
-
},
|
101
|
-
"disk": {
|
102
|
-
"total": disk.total,
|
103
|
-
"used": disk.used,
|
104
|
-
"free": disk.free,
|
105
|
-
"percent": disk.percent
|
106
|
-
},
|
107
|
-
"users": psutil.users()
|
108
|
-
}
|
109
|
-
|
110
|
-
try:
|
111
|
-
out["cpu"] = {
|
112
|
-
"count": psutil.cpu_count(),
|
113
|
-
"freq": psutil.cpu_freq(),
|
114
|
-
}
|
115
|
-
except Exception:
|
116
|
-
pass
|
117
|
-
|
118
|
-
try:
|
119
|
-
out["network"] = {
|
120
|
-
"tcp_cons": getTcpEstablishedCount(),
|
121
|
-
"bytes_sent": net.bytes_sent,
|
122
|
-
"bytes_recv": net.bytes_recv,
|
123
|
-
"packets_sent": net.packets_sent,
|
124
|
-
"packets_recv": net.packets_recv,
|
125
|
-
"errin": net.errin,
|
126
|
-
"errout": net.errout,
|
127
|
-
"dropin": net.dropin,
|
128
|
-
"dropout": net.dropout
|
129
|
-
}
|
130
|
-
except Exception:
|
131
|
-
pass
|
132
|
-
|
133
|
-
if request.DATA.get("versions") and SOFTWARE_VERSIONS:
|
134
|
-
out["versions"] = getVersions()
|
135
|
-
if request.DATA.get("blocked"):
|
136
|
-
out["blocked"] = helpers.getBlockedHosts()
|
54
|
+
key = request.DATA.get("key")
|
55
|
+
if SYS_INFO_KEY is None or key != SYS_INFO_KEY:
|
56
|
+
if not ALLOW_PUBLIC_SYS_INFO and not request.user.is_authenticated:
|
57
|
+
return views.restPermissionDenied(request, "system info is not public", 565)
|
58
|
+
out = hostinfo.getHostInfo(
|
59
|
+
include_versions=request.DATA.get("versions") and SOFTWARE_VERSIONS,
|
60
|
+
include_blocked=request.DATA.get("blocked"))
|
137
61
|
return views.restGet(request, out)
|
138
62
|
|
139
|
-
|
140
|
-
def safe_cmd(cmd, *args):
|
141
|
-
try:
|
142
|
-
cmd_args = [cmd]
|
143
|
-
if len(args):
|
144
|
-
cmd_args.extend(list(args))
|
145
|
-
return helpers.toString(subprocess.check_output(cmd_args, shell=True).strip())
|
146
|
-
except Exception as err:
|
147
|
-
return str(err)
|
148
|
-
# print( str(err))
|
149
|
-
return None
|
150
|
-
|
151
|
-
|
152
|
-
def getVersions(out=None):
|
153
|
-
if out is None:
|
154
|
-
out = {}
|
155
|
-
for key in SOFTWARE_VERSIONS:
|
156
|
-
if key == "django":
|
157
|
-
out[key] = django.__version__
|
158
|
-
else:
|
159
|
-
out[key] = safe_cmd(SOFTWARE_VERSIONS[key])
|
160
|
-
return out
|
taskqueue/periodic.py
CHANGED
@@ -102,3 +102,12 @@ def run_cleanup(force=False, verbose=False, now=None):
|
|
102
102
|
count = Task.objects.filter(created__lte=stale, state=TASK_STATE_COMPLETED).delete()
|
103
103
|
if count:
|
104
104
|
logger.info("deleted {} old completed tasks".format(count))
|
105
|
+
|
106
|
+
|
107
|
+
PUSH_METRICS_TO_CLOUDWATCH = settings.get("PUSH_METRICS_TO_CLOUDWATCH", False)
|
108
|
+
|
109
|
+
@rd.periodic(minute=rd.PERIODIC_EVERY_5_MINUTES)
|
110
|
+
def run_aws_metrics(force=False, verbose=False, now=None):
|
111
|
+
if PUSH_METRICS_TO_CLOUDWATCH:
|
112
|
+
from metrics.providers import aws
|
113
|
+
aws.publishLocalMetrics()
|
File without changes
|
File without changes
|