예제 #1
0
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)
예제 #2
0
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
예제 #3
0
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)
예제 #4
0
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)
예제 #5
0
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)