Skip to content

Commit

Permalink
Fix #8661 changing local account usage to tape recall usage in quota …
Browse files Browse the repository at this point in the history
…report (#8697)

* Fix #8661 changing local account usage to tape recall usage in quota report

* fix #8661 fixing pylint warnings and removing a comment
  • Loading branch information
aspiringmind-code authored Sep 17, 2024
1 parent ce559a1 commit b3b26db
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 18 deletions.
12 changes: 7 additions & 5 deletions src/python/RucioUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,15 @@ def getRuleQuota(rucioClient=None, ruleId=None):
size = sum(file['bytes'] for file in files)
return size


def getTapeRecallUsage(rucioClient=None, account=None):
""" size of ongoing tape recalls for this account """
""" size of ongoing tape recalls for this account (if provided) or by activity """
activity = 'Analysis TapeRecall'
rucioAccount = account
rules = rucioClient.list_replication_rules(
filters={'account': rucioAccount, 'activity': activity})
filters = {'activity': activity}

if account is not None:
filters['account'] = account

rules = rucioClient.list_replication_rules(filters=filters)
usage = sum(getRuleQuota(rucioClient, rule['id']) for rule in rules\
if rule['state'] in ['REPLICATING', 'STUCK', 'SUSPENDED']) # in Bytes
return usage
19 changes: 6 additions & 13 deletions src/script/Monitor/ReportRecallQuota.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import requests
from requests.auth import HTTPBasicAuth
from python.RucioUtils import getTapeRecallUsage

FMT = "%Y-%m-%dT%H:%M:%S%z"
WORKDIR = '/data/srv/monit/'
Expand All @@ -21,26 +22,18 @@ def readpwd():
"""
Reads password from disk
"""
with open(f"/data/certs/monit.d/MONIT-CRAB.json", encoding='utf-8') as f:
with open("/data/certs/monit.d/MONIT-CRAB.json", encoding='utf-8') as f:
credentials = json.load(f)
return credentials["url"], credentials["username"], credentials["password"]
MONITURL, MONITUSER, MONITPWD = readpwd()

def createQuotaReport(rucioClient=None, account=None):
"""
create a dictionary with the quota report to be sent to MONIT
even if we do not report usage at single RSE's now, let's collect that info as well
returns {'rse1':bytes, 'rse':bytes,..., 'totalTB':TBypte}
returns {'totalTB':TBypte}
"""

usageGenerator = rucioClient.get_local_account_usage(account=account)
totalBytes = 0
totalBytes = getTapeRecallUsage(rucioClient=rucioClient,account=None)
report = {}
for usage in usageGenerator:
rse = usage['rse']
used = usage['bytes']
report[rse] = used // 1e12
totalBytes += used
totalTB = totalBytes // 1e12
report['totalTB'] = totalTB
return report
Expand Down Expand Up @@ -74,13 +67,13 @@ def send_and_check(document, should_fail=False):
assert ((response.status_code in [200]) != should_fail), \
msg

def main(logger):
def main(log):
from rucio.client import Client
rucioClient = Client(
creds={"client_cert": "/data/certs/robotcert.pem", "client_key": "/data/certs/robotkey.pem"},
auth_type='x509',
)
logger.info("rucio client initialized: %s %s", rucioClient.ping(), rucioClient.whoami() )
log.info("rucio client initialized: %s %s", rucioClient.ping(), rucioClient.whoami() )

# prepare a JSON to be sent to MONIT
jsonDoc = {'producer': MONITUSER, 'type': 'reportrecallquota', 'hostname': gethostname()}
Expand Down

0 comments on commit b3b26db

Please sign in to comment.