MonitoringDB
Wrapper on top of ElasticDB. It is used to manage the DIRAC monitoring types.
Configuration Parameters:
The following option can be set in Systems/Monitoring/<Setup>/Databases/MonitoringDB
- IndexPrefix: Prefix used to prepend to indexes created in the ES instance. If this
is not present in the CS, the indexes are prefixed with the setup name.
For each monitoring types managed, the Period (how often a new index is created) can be defined with:
MonitoringTypes
{
RMSMonitoring
{
# Indexing strategy. Possible values: day, week, month, year, null
Period = month
}
WMSHistory
{
# Indexing strategy. Possible values: day, week, month, year, null
Period = day
}
}
- class DIRAC.MonitoringSystem.DB.MonitoringDB.MonitoringDB(name='Monitoring/MonitoringDB', readOnly=False)
Bases:
DIRAC.Core.Base.ElasticDB.ElasticDB
Extension of ElasticDB for Monitoring system DB
- RESULT_SIZE = 10000
- __init__(name='Monitoring/MonitoringDB', readOnly=False)
Standard constructor
- bulk_index(indexPrefix, data=None, mapping=None, period='day', withTimeStamp=True)
- Parameters
- Returns
S_OK/S_ERROR
- clusterName = ''
- createIndex(indexPrefix, mapping=None, period='day')
- deleteByQuery(indexName, query)
Delete data by query (careful!)
- deleteDoc(index: str, id: str)
Deletes a document in an index.
- Parameters
index – name of the index
id – document ID
- existingIndex(indexName)
Checks the existance of an index, by its name
- Parameters
indexName (str) – the name of the index
- Returns
S_OK/S_ERROR if the request is successful
- existsDoc(index: str, id: str) bool
Returns information about whether a document exists in an index.
- Parameters
index – name of the index
id – document ID
- static generateFullIndexName(indexName, period)
Given an index prefix we create the actual index name.
- getCSOption(optionName, defaultValue=None)
- getDataForAGivenPeriod(typeName, condDict, initialDate='', endDate='')
Retrieves the history of logging entries for the given component during a given given time period
- Parameters
typeName (str) – name of the monitoring type
condDict (dict) –
conditions for the query
key -> name of the field
value -> list of possible values
initialDate (str) – Indicates the start of the time period in the format ‘DD/MM/YYYY hh:mm’
endDate (str) – Indicate the end of the time period in the format ‘DD/MM/YYYY hh:mm’
- Returns
Entries from the database for the given component recorded between the initial and the end dates
- getDoc(index: str, id: str) dict
Retrieves a document in an index.
- Parameters
index – name of the index
id – document ID
- getDocTypes(indexName)
Returns mappings, by index.
- Parameters
indexName (str) – is the name of the index…
- Returns
S_OK or S_ERROR
- getIndexPrefix()
It returns the DIRAC setup.
- getIndexes(indexName=None)
It returns the available indexes…
- getKeyValues(monitoringType)
Get all values for a given key field in a type
- getLastDayData(typeName, condDict)
It returns the last day data for a given monitoring type.
- Returns
for example
{'sort': [{'timestamp': {'order': 'desc'}}], 'query': {'bool': {'must': [{'match': {'host': 'dzmathe.cern.ch'}}, {'match': {'component': 'Bookkeeping_BookkeepingManager'}}]}}}
- Parameters
- getLimitedData(typeName, condDict, size=10)
Returns a list of records for a given selection.
- Parameters
- Returns
Up to size entries for the given component from the database
- getMapping(monitoringType)
It returns the mapping of a certain monitoring type
- Parameters
monitoringType (str) – the monitoring type for example WMSHistory
- Returns
an empty dictionary if there is no mapping defenied.
- getUniqueValue(indexName, key, orderBy=False)
- index(indexName, body=None, docID=None, op_type='index')
- pingDB()
Try to connect to the database
- Returns
S_OK(TRUE/FALSE)
- put(records, monitoringType)
It is used to insert the data to ES. Calls bulk_index()
- query(index, query)
Executes a query and returns its result (uses ES DSL language).
- retrieveAggregatedData(typeName, startTime, endTime, interval, selectField, condDict, grouping, metainfo={})
Get data from the DB using simple aggregations. Note: this method is equivalent to retrieveBucketedData. The difference is in the dynamic bucketing. We do not perform dynamic bucketing on the raw data.
- Parameters
typeName (str) – name of the monitoring type
startTime (int) – start time, expressed as epoch
endtime (int) – end time, expressed as epoch
interval (str) – interval expressed in ES notation
selectField (str) – the field on which we are aggregating (the plot type)
condDict (dict) – optional additional conditions for the query
grouping (str) – what we are grouping on
metainfo (dict) – meta information
- Returns
S_OK/S_ERROR with dictionary of key/value pairs
- retrieveBucketedData(typeName, startTime, endTime, interval, selectField, condDict, grouping, metainfo=None)
Get bucketed data from the DB. This is the standard method used.
- Parameters
typeName (str) – name of the monitoring type
startTime (int) – start time, expressed as epoch
endtime (int) – end time, expressed as epoch
interval (str) – interval expressed in ES notation
selectField (str) – the field on which we are aggregating (the plot type)
condDict (dict) – optional additional conditions for the query
grouping (str) – what we are grouping on
metainfo (dict) – meta information
- Returns
S_OK/S_ERROR with dictionary of key/value pairs
- update(index, query=None, updateByQuery=True, id=None)
Executes an update of a document, and returns S_OK/S_ERROR