@cryptotaxi247 / netdata-1 / commits / 36114d3de

allow custom defined information on the dashboard; fixes #1936

Costa Tsaousis (ktsaou) committed Mar 13, 2017 at 23:03 UTC 36114d3debff2d233ea50f3fd54d057ad96d314b
4 files changed +132 -56
src/rrd2json.c
+7 -2
@@ -78,25 +78,30 @@ void rrd_stats_api_v1_chart(RRDSET *st, BUFFER *wb) {
78 rrd_stats_api_v1_chart_with_data(st, wb, NULL, NULL);
79 }
80
81 -void rrd_stats_api_v1_charts(RRDHOST *host, BUFFER *wb)
82 -{
81 +void rrd_stats_api_v1_charts(RRDHOST *host, BUFFER *wb) {
82 + static char *custom_dashboard_info_js_filename = NULL;
83 size_t c, dimensions = 0, memory = 0, alarms = 0;
84 RRDSET *st;
85
86 time_t now = now_realtime_sec();
87
88 + if(unlikely(!custom_dashboard_info_js_filename))
89 + custom_dashboard_info_js_filename = config_get(CONFIG_SECTION_WEB, "custom dashboard_info.js", "");
90 +
91 buffer_sprintf(wb, "{\n"
92 "\t\"hostname\": \"%s\""
93 ",\n\t\"version\": \"%s\""
94 ",\n\t\"os\": \"%s\""
95 ",\n\t\"update_every\": %d"
96 ",\n\t\"history\": %ld"
97 + ",\n\t\"custom_info\": \"%s\""
98 ",\n\t\"charts\": {"
99 , host->hostname
100 , program_version
101 , host->os
102 , host->rrd_update_every
103 , host->rrd_history_entries
104 + , custom_dashboard_info_js_filename
105 );
106
107 c = 0;
web/Makefile.am
+1
@@ -11,6 +11,7 @@ dist_web_DATA = \
11 dashboard.html \
12 dashboard.js \
13 dashboard_info.js \
14 + dashboard_info_custom_example.js \
15 dashboard.css \
16 dashboard.slate.css \
17 favicon.ico \
web/dashboard_info_custom_example.js new
+58
@@ -0,0 +1,58 @@
1 +/*
2 + * Custom netdata information file
3 + * -------------------------------
4 + *
5 + * Use this file to add custom information on netdata dashboards:
6 + *
7 + * 1. Copy it to a new filename (so that it will not be overwritten with netdata updates)
8 + * 2. Edit it to fit your needs
9 + * 3. Set the following option to /etc/netdata/netdata.conf :
10 + *
11 + * [web]
12 + * custom dashboard_info.js = your_filename.js
13 + *
14 + * Using this file you can:
15 + *
16 + * 1. Overwrite or add messages to menus, submenus and charts.
17 + * Use dashboard_info.js to find out what you can define.
18 + *
19 + * 2. Inject javascript code into the default netdata dashboard.
20 + *
21 + */
22 +
23 +// ----------------------------------------------------------------------------
24 +// MENU
25 +//
26 +// - title the menu title as to be rendered at the charts menu
27 +// - icon html fragment of the icon to display
28 +// - info html fragment for the description above all the menu charts
29 +
30 +customDashboard.menu = {
31 +
32 +};
33 +
34 +
35 +// ----------------------------------------------------------------------------
36 +// SUBMENU
37 +//
38 +// - title the submenu title as to be rendered at the charts menu
39 +// - info html fragment for the description above all the submenu charts
40 +
41 +customDashboard.submenu = {
42 +
43 +};
44 +
45 +
46 +// ----------------------------------------------------------------------------
47 +// CONTEXT (the template each chart is based on)
48 +//
49 +// - info html fragment for the description above the chart
50 +// - height a ratio to the default as a decimal number: 1.0 = 100%
51 +// - colors a single color or an array of colors to use for the dimensions
52 +// - valuerange the y-range of the chart as an array [min, max]
53 +// - heads an array of gauge charts to render above the submenu section
54 +// - mainheads an array of gauge charts to render at the menu section
55 +
56 +customDashboard.context = {
57 +
58 +};
web/index.html
+66 -54
@@ -992,6 +992,14 @@
992
993 // ----------------------------------------------------------------------------
994
995 + // user editable information
996 + var customDashboard = {
997 + menu: {},
998 + submenu: {},
999 + context: {}
1000 + };
1001 +
1002 + // netdata standard information
1003 var netdataDashboard = {
1004 sparklines_registry: {},
1005 os: 'unknown',
@@ -1163,12 +1171,16 @@
1171 chart.menu = chart.type;
1172 if(parts.length > 2 && parts[1] === 'cache')
1173 chart.menu_pattern = tmp + '_' + parts[1];
1174 + else if(parts.length > 1)
1175 + chart.menu_pattern = tmp;
1176 break;
1177
1178 case 'bind':
1179 chart.menu = chart.type;
1180 if(parts.length > 2 && parts[1] === 'rndc')
1181 chart.menu_pattern = tmp + '_' + parts[1];
1182 + else if(parts.length > 1)
1183 + chart.menu_pattern = tmp;
1184 break;
1185
1186 case 'cgroup':
@@ -1183,12 +1195,16 @@
1195 chart.menu = chart.type;
1196 if(parts.length > 2 && parts[1] === 'dhcpd')
1197 chart.menu_pattern = tmp + '_' + parts[1];
1198 + else if(parts.length > 1)
1199 + chart.menu_pattern = tmp;
1200 break;
1201
1202 case 'ovpn':
1203 chart.menu = chart.type;
1204 if(parts.length > 3 && parts[1] === 'status' && parts[2] === 'log')
1205 chart.menu_pattern = tmp + '_' + parts[1];
1206 + else if(parts.length > 1)
1207 + chart.menu_pattern = tmp;
1208 break;
1209
1210 case 'smartd':
@@ -1196,28 +1212,8 @@
1212 chart.menu = chart.type;
1213 if(parts.length > 2 && parts[1] === 'log')
1214 chart.menu_pattern = tmp + '_' + parts[1];
1199 - break;
1200 -
1201 - case 'dovecot':
1202 - case 'exim':
1203 - case 'hddtemp':
1204 - case 'ipfs':
1205 - case 'memcached':
1206 - case 'mysql':
1207 - case 'named':
1208 - case 'nginx':
1209 - case 'nut':
1210 - case 'phpfpm':
1211 - case 'postfix':
1212 - case 'postgres':
1213 - case 'redis':
1214 - case 'retroshare':
1215 - case 'smawebbox':
1216 - case 'snmp':
1217 - case 'squid':
1218 - case 'tomcat':
1219 - chart.menu = chart.type;
1220 - chart.menu_pattern = tmp;
1215 + else if(parts.length > 1)
1216 + chart.menu_pattern = tmp;
1217 break;
1218
1219 case 'tc':
@@ -1248,6 +1244,8 @@
1244
1245 default:
1246 chart.menu = chart.type;
1247 + if(parts.length > 1)
1248 + chart.menu_pattern = tmp;
1249 break;
1250 }
1251
@@ -2288,6 +2286,43 @@
2286 document.getElementById('alarms_count_badge').innerHTML = '';
2287 }
2288
2289 + function initializeDynamicDashboardWithData(data) {
2290 + if(data !== null) {
2291 + options.hostname = data.hostname;
2292 + options.data = data;
2293 + options.version = data.version;
2294 + netdataDashboard.os = data.os;
2295 +
2296 + if(typeof data.hosts != 'undefined')
2297 + options.hosts = data.hosts;
2298 +
2299 + // update the dashboard hostname
2300 + document.getElementById('hostname').innerHTML = options.hostname;
2301 + document.getElementById('hostname').href = NETDATA.serverDefault;
2302 + document.getElementById('netdataVersion').innerHTML = options.version;
2303 +
2304 + // update the dashboard title
2305 + document.title = options.hostname + ' netdata dashboard';
2306 +
2307 + // close the splash screen
2308 + $("#loadOverlay").css("display","none");
2309 +
2310 + // create a chart_by_name index
2311 + data.charts_by_name = {};
2312 + var charts = data.charts;
2313 + var x;
2314 + for(x in charts) {
2315 + if(!charts.hasOwnProperty(x)) continue;
2316 +
2317 + var chart = charts[x];
2318 + data.charts_by_name[chart.name] = chart;
2319 + }
2320 +
2321 + // render all charts
2322 + renderChartsAndMenu(data);
2323 + }
2324 + }
2325 +
2326 function initializeDynamicDashboard(netdata_url) {
2327 if(typeof netdata_url === 'undefined' || netdata_url === null)
2328 netdata_url = NETDATA.serverDefault;
@@ -2302,39 +2337,16 @@
2337
2338 // download all the charts the server knows
2339 NETDATA.chartRegistry.downloadAll(netdata_url, function(data) {
2305 - if(data !== null) {
2306 - options.hostname = data.hostname;
2307 - options.data = data;
2308 - options.version = data.version;
2309 - netdataDashboard.os = data.os;
2310 -
2311 - if(typeof data.hosts != 'undefined')
2312 - options.hosts = data.hosts;
2313 -
2314 - // update the dashboard hostname
2315 - document.getElementById('hostname').innerHTML = options.hostname;
2316 - document.getElementById('hostname').href = NETDATA.serverDefault;
2317 - document.getElementById('netdataVersion').innerHTML = options.version;
2318 -
2319 - // update the dashboard title
2320 - document.title = options.hostname + ' netdata dashboard';
2321 -
2322 - // close the splash screen
2323 - $("#loadOverlay").css("display","none");
2324 -
2325 - // create a chart_by_name index
2326 - data.charts_by_name = {};
2327 - var charts = data.charts;
2328 - var x;
2329 - for(x in charts) {
2330 - if(!charts.hasOwnProperty(x)) continue;
2331 -
2332 - var chart = charts[x];
2333 - data.charts_by_name[chart.name] = chart;
2340 + if(data != null) {
2341 + if(typeof data.custom_info !== 'undefined' && data.custom_info !== "") {
2342 + loadJs(data.custom_info, function () {
2343 + $.extend(true, netdataDashboard, customDashboard);
2344 + initializeDynamicDashboardWithData(data);
2345 + });
2346 + }
2347 + else {
2348 + initializeDynamicDashboardWithData(data);
2349 }
2335 -
2336 - // render all charts
2337 - renderChartsAndMenu(data);
2350 }
2351 });
2352 });