This is an automated email from the ASF dual-hosted git repository.
nchung pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-sdap-nexus.git
The following commit(s) were added to refs/heads/master by this push:
new e433bae RMQ monitor script for use in quickstart guide (#205)
e433bae is described below
commit e433baee668cce5d5ff093976af799625b761277
Author: Riley Kuttruff <[email protected]>
AuthorDate: Wed Oct 12 12:59:57 2022 -0700
RMQ monitor script for use in quickstart guide (#205)
* Added RMQ monitor script to repo
* Added arguments for RMQ username & pw
Co-authored-by: rileykk <[email protected]>
---
CHANGELOG.md | 1 +
tools/rmqmonitor/README.md | 13 +++++++++++
tools/rmqmonitor/monitor.py | 54 +++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 68 insertions(+)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 53da7c8..7f7462f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -20,6 +20,7 @@ and this project adheres to [Semantic
Versioning](https://semver.org/spec/v2.0.0
- Added markdown table to matchup `platform` param in openapi spec
- SDAP-400: Added NCAR insitu api to matchup
- SDAP-405: Added SPURS AWS insitu api to matchup and new platform values to
OpenAPI matchup spec
+- RabbitMQ monitor script used in Docker quickstart guide
### Changed
- SDAP-390: Changed `/doms` to `/cdms` and `doms_reader.py` to `cdms_reader.py`
- domslist endpoint points to AWS insitu instead of doms insitu
diff --git a/tools/rmqmonitor/README.md b/tools/rmqmonitor/README.md
new file mode 100644
index 0000000..c84501c
--- /dev/null
+++ b/tools/rmqmonitor/README.md
@@ -0,0 +1,13 @@
+# RMQ Monitor
+
+A simple script to monitor the RabbitMQ message queue used by the SDAP
ingester.
+
+## To run
+
+You first need to install the Python requests package
+
+`pip install requests`
+
+To run:
+
+`python monitor.py`
\ No newline at end of file
diff --git a/tools/rmqmonitor/monitor.py b/tools/rmqmonitor/monitor.py
new file mode 100644
index 0000000..6d5ddc8
--- /dev/null
+++ b/tools/rmqmonitor/monitor.py
@@ -0,0 +1,54 @@
+
+import argparse
+import sys
+import time
+
+import requests
+from requests.auth import HTTPBasicAuth
+
+parser = argparse.ArgumentParser()
+
+parser.add_argument('--username', action='store', default='user',
help='RabbitMQ username')
+parser.add_argument('--password', action='store', default='bitnami',
help='RabbitMQ password')
+
+args = vars(parser.parse_args())
+
+auth = HTTPBasicAuth(args['username'], args['password'])
+
+waiting = True
+
+req_number = 0
+
+print()
+
+
+def delete_last_line():
+ sys.stdout.write('\x1b[1A')
+ sys.stdout.write('\x1b[2K')
+
+
+while True:
+ try:
+ req_number += 1
+
+ response = requests.get("http://localhost:15672/api/queues/%2f/nexus",
auth=auth)
+
+ if response.ok:
+ data = response.json()
+
+ delete_last_line()
+ print(f"{data['messages_unacknowledged']} in progress,
{data['messages_ready']} waiting.", end='\n', flush=True)
+
+ if data['messages_unacknowledged'] == 0 and data['messages_ready']
== 0 and not waiting:
+ print()
+ break
+ elif data['messages_unacknowledged'] > 0 or data['messages_ready']
> 0:
+ waiting = False
+ else:
+ delete_last_line()
+ print(f"RMQ request {req_number} failed: {response.status_code}",
end='\n', flush=True)
+ except Exception as err:
+ delete_last_line()
+ print(f"An exception occurred: Request {req_number}, error:
{type(err)=}", end='\n', flush=True)
+
+ time.sleep(5)