Skip to content

Commit d4f9c7f

Browse files
committed
fix (MonitoringDB): make a MonitoringDB singleton
1 parent 1c418b4 commit d4f9c7f

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

src/DIRAC/MonitoringSystem/Client/ServerUtils.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
It always try to insert the records directly. In case of failure the monitoring client is used...
44
"""
55

6-
from DIRAC.Core.Utilities.ServerUtils import getDBOrClient
6+
from DIRAC.Core.Base.Client import Client
7+
from DIRAC.MonitoringSystem.DB.MonitoringDB import gMonitoringDB
78

89

910
def getMonitoringDB():
10-
serverName = "Monitoring/Monitoring"
11-
MonitoringDB = None
1211
try:
13-
from DIRAC.MonitoringSystem.DB.MonitoringDB import MonitoringDB
12+
if gMonitoringDB and gMonitoringDB._connected:
13+
return gMonitoringDB
1414
except Exception:
1515
pass
16-
return getDBOrClient(MonitoringDB, serverName)
16+
return Client(url="Monitoring/Monitoring")

src/DIRAC/MonitoringSystem/DB/MonitoringDB.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ def __init__(self, name="Monitoring/MonitoringDB", readOnly=False):
4949
try:
5050
section = getDatabaseSection("Monitoring/MonitoringDB")
5151
indexPrefix = gConfig.getValue(f"{section}/IndexPrefix", CSGlobals.getSetup()).lower()
52-
5352
# Connecting to the ES cluster
5453
super().__init__(dbname=name.split("/")[1], fullName=name, indexPrefix=indexPrefix)
5554
except RuntimeError as ex:
@@ -532,3 +531,9 @@ def getDataForAGivenPeriod(self, typeName, condDict, initialDate="", endDate="")
532531
condDict["endTime"] = calendar.timegm(time.gmtime()) * 1000
533532

534533
return self.__getRawData(typeName, condDict)
534+
535+
536+
try:
537+
gMonitoringDB = MonitoringDB()
538+
except:
539+
gMonitoringDB = None

0 commit comments

Comments
 (0)