diff --git a/build.js b/build.js index dfc4f22..fda9090 100644 --- a/build.js +++ b/build.js @@ -21,6 +21,20 @@ if (!fs.existsSync(dir)){ const dashboards = ['General', 'Metrics', 'Summary']; +var summaryList = []; for (const dashboard of dashboards) { - builder.build(dashboard, options); + var summary = builder.build(dashboard, options); + summaryList.push(summary); +} + +console.log(""); +console.log("SUMMARY"); +console.log(""); +console.log("dashboards: " + summaryList.length); +console.log(""); +for (const summary of summaryList) { + console.log("dashboard: " + summary.name); + console.log("panels: " + summary.panels); + console.log("path: " + summary.path); + console.log(""); } diff --git a/lib/DashboardBuilder.js b/lib/DashboardBuilder.js index dd61f8e..80b25f3 100644 --- a/lib/DashboardBuilder.js +++ b/lib/DashboardBuilder.js @@ -18,17 +18,23 @@ class DashboardBuilder { const dashboardDefinition = this.loadDashboardDefinition(dashboardName); this.addTitle(result, dashboardDefinition); this.addFilters(result, dashboardDefinition, options); - this.addPanels(result, dashboardDefinition, options); - - this.writeDashboard(dashboardName, result); + this.addPanels(result, dashboardDefinition, options, dashboardName); + + const path = `./build/dashboards/${dashboardName}.json`; + this.writeDashboard(path, result); + return { + "name": dashboardName, + "panels": result.panels.length, + "path": path + } } loadDashboardDefinition(dashboardName) { return this.loadJSON(rootPath + `/dashboards/defs/${dashboardName}.json`); } - writeDashboard(dashboardName, result) { - this.writeJSON(`./build/dashboards/${dashboardName}.json`, result); + writeDashboard(path, result) { + this.writeJSON(path, result); } addTitle(result, dashboardDefinition) { @@ -40,8 +46,8 @@ class DashboardBuilder { result['templating']['list'] = this.buildFilters(dashboardDefinition["filters"], options); } - addPanels(result, dashboardDefinition, options) { - result["panels"] = this.buildPanels(dashboardDefinition["rows"], options); + addPanels(result, dashboardDefinition, options, dashboardName) { + result["panels"] = this.buildPanels(dashboardDefinition["rows"], options, dashboardName); } buildFilters(filters, options) { @@ -56,9 +62,10 @@ class DashboardBuilder { return result; } - buildPanels(rows, options) { + buildPanels(rows, options, dashboardName) { let result = []; + console.log("") let currentY = 0; let currentID = 1; for(const row of rows) { @@ -79,6 +86,7 @@ class DashboardBuilder { const panelHeight = this.makePanelHeight(builder, column); this.updatePanel(panel, column, currentID, panelX, panelY, panelWidth, panelHeight); + console.log(dashboardName + ": add panel " + panel.title) result.push(panel); currentID++;