21121: Specify prometheus auth with a file
authorPeter Amstutz <peter.amstutz@curii.com>
Tue, 26 Mar 2024 20:56:15 +0000 (16:56 -0400)
committerPeter Amstutz <peter.amstutz@curii.com>
Tue, 26 Mar 2024 20:56:15 +0000 (16:56 -0400)
Arvados-DCO-1.1-Signed-off-by: Peter Amstutz <peter.amstutz@curii.com>

tools/cluster-activity/arvados_cluster_activity/main.py

index 5447f74904fcb787b15c65cf0d4a06b2cfa5ff7b..299f4796f5fec90600198ac3c29994aba5473a15 100755 (executable)
@@ -22,8 +22,10 @@ def parse_arguments(arguments):
     arg_parser.add_argument('--start', help='Start date for the report in YYYY-MM-DD format (UTC)')
     arg_parser.add_argument('--end', help='End date for the report in YYYY-MM-DD format (UTC), default "now"')
     arg_parser.add_argument('--days', type=int, help='Number of days before "end" to start the report')
-    arg_parser.add_argument('--cluster', type=str, help='Cluster to query')
     arg_parser.add_argument('--cost-report-file', type=str, help='Export cost report to specified CSV file')
+    arg_parser.add_argument('--cluster', type=str, help='Cluster to query for prometheus stats')
+    arg_parser.add_argument('--prometheus-auth', type=str, help='Authorization file with prometheus info')
+
     args = arg_parser.parse_args(arguments)
 
     if args.days and args.start:
@@ -63,6 +65,13 @@ def parse_arguments(arguments):
             exit(1)
 
 
+    if args.prometheus_auth:
+        with open(args.prometheus_auth, "rt") as f:
+            for line in f:
+                sp = line.split("=")
+                if sp[0].startswith("PROMETHEUS_"):
+                    os.environ[sp[0]] = sp[1]
+
     return args, since, to
 
 def data_usage(prom, timestamp, cluster, label):
@@ -275,7 +284,7 @@ def main(arguments=None):
 
     args, since, to = parse_arguments(arguments)
 
-    if "PROMETHEUS_HOST" in os.environ:
+    if "PROMETHEUS_HOST" in os.environ and args.cluster:
         report_from_prometheus(args.cluster, since, to)
 
     if args.cost_report_file: