Add heartbeat frequency setting

This commit is contained in:
R. Miles McCain 2020-04-24 13:22:22 -04:00
parent 9881dedac0
commit 3f7aaa8f0d
No known key found for this signature in database
GPG Key ID: 24F9B6A2588C5408
5 changed files with 30 additions and 4 deletions

View File

@ -74,6 +74,14 @@ SERVER_EMAIL=Shynet <noreply@shynet.example.com>
REDIS_CACHE_LOCATION=redis://redis.default.svc.cluster.local/0 REDIS_CACHE_LOCATION=redis://redis.default.svc.cluster.local/0
# If set, make sure CELERY_TASK_ALWAYS_EAGER is False # If set, make sure CELERY_TASK_ALWAYS_EAGER is False
CELERY_BROKER_URL=redis://redis.default.svc.cluster.local/1 CELERY_BROKER_URL=redis://redis.default.svc.cluster.local/1
# Other Shynet settings
# How frequently should the monitoring script "phone home" (in ms)?
SCRIPT_HEARTBEAT_FREQUENCY=5000
# Should only superusers (admins) be able to create services? This is helpful
# when you'd like to invite others to your Shynet instance but don't want
# them to be able to create services of their own.
ONLY_SUPERUSERS_CREATE=False
``` ```
4. Setup the Shynet database by running `docker run --env-file=<your env file> milesmcc/shynet:latest python manage.py migrate`. 4. Setup the Shynet database by running `docker run --env-file=<your env file> milesmcc/shynet:latest python manage.py migrate`.
@ -162,6 +170,15 @@ SERVER_EMAIL=Shynet <noreply@shynet.example.com>
REDIS_CACHE_LOCATION=redis://redis.default.svc.cluster.local/0 REDIS_CACHE_LOCATION=redis://redis.default.svc.cluster.local/0
# If set, make sure CELERY_TASK_ALWAYS_EAGER is False # If set, make sure CELERY_TASK_ALWAYS_EAGER is False
CELERY_BROKER_URL=redis://redis.default.svc.cluster.local/1 CELERY_BROKER_URL=redis://redis.default.svc.cluster.local/1
# Other Shynet settings
# How frequently should the monitoring script "phone home" (in ms)?
SCRIPT_HEARTBEAT_FREQUENCY=5000
# Should only superusers (admins) be able to create services? This is helpful
# when you'd like to invite others to your Shynet instance but don't want
# them to be able to create services of their own.
ONLY_SUPERUSERS_CREATE=False
``` ```
9. Setup the Shynet database by running `docker run --env-file=<your env file> milesmcc/shynet:latest-ssl python manage.py migrate`. 9. Setup the Shynet database by running `docker run --env-file=<your env file> milesmcc/shynet:latest-ssl python manage.py migrate`.

View File

@ -23,6 +23,6 @@ window.onload = function () {
); );
} catch {} } catch {}
} }
setInterval(sendUpdate, 5000); setInterval(sendUpdate, Number("{{heartbeat_frequency}}"));
sendUpdate(); sendUpdate();
}; };

View File

@ -82,10 +82,15 @@ class ScriptView(View):
}, },
) )
) )
heartbeat_frequency = settings.SCRIPT_HEARTBEAT_FREQUENCY
return render( return render(
self.request, self.request,
"analytics/scripts/page.js", "analytics/scripts/page.js",
context={"endpoint": endpoint, "protocol": protocol}, context={
"endpoint": endpoint,
"protocol": protocol,
"heartbeat_frequency": heartbeat_frequency,
},
content_type="application/javascript", content_type="application/javascript",
) )

View File

@ -256,3 +256,7 @@ ONLY_SUPERUSERS_CREATE = os.getenv("ONLY_SUPERUSERS_CREATE", "True") == "True"
# Should the script use HTTPS to send the POST requests? The hostname is from # Should the script use HTTPS to send the POST requests? The hostname is from
# the django SITE default. (Edit it using the admin panel.) # the django SITE default. (Edit it using the admin panel.)
SCRIPT_USE_HTTPS = os.getenv("SCRIPT_USE_HTTPS", "True") == "True" SCRIPT_USE_HTTPS = os.getenv("SCRIPT_USE_HTTPS", "True") == "True"
# How frequently should the tracking script "phone home" with a heartbeat, in
# milliseconds?
SCRIPT_HEARTBEAT_FREQUENCY = int(os.getenv("SCRIPT_HEARTBEAT_FREQUENCY", "5000"))

View File

@ -7,8 +7,8 @@
</head> </head>
<body> <body>
<noscript><img src="//localhost:8000/ingress/211410e6-b401-4fe8-8740-7926368590be/pixel.gif"></noscript> <noscript><img src="//localhost:8000/ingress/test_uuid/pixel.gif"></noscript>
<script src="//localhost:8000/ingress/211410e6-b401-4fe8-8740-7926368590be/script.js"></script> <script src="//localhost:8000/ingress/test_uuid/script.js"></script>
</body> </body>
</html> </html>