How to Clear the Swimlane Usage Metrics
Resetting the Swimlane Usage Metrics is available in the Swimlane Health & Maintenance Operations Application. However, having the following manual method to reset the data using a Python script is also helpful when troubleshooting.
Using MongoDB
Connect to the MongoDB using the mongo shell or a tool like Robo3T and run the following query:
use Swimlane;
db.UsageEntryAggregates.remove({})
Using Python Script
Description
Create the following Script Inputs in your task:
swimlane_api_pat
mongoServer
mongoPort
mongoUser # For the Swimlane database
mongoPass # For the Swimlane database
database = Swimlane
collection = UsageEntryAggregates
task = Reset Usage Metrics
NOTE: For a standalone deployment, remove line number 16 below from the code (replicaSet='rs0',)
from pymongo import MongoClient
from swimlane import Swimlane
import pendulum
import ssl
#connect to Swimlane:
swimlane = Swimlane(sw_context.config['InternalSwimlaneUrl'], access_token=sw_context.inputs['swimlane_api_pat'], verify_ssl=False)
#Connect to Mongo:
def connect_to_mongo(swimlane_auth_source):
connectionParams = MongoClient(host=sw_context.inputs['mongoServer'],
port=int(sw_context.inputs['mongoPort']),
username=sw_context.inputs['mongoUser'],
password=sw_context.inputs['mongoPass'],
authSource=swimlane_auth_source,
replicaSet='rs0',
authMechanism='SCRAM-SHA-1',
ssl=True,
ssl_cert_reqs=ssl.CERT_NONE)
return connectionParams
#Set Database & Auth to Swimlane or SwimlaneHistory from Workflow Action Set Field
swimlane_auth_source = swimlane_database = sw_context.inputs['database']
#Retrieve Collection from Workflow Action Set Field
collection_name = sw_context.inputs['collection']
try:
if swimlane_auth_source and collection_name and sw_context.inputs['task'] == 'Reset Usage Metrics':
db = connect_to_mongo(swimlane_auth_source)[swimlane_database]
collection = db[collection_name]
resetUsageMetrics = collection.delete_many({})
sw_outputs = [{'deleted_count': resetUsageMetrics.deleted_count}]
except Exception as e:
print(e)