]> arthur.barton.de Git - netdata.git/commitdiff
Merge pull request #1939 from ktsaou/master
authorCosta Tsaousis <costa@tsaousis.gr>
Mon, 13 Mar 2017 23:37:22 +0000 (01:37 +0200)
committerGitHub <noreply@github.com>
Mon, 13 Mar 2017 23:37:22 +0000 (01:37 +0200)
allow custom defined information on the dashboard

.gitignore
python.d/cpufreq.chart.py
src/main.c
src/rrd.h
src/rrd2json.c
src/rrd2json_api_old.c
src/rrdhost.c
src/rrdpush.c
web/Makefile.am
web/dashboard_info_custom_example.js [new file with mode: 0644]
web/index.html

index 16f0e89796ac61689f7108b022896fddc9299d4b..0169e931658a55d00642570ae8ce02ad1d4029b7 100644 (file)
@@ -25,6 +25,7 @@ stamp-h1
 
 netdata
 apps.plugin
+freeipmi.plugin
 netdata.spec
 
 *.tar.*
index c761aae88a336cb02048725848071bbfa84c2c8b..e28bdea8f6abeba09752edda468075cebca779d4 100644 (file)
@@ -62,6 +62,7 @@ class Service(SimpleService):
                 return data
             else:
                 self.alert("accurate method failed, falling back")
+                self.accurate_exists = False
 
 
         for name, paths in self.assignment.items():
index 20722a58f0cd60d8362de62499c9420f589ad2cd..a72585e28377a1157bcae85459bc73176b14d8d3 100644 (file)
@@ -366,7 +366,10 @@ static void backwards_compatible_config() {
         web_server_mode = (mode)?WEB_SERVER_MODE_MULTI_THREADED:WEB_SERVER_MODE_SINGLE_THREADED;
     }
 
-    // move [global] options to the [api] section
+    // move [global] options to the [web] section
+    config_move(CONFIG_SECTION_GLOBAL, "http port listen backlog",
+                CONFIG_SECTION_WEB,    "listen backlog");
+
     config_move(CONFIG_SECTION_GLOBAL, "bind socket to IP",
                 CONFIG_SECTION_WEB,    "bind to");
 
@@ -412,7 +415,7 @@ static void get_netdata_configured_variables() {
 
     char buf[HOSTNAME_MAX + 1];
     if(gethostname(buf, HOSTNAME_MAX) == -1)
-        error("WARNING: Cannot get machine hostname.");
+        error("Cannot get machine hostname.");
 
     netdata_configured_hostname = config_get(CONFIG_SECTION_GLOBAL, "hostname", buf);
     debug(D_OPTIONS, "hostname set to '%s'", netdata_configured_hostname);
index 7843c80381e3c4fa10ae429f0ce8dda3fc777ac3..2f4f2127fffb202b7b94510770d2bbc250fd536e 100644 (file)
--- a/src/rrd.h
+++ b/src/rrd.h
@@ -376,7 +376,7 @@ struct rrdhost {
     uint32_t flags;                                 // flags about this RRDHOST
 
     int rrd_update_every;                           // the update frequency of the host
-    int rrd_history_entries;                        // the number of history entries for the host's charts
+    long rrd_history_entries;                       // the number of history entries for the host's charts
     RRD_MEMORY_MODE rrd_memory_mode;                // the memory more for the charts of this host
 
     char *cache_dir;                                // the directory to save RRD cache files
@@ -491,7 +491,7 @@ extern RRDHOST *rrdhost_find_or_create(
         , const char *guid
         , const char *os
         , int update_every
-        , int history
+        , long history
         , RRD_MEMORY_MODE mode
         , int health_enabled
         , int rrdpush_enabled
index 74ae1bb744df6f582600e361ed96a3cb18da6ddd..4d853930cc35a791f74b00d57046df3371574377 100644 (file)
@@ -78,25 +78,30 @@ void rrd_stats_api_v1_chart(RRDSET *st, BUFFER *wb) {
     rrd_stats_api_v1_chart_with_data(st, wb, NULL, NULL);
 }
 
-void rrd_stats_api_v1_charts(RRDHOST *host, BUFFER *wb)
-{
+void rrd_stats_api_v1_charts(RRDHOST *host, BUFFER *wb) {
+    static char *custom_dashboard_info_js_filename = NULL;
     size_t c, dimensions = 0, memory = 0, alarms = 0;
     RRDSET *st;
 
     time_t now = now_realtime_sec();
 
+    if(unlikely(!custom_dashboard_info_js_filename))
+        custom_dashboard_info_js_filename = config_get(CONFIG_SECTION_WEB, "custom dashboard_info.js", "");
+
     buffer_sprintf(wb, "{\n"
            "\t\"hostname\": \"%s\""
         ",\n\t\"version\": \"%s\""
         ",\n\t\"os\": \"%s\""
         ",\n\t\"update_every\": %d"
-        ",\n\t\"history\": %d"
+        ",\n\t\"history\": %ld"
+        ",\n\t\"custom_info\": \"%s\""
         ",\n\t\"charts\": {"
         , host->hostname
         , program_version
         , host->os
         , host->rrd_update_every
         , host->rrd_history_entries
+        , custom_dashboard_info_js_filename
         );
 
     c = 0;
index 3b0283088545c0ea047375c0519731cc1ecb1b16..6710f31cf9071450a17916d5a64b356a094e7113 100644 (file)
@@ -142,7 +142,7 @@ void rrd_all2json_api_old(RRDHOST *host, BUFFER *wb)
     buffer_sprintf(wb, "\n\t],\n"
                     "\t\"hostname\": \"%s\",\n"
                     "\t\"update_every\": %d,\n"
-                    "\t\"history\": %d,\n"
+                    "\t\"history\": %ld,\n"
                     "\t\"memory\": %lu\n"
                     "}\n"
                    , host->hostname
index 575b9ec0816860e47c52aad71785c0d6f88e1f0d..81ff96f892415a82a80f6a2ff2f330203a8e9caa 100644 (file)
@@ -83,7 +83,7 @@ RRDHOST *rrdhost_create(const char *hostname,
         const char *guid,
         const char *os,
         int update_every,
-        int entries,
+        long entries,
         RRD_MEMORY_MODE memory_mode,
         int health_enabled,
         int rrdpush_enabled,
@@ -98,7 +98,7 @@ RRDHOST *rrdhost_create(const char *hostname,
     RRDHOST *host = callocz(1, sizeof(RRDHOST));
 
     host->rrd_update_every    = update_every;
-    host->rrd_history_entries = entries;
+    host->rrd_history_entries = align_entries_to_pagesize(memory_mode, entries);
     host->rrd_memory_mode     = memory_mode;
     host->health_enabled      = (memory_mode == RRD_MEMORY_MODE_NONE)? 0 : health_enabled;
     host->rrdpush_enabled     = (rrdpush_enabled && rrdpush_destination && *rrdpush_destination && rrdpush_api_key && *rrdpush_api_key);
@@ -233,7 +233,7 @@ RRDHOST *rrdhost_create(const char *hostname,
                      ", os %s"
                      ", update every %d"
                      ", memory mode %s"
-                     ", history entries %d"
+                     ", history entries %ld"
                      ", streaming %s"
                      " (to '%s' with api key '%s')"
                      ", health %s"
@@ -270,7 +270,7 @@ RRDHOST *rrdhost_find_or_create(
         , const char *guid
         , const char *os
         , int update_every
-        , int history
+        , long history
         , RRD_MEMORY_MODE mode
         , int health_enabled
         , int rrdpush_enabled
@@ -310,7 +310,7 @@ RRDHOST *rrdhost_find_or_create(
             error("Host '%s' has an update frequency of %d seconds, but the wanted one is %d seconds.", host->hostname, host->rrd_update_every, update_every);
 
         if(host->rrd_history_entries != history)
-            error("Host '%s' has history of %d entries, but the wanted one is %d entries.", host->hostname, host->rrd_history_entries, history);
+            error("Host '%s' has history of %ld entries, but the wanted one is %ld entries.", host->hostname, host->rrd_history_entries, history);
 
         if(host->rrd_memory_mode != mode)
             error("Host '%s' has memory mode '%s', but the wanted one is '%s'.", host->hostname, rrd_memory_mode_name(host->rrd_memory_mode), rrd_memory_mode_name(mode));
index 87c4309a2f546d7bff85c195c7d8f707395c0f63..72e6d8a737bab8ca32688974b9ed34db1908af6e 100644 (file)
@@ -522,7 +522,7 @@ int rrdpush_receive(int fd, const char *key, const char *hostname, const char *m
     }
 
 #ifdef NETDATA_INTERNAL_CHECKS
-    info("STREAM %s [receive from [%s]:%s]: client willing to stream metrics for host '%s' with machine_guid '%s': update every = %d, history = %d, memory mode = %s, health %s"
+    info("STREAM %s [receive from [%s]:%s]: client willing to stream metrics for host '%s' with machine_guid '%s': update every = %d, history = %ld, memory mode = %s, health %s"
          , hostname
          , client_ip
          , client_port
@@ -583,12 +583,11 @@ int rrdpush_receive(int fd, const char *key, const char *hostname, const char *m
     error("STREAM %s [receive from [%s]:%s]: disconnected (completed updates %zu).", host->hostname, client_ip, client_port, count);
 
     rrdhost_wrlock(host);
+    host->senders_disconnected_time = now_realtime_sec();
     host->connected_senders--;
     if(!host->connected_senders) {
         if(health_enabled == CONFIG_BOOLEAN_AUTO)
             host->health_enabled = 0;
-
-        host->senders_disconnected_time = now_realtime_sec();
     }
     rrdhost_unlock(host);
 
index 6d1130239fc259770bd880ef1fe885727194d115..03a487597263805909372d5ed70286b23f5d3901 100644 (file)
@@ -11,6 +11,7 @@ dist_web_DATA = \
        dashboard.html \
        dashboard.js \
        dashboard_info.js \
+       dashboard_info_custom_example.js \
        dashboard.css \
        dashboard.slate.css \
        favicon.ico \
diff --git a/web/dashboard_info_custom_example.js b/web/dashboard_info_custom_example.js
new file mode 100644 (file)
index 0000000..f9e255d
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * Custom netdata information file
+ * -------------------------------
+ *
+ * Use this file to add custom information on netdata dashboards:
+ *
+ * 1. Copy it to a new filename (so that it will not be overwritten with netdata updates)
+ * 2. Edit it to fit your needs
+ * 3. Set the following option to /etc/netdata/netdata.conf :
+ *
+ *    [web]
+ *      custom dashboard_info.js = your_filename.js
+ *
+ * Using this file you can:
+ *
+ * 1. Overwrite or add messages to menus, submenus and charts.
+ *    Use dashboard_info.js to find out what you can define.
+ *
+ * 2. Inject javascript code into the default netdata dashboard.
+ *
+ */
+
+// ----------------------------------------------------------------------------
+// MENU
+//
+// - title      the menu title as to be rendered at the charts menu
+// - icon       html fragment of the icon to display
+// - info       html fragment for the description above all the menu charts
+
+customDashboard.menu = {
+
+};
+
+
+// ----------------------------------------------------------------------------
+// SUBMENU
+//
+// - title       the submenu title as to be rendered at the charts menu
+// - info        html fragment for the description above all the submenu charts
+
+customDashboard.submenu = {
+
+};
+
+
+// ----------------------------------------------------------------------------
+// CONTEXT (the template each chart is based on)
+//
+// - info        html fragment for the description above the chart
+// - height      a ratio to the default as a decimal number: 1.0 = 100%
+// - colors      a single color or an array of colors to use for the dimensions
+// - valuerange  the y-range of the chart as an array [min, max]
+// - heads       an array of gauge charts to render above the submenu section
+// - mainheads   an array of gauge charts to render at the menu section
+
+customDashboard.context = {
+
+};
index a254aa83907e547500c39e3b51ac8c78b4022cf7..250dbfed32c69a35d8729836fcf4f0c57a54b4a4 100644 (file)
 
         // ----------------------------------------------------------------------------
 
+        // user editable information
+        var customDashboard = {
+            menu: {},
+            submenu: {},
+            context: {}
+        };
+
+        // netdata standard information
         var netdataDashboard = {
             sparklines_registry: {},
             os: 'unknown',
                     chart.menu = chart.type;
                     if(parts.length > 2 && parts[1] === 'cache')
                         chart.menu_pattern = tmp + '_' + parts[1];
+                    else if(parts.length > 1)
+                        chart.menu_pattern = tmp;
                     break;
 
                 case 'bind':
                     chart.menu = chart.type;
                     if(parts.length > 2 && parts[1] === 'rndc')
                         chart.menu_pattern = tmp + '_' + parts[1];
+                    else if(parts.length > 1)
+                        chart.menu_pattern = tmp;
                     break;
 
                 case 'cgroup':
                     chart.menu = chart.type;
                     if(parts.length > 2 && parts[1] === 'dhcpd')
                         chart.menu_pattern = tmp + '_' + parts[1];
+                    else if(parts.length > 1)
+                        chart.menu_pattern = tmp;
                     break;
 
                 case 'ovpn':
                     chart.menu = chart.type;
                     if(parts.length > 3 && parts[1] === 'status' && parts[2] === 'log')
                         chart.menu_pattern = tmp + '_' + parts[1];
+                    else if(parts.length > 1)
+                        chart.menu_pattern = tmp;
                     break;
 
                 case 'smartd':
                     chart.menu = chart.type;
                     if(parts.length > 2 && parts[1] === 'log')
                         chart.menu_pattern = tmp + '_' + parts[1];
-                    break;
-
-                case 'dovecot':
-                case 'exim':
-                case 'hddtemp':
-                case 'ipfs':
-                case 'memcached':
-                case 'mysql':
-                case 'named':
-                case 'nginx':
-                case 'nut':
-                case 'phpfpm':
-                case 'postfix':
-                case 'postgres':
-                case 'redis':
-                case 'retroshare':
-                case 'smawebbox':
-                case 'snmp':
-                case 'squid':
-                case 'tomcat':
-                    chart.menu = chart.type;
-                    chart.menu_pattern = tmp;
+                    else if(parts.length > 1)
+                        chart.menu_pattern = tmp;
                     break;
 
                 case 'tc':
 
                 default:
                     chart.menu = chart.type;
+                    if(parts.length > 1)
+                        chart.menu_pattern = tmp;
                     break;
             }
 
                 document.getElementById('alarms_count_badge').innerHTML = '';
         }
 
+        function initializeDynamicDashboardWithData(data) {
+            if(data !== null) {
+                options.hostname = data.hostname;
+                options.data = data;
+                options.version = data.version;
+                netdataDashboard.os = data.os;
+
+                if(typeof data.hosts != 'undefined')
+                    options.hosts = data.hosts;
+
+                // update the dashboard hostname
+                document.getElementById('hostname').innerHTML = options.hostname;
+                document.getElementById('hostname').href = NETDATA.serverDefault;
+                document.getElementById('netdataVersion').innerHTML = options.version;
+
+                // update the dashboard title
+                document.title = options.hostname + ' netdata dashboard';
+
+                // close the splash screen
+                $("#loadOverlay").css("display","none");
+
+                // create a chart_by_name index
+                data.charts_by_name = {};
+                var charts = data.charts;
+                var x;
+                for(x in charts) {
+                    if(!charts.hasOwnProperty(x)) continue;
+
+                    var chart = charts[x];
+                    data.charts_by_name[chart.name] = chart;
+                }
+
+                // render all charts
+                renderChartsAndMenu(data);
+            }
+        }
+
         function initializeDynamicDashboard(netdata_url) {
             if(typeof netdata_url === 'undefined' || netdata_url === null)
                 netdata_url = NETDATA.serverDefault;
 
                 // download all the charts the server knows
                 NETDATA.chartRegistry.downloadAll(netdata_url, function(data) {
-                    if(data !== null) {
-                        options.hostname = data.hostname;
-                        options.data = data;
-                        options.version = data.version;
-                        netdataDashboard.os = data.os;
-
-                        if(typeof data.hosts != 'undefined')
-                            options.hosts = data.hosts;
-
-                        // update the dashboard hostname
-                        document.getElementById('hostname').innerHTML = options.hostname;
-                        document.getElementById('hostname').href = NETDATA.serverDefault;
-                        document.getElementById('netdataVersion').innerHTML = options.version;
-
-                        // update the dashboard title
-                        document.title = options.hostname + ' netdata dashboard';
-
-                        // close the splash screen
-                        $("#loadOverlay").css("display","none");
-
-                        // create a chart_by_name index
-                        data.charts_by_name = {};
-                        var charts = data.charts;
-                        var x;
-                        for(x in charts) {
-                            if(!charts.hasOwnProperty(x)) continue;
-
-                            var chart = charts[x];
-                            data.charts_by_name[chart.name] = chart;
+                    if(data != null) {
+                        if(typeof data.custom_info !== 'undefined' && data.custom_info !== "") {
+                            loadJs(data.custom_info, function () {
+                                $.extend(true, netdataDashboard, customDashboard);
+                                initializeDynamicDashboardWithData(data);
+                            });
+                        }
+                        else {
+                            initializeDynamicDashboardWithData(data);
                         }
-
-                        // render all charts
-                        renderChartsAndMenu(data);
                     }
                 });
             });