9
9
"""
10
10
import datetime
11
11
12
- from DIRAC import S_ERROR , S_OK
12
+ from DIRAC import S_ERROR , S_OK , gConfig
13
13
from DIRAC .AccountingSystem .Client .DataStoreClient import DataStoreClient
14
14
from DIRAC .AccountingSystem .Client .Types .WMSHistory import WMSHistory
15
15
from DIRAC .ConfigurationSystem .Client .Helpers .Operations import Operations
16
+ from DIRAC .ConfigurationSystem .Client .Helpers .Resources import getSites
16
17
from DIRAC .Core .Base .AgentModule import AgentModule
17
18
from DIRAC .Core .Utilities import TimeUtilities
18
19
from DIRAC .MonitoringSystem .Client .MonitoringReporter import MonitoringReporter
@@ -77,6 +78,8 @@ def initialize(self):
77
78
def execute (self ):
78
79
"""Main execution method"""
79
80
81
+ site_metadata = self ._getSitesMetadata ()
82
+
80
83
# on the first iteration of the agent, do nothing in order to avoid double committing after a restart
81
84
if self .am_getModuleParam ("cyclesDone" ) == 0 :
82
85
self .log .notice ("Skipping the first iteration of the agent" )
@@ -131,6 +134,9 @@ def execute(self):
131
134
132
135
for backend in self .datastores :
133
136
if backend .lower () == "monitoring" :
137
+ site_name = rD ["Site" ]
138
+ rD ["Tier" ] = site_metadata [site_name ]["Tier" ]
139
+ rD ["Type" ] = site_metadata [site_name ]["Type" ]
134
140
rD ["timestamp" ] = int (TimeUtilities .toEpochMilliSeconds (now ))
135
141
self .datastores ["Monitoring" ].addRecord (rD )
136
142
@@ -154,3 +160,30 @@ def execute(self):
154
160
self .log .verbose (f"Done committing WMSHistory to { backend } backend" )
155
161
156
162
return S_OK ()
163
+
164
+ def _getSitesMetadata (self ):
165
+ """Get the metadata for the sites"""
166
+ res = getSites ()
167
+ if not res ["OK" ]:
168
+ return res
169
+ sites = res ["Value" ]
170
+ site_metadata = {}
171
+
172
+ for site in sites :
173
+ site_metadata [site ] = {}
174
+
175
+ # Get the site metadata from the Configuration System
176
+ grid = site .split ("." )[0 ]
177
+ res = gConfig .getOptionsDict (f"Resources/Sites/{ grid } /{ site } " )
178
+ if not res ["OK" ]:
179
+ self .log .error ("Failure getting options dict for site" , f"{ site } : { res ['Message' ]} " )
180
+ continue
181
+ siteInfoCS = res ["Value" ]
182
+
183
+ # The site tier is normally 1 or 2. Few VOs may define tier 3.
184
+ # If the tier is not defined, we assume it is 4, with 4 meaning "not pledged" (opportunistic).
185
+ site_metadata [site ]["Tier" ] = siteInfoCS .get ("MoUTierLevel" , "4" )
186
+ # The site type is defined by the first part of the site name.
187
+ # It needs to be interpreted at the Monitoring side (e.g. in Grafana).
188
+ site_metadata [site ]["Type" ] = site .split ("." )[0 ]
189
+ return site_metadata
0 commit comments