added version update check #175
Costa Tsaousis (ktsaou) committed
Apr 6, 2016 at 00:46 UTC
fc71850c9077ec543a3b4ae8e9fb166672a1bcb4
2 files changed
+164
-12
.gitignore
+2
@@ -58,4 +58,6 @@ web/datasource.css
58
web/gadget.xml
59
web/index_new.html
60
web/version.txt
61
+
62
system/netdata-openrc
63
+system/netdata-init-d
web/index.html
+162
-12
@@ -282,29 +282,27 @@
282
283
<!-- check which theme to use -->
284
<script>
285
- function getTheme(def) {
285
+ function loadLocalStorage(name) {
286
var ret = null;
287
288
try {
289
if(typeof Storage !== "undefined" && typeof localStorage === 'object')
290
- ret = localStorage.getItem('netdataTheme');
290
+ ret = localStorage.getItem(name);
291
}
292
catch(error) {
293
;
294
}
295
296
- if(ret === null || ret === 'undefined') return def;
297
- else return ret;
298
- }
299
- var netdataTheme = getTheme('slate');
296
+ if(typeof ret === 'undefined' || ret === null)
297
+ return null;
298
301
- function setTheme(theme) {
302
- if(netdataTheme === theme)
303
- return false;
299
+ return ret;
300
+ }
301
302
+ function saveLocalStorage(name, value) {
303
try {
304
if(typeof Storage !== "undefined" && typeof localStorage === 'object') {
307
- localStorage.setItem('netdataTheme', theme);
305
+ localStorage.setItem(name, value.toString());
306
return true;
307
}
308
}
@@ -314,10 +312,23 @@
312
313
return false;
314
}
315
+
316
+ function getTheme(def) {
317
+ var ret = loadLocalStorage('netdataTheme');
318
+ if(typeof ret === 'undefined' || ret === null || ret === 'undefined')
319
+ return def;
320
+ else
321
+ return ret;
322
+ }
323
+ var netdataTheme = getTheme('slate');
324
+
325
+ function setTheme(theme) {
326
+ return saveLocalStorage('netdataTheme', theme);
327
+ }
328
</script>
329
330
<!-- load the dashboard manager - it will do the rest -->
320
- <script type="text/javascript" src="dashboard.js?v25"></script>
331
+ <script type="text/javascript" src="dashboard.js?v26"></script>
332
</head>
333
334
<body data-spy="scroll" data-target="#sidebar">
@@ -336,6 +347,7 @@
347
<ul class="nav navbar-nav">
348
<li><a href="#" class="btn" data-toggle="modal" data-target="#optionsModal"><i class="fa fa-cog"></i> settings</a></li>
349
<li><a href="https://github.com/firehol/netdata/wiki" class="btn" target="_blank"><i class="fa fa-github"></i> community</a></li>
350
+ <li id="updateButton"><a href="#" class="btn" data-toggle="modal" data-target="#updateModal"><i class="fa fa-cloud-download"></i> update</a></li>
351
<!-- <li><a href="old/" class="btn" target="_blank"><i class="fa fa-step-backward"></i> old dashboard</a></li> -->
352
<li><a href="#" class="btn" data-toggle="modal" data-target="#helpModal"><i class="fa fa-question-circle"></i> help</a></li>
353
<!-- <li><a href="#sec">Visualize</a></li>
@@ -725,6 +737,28 @@
737
</div>
738
</div>
739
740
+
741
+ <div class="modal fade" id="updateModal" tabindex="-1" role="dialog" aria-labelledby="updateModalLabel">
742
+ <div class="modal-dialog" role="document">
743
+ <div class="modal-content">
744
+ <div class="modal-header">
745
+ <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
746
+ <h4 class="modal-title" id="updateModalLabel">Update Check</h4>
747
+ </div>
748
+ <div class="modal-body">
749
+ Your netdata version: <b><code><span id="netdataVersion">Unknown</span></code></b>
750
+ <br/>
751
+ <div style="padding: 10px;"></div>
752
+ <div id="versionCheckLog">Not checked yet. Please press the Check Now button.</div>
753
+ </div>
754
+ <div class="modal-footer">
755
+ <a href="#" onclick="notifyForUpdate(true);" type="button" class="btn btn-default">Check Now</a>
756
+ <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
757
+ </div>
758
+ </div>
759
+ </div>
760
+ </div>
761
+
762
<script>
763
764
var demo_hostname = 'netdata.firehol.org';
@@ -1574,6 +1608,119 @@ function downloadAllCharts(netdata_url) {
1608
1609
// ----------------------------------------------------------------------------
1610
1611
+function versionLog(msg) {
1612
+ document.getElementById('versionCheckLog').innerHTML = msg;
1613
+}
1614
+
1615
+function getNetdataVersion(callback) {
1616
+ versionLog('Downloading installed version info from netdata...');
1617
+
1618
+ $.ajax({
1619
+ url: 'version.txt',
1620
+ async: true,
1621
+ cache: false
1622
+ })
1623
+ .done(function(data) {
1624
+ data = data.replace(/(\r\n|\n|\r)/gm,"")
1625
+ console.log(data.length);
1626
+ versionLog('Installed version of netdata is ' + data);
1627
+ document.getElementById('netdataVersion').innerHTML = data;
1628
+ callback(data);
1629
+ })
1630
+ .fail(function() {
1631
+ versionLog('Failed to download installed version info from netdata!');
1632
+ callback(null);
1633
+ });
1634
+}
1635
+
1636
+function getGithubLatestCommit(callback) {
1637
+ versionLog('Downloading latest version info from github...');
1638
+
1639
+ $.ajax({
1640
+ url: 'https://api.github.com/repos/firehol/netdata/commits',
1641
+ async: true,
1642
+ cache: false
1643
+ })
1644
+ .done(function(data) {
1645
+ versionLog('Latest version info from github is ' + data[0].sha);
1646
+ callback(data[0].sha);
1647
+ })
1648
+ .fail(function() {
1649
+ versionLog('Failed to download installed version info from github!');
1650
+ callback(null);
1651
+ });
1652
+}
1653
+
1654
+function checkForUpdate(callback) {
1655
+ getNetdataVersion(function(sha1) {
1656
+ if(sha1 === null) callback(null, null);
1657
+
1658
+ getGithubLatestCommit(function(sha2) {
1659
+ callback(sha1, sha2);
1660
+ });
1661
+ });
1662
+
1663
+ return null;
1664
+}
1665
+
1666
+var updateBlinkCounter = 0;
1667
+function notifyForUpdate(force) {
1668
+ var now = new Date().getTime();
1669
+
1670
+ if(typeof force === 'undefined' || force !== true) {
1671
+ var last = loadLocalStorage('last_update_check');
1672
+
1673
+ if(typeof last === 'string')
1674
+ last = parseInt(last);
1675
+ else
1676
+ last = 0;
1677
+
1678
+ if(now - last < 3600000 * 8) {
1679
+ // no need to check it - too soon
1680
+ return;
1681
+ }
1682
+ }
1683
+
1684
+ checkForUpdate(function(sha1, sha2) {
1685
+ var save = false;
1686
+
1687
+ if(sha1 === null) {
1688
+ save = false;
1689
+ versionLog('<p><big>Failed to get your netdata version!</big></p>');
1690
+ }
1691
+ else if(sha2 === null) {
1692
+ save = false;
1693
+ versionLog('<p><big>Failed to get the latest version from github.</big></p>');
1694
+ }
1695
+ else if(sha1 === sha2) {
1696
+ save = true;
1697
+ versionLog('<p><big>You already have the latest version of netdata!</big></p>');
1698
+ }
1699
+ else {
1700
+ save = true;
1701
+ var compare = 'https://github.com/firehol/netdata/compare/' + sha1.toString() + '...' + sha2.toString();
1702
+
1703
+ versionLog('<p><big><strong>You don\'t have the latest version of netdata!</strong></big></p><p>Latest version: ' + sha2.toString() + '</p><p><a href="' + compare + '" target="_blank">Click here for the changes log</a> since your installed version, and<br/><a href="https://github.com/firehol/netdata/wiki/Updating-Netdata" target="_blank">click here for directions on updating</a> your netdata installation.</p><p>We suggest to review the changes log for new features you may be interested, or important bug fixes you may need.<br/>Keeping your netdata updated is generally a good idea.</p>');
1704
+
1705
+ function updateButtonBlink() {
1706
+ updateBlinkCounter--;
1707
+ if(updateBlinkCounter > 0)
1708
+ $('#updateButton').fadeOut(500).fadeIn(500, updateButtonBlink);
1709
+ }
1710
+
1711
+ if(updateBlinkCounter === 0) {
1712
+ updateBlinkCounter = 300;
1713
+ updateButtonBlink();
1714
+ }
1715
+ }
1716
+
1717
+ if(save)
1718
+ saveLocalStorage('last_update_check', now.toString());
1719
+ });
1720
+}
1721
+
1722
+// ----------------------------------------------------------------------------
1723
+
1724
function finalizePage() {
1725
// resize all charts - without starting the background thread
1726
// this has to be done while NETDATA is paused
@@ -1674,10 +1821,13 @@ function finalizePage() {
1821
location.reload();
1822
});
1823
1677
- if(document.location.hostname === demo_hostname)
1824
+ if(document.location.hostname === demo_hostname) {
1825
setTimeout(function() {
1826
$('#welcomeModal').modal();
1827
}, 1000);
1828
+ }
1829
+ else
1830
+ notifyForUpdate();
1831
}
1832
1833
function resetDashboardOptions() {