Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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