-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathMMM-GrafanaGauges.js
executable file
·49 lines (48 loc) · 2.03 KB
/
MMM-GrafanaGauges.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
Module.register("MMM-GrafanaGauges", {
// Default module config.
defaults: {
height:"100",
width:"100",
refreshInterval: 900,
animationSpeed: 1000,
https: false
},
// Define start sequence.
start: function() {
Log.info("Starting module: " + this.name + "!!!!");
this.scheduleUpdate(this.config.refreshInterval);
},
// Override dom generator.
getDom: function() {
var img = '';
var wrapper = document.createElement("div");
var url = ((this.config.https === true) ? "https://" : "http://") + this.config.host + ":" + this.config.port + "/dashboard-solo/db/" + this.config.dashboardname+ "?orgId=" + this.config.orgId
for (var i = 0 ; i < this.config.showIDs.length; i++) {
img += '<iframe src="' + url + '&panelId='+this.config.showIDs[i]+'" width="' + this.config.width + '" height="' + this.config.height + '" frameborder="0" scrolling="no"></iframe>';
}
Log.info('img=' + img);
wrapper.innerHTML = img;
wrapper.setAttribute("timestamp", new Date().getTime());
return wrapper;
},
scheduleUpdate: function(delay) {
var nextLoad = this.config.refreshInterval;
if (typeof delay !== "undefined" && delay >= 0) {
nextLoad = delay * 1000; // Convert seconds to millis
}
var self = this;
setTimeout(function() {
self.updateFrame();
}, nextLoad);
},
updateFrame: function() {
if (this.config.host === "") {
Log.error("Tried to refresh, iFrameReload URL not set!");
return;
}
// Change url to force refresh?
this.src = ((this.config.https === true) ? "https://" : "http://") + this.config.host + ":" + this.config.port + "/dashboard-solo/db/" + this.config.dashboardname+ "?orgId=" + this.config.orgId;
this.updateDom(this.config.animationSpeed);
this.scheduleUpdate(this.config.refreshInterval);
}
});