import subprocess import json import time import csv from datetime import datetime import argparse import base64 # Parse command-line arguments for data logging parameters parser = argparse.ArgumentParser(description='Parameters for data logging') parser.add_argument('-mj', '--maxjobs', type=int, required=True, help="Max Jobs parameter value") parser.add_argument('-c', '--churn', type=int, required=True, help="Churn parameter value") parser.add_argument('-i', '--interval', type=int, required=True, help="Interval parameter value") parser.add_argument('-u', '--username', type=str, required=True, help="Username for authentication") parser.add_argument('-p', '--password', type=str, required=True, help="Password for authentication") parser.add_argument('-db', '--filterByDatabase', type=str, required=False, help="Filter by specific database ID (optional)") parser.add_argument('-s', '--serverURL', type=str, default="http://localhost:5984/", help="Server URL (optional, default is http://localhost:5984/)") args = parser.parse_args() # Encode the username and password into base64 authentication_token = base64.b64encode(f"{args.username}:{args.password}".encode()).decode() # Send a curl request to get scheduler data from CouchDB cmd = ["curl", "--location", f'{args.serverURL}_scheduler/docs', "--header", f'Authorization: Basic {authentication_token}'] while True: result = subprocess.run(cmd, stdout=subprocess.PIPE) data = json.loads(result.stdout) with open('output.csv', 'a', newline='') as f: writer = csv.writer(f) for doc in data['docs']: doc_id = doc['doc_id'] if args.filterByDatabase: if doc_id != args.filterByDatabase: continue else: print("doc_id is", doc_id) docs_written = doc['info']['docs_written'] start_time = datetime.strptime(doc['start_time'], "%Y-%m-%dT%H:%M:%SZ") time_elapsed = -(datetime.now() - start_time).total_seconds() speed = docs_written/time_elapsed # Log the speed of document processing print("Speed is", speed, "documents per second") writer.writerow([datetime.now(), doc_id, docs_written, speed, args.maxjobs, args.churn, args.interval]) # Adjust time between iterations here time.sleep(15)