Skip to content

Commit

Permalink
added basic bootstrap spacing and grid, created basic table, node hel…
Browse files Browse the repository at this point in the history
…per successfully pushes data to module, updated README
  • Loading branch information
aaron64 committed Feb 2, 2019
1 parent dae440d commit 44cdfce
Show file tree
Hide file tree
Showing 6 changed files with 3,068 additions and 118 deletions.
190 changes: 73 additions & 117 deletions MMM-DockerVisualizer.js
Expand Up @@ -5,131 +5,87 @@
*
*/
Module.register("MMM-DockerVisualizer", {

// Default module config.
defaults: {
visualizerIp: "192.168.0.1:8080"
visualizerIp: "http://192.168.0.10:8080"
},

getNodes: function() {
var nodes = []
var tasks = []
var services = []

http.get(this.config.visualizerIp + "/apis/nodes", function(res){

response = '';

res.on('data', function(data){
response += data;
});

res.on('end', function(){
var json = JSON.parse(response)
for(var i = 0; i < json.objects.length; i++) {
node = json.objects[i]

nodes.push({
'name': node.Description.Hostname,
'id': node.ID,
'services': []
})
}

for(var i = 0; i < nodes.length; i++) {
console.log(nodes[i])
}
console.log()
});
}).on('error', function(e){
console.log('Got an error: ', e);
});


http.get(this.config.visualizerIp + "/apis/services", function(res){
response = '';

res.on('data', function(data){
response += data;
});

res.on('end', function(){
var json = JSON.parse(response)
for(var i = 0; i < json.objects.length; i++) {
service = json.objects[i]

services.push({
'name': service.Spec.Name,
'id': service.ID,
})
}

for(var i = 0; i < services.length; i++) {
console.log(services[i])
}
console.log()
});
}).on('error', function(e){
console.log('Got an error: ', e);
});

http.get(this.config.visualizerIp + "/apis/tasks", function(res){
response = '';

res.on('data', function(data){
response += data;
});

res.on('end', function(){
var json = JSON.parse(response)
for(var i = 0; i < json.objects.length; i++) {
task = json.objects[i]

if(task.DesiredState == "running") {
tasks.push({
'nodeID': task.NodeID,
'serviceID': task.ServiceID
})
}
}

for(var i = 0; i < tasks.length; i++) {
console.log(tasks[i])
}
console.log()
bindServices()
});
}).on('error', function(e){
console.log('Got an error: ', e);
});


for(var i = 0; i < tasks.length; i++) {
for(var j = 0; j < services.length; j++) {
if(tasks[i]["serviceID"] == services[j]["id"]) {
for(var k = 0; k < nodes.length; k++) {
if(tasks[i]["nodeID"] == nodes[k]["id"]) {
nodes[k]["services"].push(services[j])
console.log(nodes[k])
}
}
}
}
}
}
nodes: [],

start: function() {
Log.log("Sending notification to helper...")
this.sendSocketNotification('GET_NODES', this.config.visualizerIp);
this.loaded = false;
},

getStyles: function() {
return [
this.file('css/grid.css'),
this.file('css/spacing.css')
]
},

getDom: function() {
var wrapper = document.createElement("div")
wrapper.innerHTML = "HELLO"
wrapper.className += "container";

if(nodes[0] == "ERROR") {
wrapper.innerHTML = "Error retreiving docker services."
}

var table = document.createElement("div")
table.className += "row";

for(var i = 0; i < nodes.length; i++) {
var col = document.createElement("div")
col.className += "col-md-4 p-0"
col.setAttribute("style", "border: 1px solid white")

var head = document.createElement("h2")
head.className += "row m-0 p-0 pb-3";
head.setAttribute("style", "text-align: center")
head.innerHTML = nodes[i]["name"]
col.appendChild(head)

var headInfo = document.createElement("h4")
headInfo.className += "row m-0 p-0 pb-3"
headInfo.setAttribute("style", "text-align: center; border-bottom: 1px solid white")
headInfo.innerHTML = nodes[i]["addr"] + "\n" + nodes[i]["state"]
col.appendChild(headInfo)

for(var j = 0; j < nodes[i]["services"].length; j++) {
var service = nodes[i]["services"][j];
var serviceDOM = document.createElement("div")
serviceDOM.className += "row m-0"
serviceDOM.setAttribute("style", "border-bottom: 1px solid white")

var serviceContent = document.createElement("div")
serviceContent.className = "m-0 pl-1 pr-1"

var serviceName = document.createElement("h4")
serviceName.innerHTML = service["name"]
serviceName.setAttribute("style", "text-align: left")
serviceContent.appendChild(serviceName)

serviceDOM.appendChild(serviceContent)

col.appendChild(serviceDOM)
}

table.appendChild(col)
}

wrapper.appendChild(table)
return wrapper
},

socketNotificationReceived: function (notification, payload) {
if (notification === "NODES") {
Log.log(payload)
nodes = payload
this.updateDom()
}
}
})
var http = require('http')

var url_nodes = 'http://192.168.0.10:8080/apis/nodes'
var url_tasks = 'http://192.168.0.10:8080/apis/tasks'
var url_services = 'http://192.168.0.10:8080/apis/services'

nodes = []
tasks = []
services = []

69 changes: 68 additions & 1 deletion README.md
@@ -1,2 +1,69 @@

# MMM-DockerVisualizer
See your docker swarm running in real time through docker-swarm-visualizer.
A <a href="https://github.com/MichMich/MagicMirror">MagicMirror</a> module that displays docker swarm information.

This module depends on the swarm running <a href="https://github.com/ManoMarks/docker-swarm-visualizer">Docker Swarm Visualizer</a> in order to get information about the swarm.


## Installation
1. Run <a href="https://github.com/ManoMarks/docker-swarm-visualizer">Docker Swarm Visualizer</a> inside your docker swarm.
2. Navigate into your MagicMirror's `modules` folder and execute:
```
git clone https://github.com/aaron64/MMM-DockerVisualizer.git
cd MMM-DockerVisualizer
npm install
```
3. Add the module inside `config.js` .


## Config


|Option|Description|
|---|---|
|visualizerIp| The address (and port) of the docker swarm visualizer

Example of `config.js`
```
{
module: "MMM-DockerVisualizer",
position: "top_right",
config: {
visualizerIp: 192.168.0.2:8080
}
}
```

## Screenshots



## Contributors

<a href="https://github.com/ManoMarks">ManoMarks</a> For creating the docker visualizer that I pull all the information from. (Thank you)

## Version




The MIT License (MIT)
=====================

Copyright © 2018 SpoturDeal - Carl

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the “Software”), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

**The software is provided “as is”, without warranty of any kind, express or implied, including but not limited to the warranties of merchantability,
fitness for a particular purpose and noninfringement. In no event shall the authors or copyright holders be liable for any claim, damages or other liability,
whether in an action of contract, tort or otherwise, arising from, out of or in connection with the software or the use or other dealings in the software.**

0 comments on commit 44cdfce

Please sign in to comment.