diff options
| author | Victor Näslund <victor@sunet.se> | 2022-11-13 22:28:12 +0100 |
|---|---|---|
| committer | Victor Näslund <victor@sunet.se> | 2022-11-13 22:28:12 +0100 |
| commit | dd901cd2cfc2b72b18ea0fcac0cc478b33198d2d (patch) | |
| tree | fefa4853f4a9b49655208af46e48e31edff1e538 /src/collector/healthcheck.py | |
| parent | 563607809d993c9e496423829b1f93def22a4aac (diff) | |
better mongodb handling
Diffstat (limited to 'src/collector/healthcheck.py')
| -rw-r--r-- | src/collector/healthcheck.py | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/collector/healthcheck.py b/src/collector/healthcheck.py new file mode 100644 index 0000000..7d336fd --- /dev/null +++ b/src/collector/healthcheck.py @@ -0,0 +1,38 @@ +""" +Send a healthcheck request +""" +import sys +import time +import json + +import requests + + +def check_collector() -> bool: + """Check our collector using /info + + :return: bool + """ + time.sleep(2) # Prevent race condition with redis container healthcheck + + req = requests.get( + "http://localhost:8000/info", + timeout=3, + # verify="./rootCA.crt", + ) + + if req.status_code != 200: + return False + + data = json.loads(req.text) + if isinstance(data["estimated document count"], int) and data["estimated document count"] >= 0: + return req.status_code == 200 + + return False + + +if __name__ == "__main__": + if sys.argv[1] == "COLLECTOR": + if check_collector(): + sys.exit(0) + sys.exit(1) |
