From 0835932f7090e3860b0df2007b9b5e8f44969423 Mon Sep 17 00:00:00 2001 From: Becky Reamy Date: Fri, 31 May 2019 14:47:08 -0400 Subject: [PATCH] This creates a new database monitor page that can be used to see what studies have been loaded, db status, rserve status and solr status. Adding a new branch to transmart-data with updates to the Config-template.groovy to add monitor page to be visible outside of login. --- .../controllers/MonitorController.groovy | 19 +++++++ grails-app/services/MonitorService.groovy | 51 +++++++++++++++++++ .../status/RserveStatus.groovy | 12 ++++- .../status/SolrStatus.groovy | 13 +++++ 4 files changed, 93 insertions(+), 2 deletions(-) create mode 100644 grails-app/controllers/MonitorController.groovy create mode 100644 grails-app/services/MonitorService.groovy diff --git a/grails-app/controllers/MonitorController.groovy b/grails-app/controllers/MonitorController.groovy new file mode 100644 index 000000000..62120c03e --- /dev/null +++ b/grails-app/controllers/MonitorController.groovy @@ -0,0 +1,19 @@ +class MonitorController { + + def monitorService + + def index = { + def dbStatusText = "" + def otherStatusText = monitorService.otherStatusText + + try { + dbStatusText = monitorService.getDatabaseStatusText(false, "") + } catch (e) { + dbStatusText = monitorService.getDatabaseStatusText(true, e.getMessage()) + } + + render(text: dbStatusText + otherStatusText) + + } + + } diff --git a/grails-app/services/MonitorService.groovy b/grails-app/services/MonitorService.groovy new file mode 100644 index 000000000..c4965ef55 --- /dev/null +++ b/grails-app/services/MonitorService.groovy @@ -0,0 +1,51 @@ +import groovy.sql.Sql + + class MonitorService { + + def grailsApplication + def dataSource + def rserveStatusService + def solrStatusService + + def getObservationCount() { + Sql sql = new Sql(dataSource) + String sqlText = "SELECT COUNT(*) FROM i2b2demodata.observation_fact" + def result = sql.firstRow(sqlText) + return result.values()[0] + } + + def getLoadedStudies() { + Sql sql = new Sql(dataSource) + String sqlText = "SELECT c_name FROM i2b2metadata.i2b2 WHERE c_visualattributes = 'FAS'" + return sql.rows(sqlText).collect({ it.getAt(0)}).join(", ") + } + + def getAppVersion() { + return grailsApplication.metadata['app.version'] + } + + def getDatabaseStatusText(isDBError, errorMessage) { + if (!isDBError) { + return "Database Connection Status: " + "OK
" + + "Observation Count: " + observationCount + "
" + + "Loaded Studies: " + loadedStudies + "
" + + } + else { + return "Database Connection Status: " + "ERROR
" + + "Last Database Error Message: " + errorMessage + "
" + } + } + + def getOtherStatusText() { + return "App Version: " + appVersion + "

" + + "RServe Status
" + + "--------------------
" + + rserveStatusService.status.toHTMLString() + "
" + + "Solr Status
" + + "--------------------
" + + solrStatusService.status.toHTMLString() + } + + + + } diff --git a/src/groovy/org/transmartfoundation/status/RserveStatus.groovy b/src/groovy/org/transmartfoundation/status/RserveStatus.groovy index 29f93c562..f134c88e9 100644 --- a/src/groovy/org/transmartfoundation/status/RserveStatus.groovy +++ b/src/groovy/org/transmartfoundation/status/RserveStatus.groovy @@ -1,7 +1,5 @@ package org.transmartfoundation.status -import java.util.Date; - class RserveStatus { String url @@ -15,4 +13,14 @@ class RserveStatus { return "RserveStatus (" + url + ") - probe at: " + lastProbe } + String toHTMLString () { + return 'url: ' + url + "
" + + 'connected: ' + connected + "
" + + 'simpleExpressionOK: ' + simpleExpressionOK + "
" + + 'librariesOk: ' + librariesOk + "
" + + 'lastErrorMessage: ' + lastErrorMessage + "
" + + 'lastProbe: ' + lastProbe + "
" + } + + } diff --git a/src/groovy/org/transmartfoundation/status/SolrStatus.groovy b/src/groovy/org/transmartfoundation/status/SolrStatus.groovy index 965413f87..2598d1bdf 100644 --- a/src/groovy/org/transmartfoundation/status/SolrStatus.groovy +++ b/src/groovy/org/transmartfoundation/status/SolrStatus.groovy @@ -15,4 +15,17 @@ class SolrStatus { String toString () { return "SolrStatus (URL: " + url + ") - probe at: " + lastProbe } + + String toHTMLString () { + return 'url: ' + url + "
" + + 'connected: ' + connected + "
" + + 'rwgAvailable: ' + rwgAvailable + "
" + + 'rwgNumberOfRecords: ' + rwgNumberOfRecords + "
" + + 'browseAvailable: ' + browseAvailable + "
" + + 'browseNumberOfRecords: ' + browseNumberOfRecords + "
" + + 'sampleAvailable: ' + sampleAvailable + "
" + + 'sampleNumberOfRecords: ' + sampleNumberOfRecords + "
" + + 'lastProbe: ' + lastProbe + "
" + } + }