def metrics_search_in_dashboards_and_count_migration(): dashboards = getDashboards() pattern = ".*sum\:(starbug|c2c).*\.(sum|count)\{.*" res = getMetricQueryMatchingPatternInDashboards(dashboards, pattern) msg = { "title": "Search for pattern in dashboards", "message": "Pattern {}".format(pattern) } arr = [] for key, value in res.items(): queryDetails = splitQuery(key) queryDetails["count"] = value arr.append(queryDetails) writeJSONToFile("dashboard-search.json", arr) metricCount = {} for el in arr: metrics = el.get('metrics', []) for m in metrics: metricCount[m] = metricCount.get(m, 0) + 1 newArr = [] for key, value in metricCount.items(): newArr.append({"metric": key, "count": value}) return render_template(MAIN_TEMPLATE, title=TITLE, list=newArr, message=msg)
def storeParallelOuputToFile(output, filename): store = {} if (isFileAvailable(filename)): store = readJSONFromFile(filename).get("data") for o in output: oId = o.get('id') store[oId] = o.get('output') writeJSONToFile(filename, store) return store
def _getDashboardsJSON(update=False): if (update): dashboardsJSON = api.Dashboard.get_all() print("load (dashboards)") writeJSONToFile(FILENAME, dashboardsJSON) return {"data": dashboardsJSON} else: if (isFileAvailable(FILENAME)): return readJSONFromFile(FILENAME) else: return _getDashboardsJSON(True)
def _getMonitorsJSON(update=False): if (update): monitorsJSON = api.Monitor.get_all() print("load (monitors)") print("loaded {} monitors".format(len(monitorsJSON))) writeJSONToFile(FILENAME, monitorsJSON) return {"data": monitorsJSON} else: if (isFileAvailable(FILENAME)): return readJSONFromFile(FILENAME) else: return _getMonitorsJSON(True)
def getDashboardDetails(dashboardId, update=False): # print("_getDashboardDetails: {}".format(dashboardId)) if (update): dashboardDetailsJSON = api.Dashboard.get(dashboardId) dashboardDetailsJSONStored = readJSONFromFile(FILENAME_DETAILS).get( "data") dashboardDetailsJSONStored[dashboardId] = dashboardDetailsJSON writeJSONToFile(FILENAME_DETAILS, dashboardDetailsJSONStored) return dashboardDetailsJSON else: if (isFileAvailable(FILENAME_DETAILS)): dashboardDetailsJSONStored = readJSONFromFile( FILENAME_DETAILS).get("data") if (dashboardId in dashboardDetailsJSONStored): return dashboardDetailsJSONStored[dashboardId] else: return getDashboardDetails(dashboardId, True) else: writeJSONToFile(FILENAME_DETAILS, {}) return getDashboardDetails(dashboardId, True)