Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.git
node_modules/caniuse-db/*
*.sh
124 changes: 124 additions & 0 deletions .idea/uiDesigner.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ RUN npm run dist
# Default host is localhost. This is for same-origin policies.
ENV HOST "localhost"

# Number of milliseconds between polling requests. Default is 200.
ENV MS 200
# Number of milliseconds between polling requests. Default is 1000.
ENV MS 1000

#Default port to expose.
ENV PORT 8080
Expand Down
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
*** note ***

I did some improvements to the original https://github.com/ManoMarks/docker-swarm-visualizer

It adds node and container data to make this visualizer a better swarm monitoring tool.

Here is a sample image of nodes with data:

![Sample image of nodes with data](./nodes.png)



see installation instructions from https://github.com/ManoMarks/docker-swarm-visualizer below :

# Docker Swarm Visualizer

Demo container that displays Docker services on a Docker Swarm a diagram.
Expand Down
10 changes: 10 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@


docker swarm init --advertise-addr 127.0.0.1:2377
docker service create rabbitmq:3.6.5

npm run dist && npm start

#docker swarm leave --force


18 changes: 9 additions & 9 deletions dist/app.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/app.js.map

Large diffs are not rendered by default.

Binary file added nodes.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
"keywords": ["Docker","Swarm","D3","Node Visualization"],
"author": "Your name here",
"devDependencies": {
"babel-core": "^5.8.22",
"babel-loader": "^5.3.2",
"babel-core": "^5.8.38",
"babel-loader": "^5.4.2",
"chai": "^3.2.0",
"copyfiles": "^0.2.1",
"css-loader": "^0.16.0",
Expand Down
5 changes: 5 additions & 0 deletions push.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

docker build -t=turaaa/swarmvisualizer:latest .
docker push turaaa/swarmvisualizer:latest
#docker swarm leave --force

10 changes: 6 additions & 4 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ var http = require('http');
var WS = require('ws');

var WebSocketServer = WS.Server;
var host = process.env.HOST;
var port;
var host = process.env.HOST ||"localhost";
process.env.HOST=host
var port =process.env.PORT || 8080;
process.env.PORT=port;
var indexData;
var app = express();
var ms = process.env.MS;

var ms = process.env.MS || 1000;
process.env.MS=ms

app.use(express.static('dist'));

Expand Down
29 changes: 24 additions & 5 deletions src/data-provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@ function nodeOrContainerExists(arr, value) {
return false;
}

var stringToColour = function(str) {

// str to hash
for (var i = 0, hash = 0; i < str.length; hash = str.charCodeAt(i++) + ((hash << 5) - hash));

// int/hash to hex
for (var i = 0, colour = "#"; i < 3; colour += ("00" + ((hash >> i++ * 8) & 0xFF).toString(16)).slice(-2));

return colour;
}

function physicalStructProvider([initialNodes,initialContainers]){
let containers = _.map(initialContainers, _.cloneDeep);
Expand All @@ -45,7 +55,14 @@ function physicalStructProvider([initialNodes,initialContainers]){
_.find(root,(cluster) => {
var node = _.find(cluster.children,{ ID:NodeID });
if(!node) return;
let imageTag = cloned.Spec.ContainerSpec.Image.split(':')[1];
var dt=new Date(cloned.UpdatedAt);
var color= stringToColour(cloned.ServiceID);
let imageTag ="<span style='color:" + color+"; font-weight: bold;font-size: 12px'>"+ cloned.Spec.ContainerSpec.Image.split(':')[0] +"</span>"+
"<br/> tag : "+cloned.Spec.ContainerSpec.Image.split(':')[1]+
"<br/>" + (cloned.Spec.ContainerSpec.Args?" cmd : "+cloned.Spec.ContainerSpec.Args:"" ) +
"<br/> updated : "+dt.getDate()+"/"+(dt.getMonth()+1)+" "+ dt.getHours()+":"+dt.getMinutes()+
"<br/> ID : "+cloned.Status.ContainerStatus.ContainerID+
"<br/>";
cloned.tag = imageTag;
node.children.push(cloned);
return true;
Expand Down Expand Up @@ -110,14 +127,16 @@ function physicalStructProvider([initialNodes,initialContainers]){
for (let node of nodes) {
if(!nodeOrContainerExists(currentnodelist,node.ID)) {
updateNode(node,'ready');

addNode(node);
} else {
for (let currentnode of currentnodelist) {
if (node.ID == currentnode.ID) {
name = node.Description.Hostname;
if(name.length>0) {
currentnode.Description.Hostname = name;
currentnode.name = name;
currentnode.Description.Hostname = name ;
currentnode.name = name+" <br/> "+ currentnode.Spec.Role+
" <br/>"+(currentnode.Description.Resources.MemoryBytes/1000000000).toFixed(0)+"G free";
}
updateNode(currentnode, node.state);
}
Expand Down Expand Up @@ -184,7 +203,7 @@ class DataProvider extends EventEmitter {

start(){
STARTED = 1;
console.log(STARTED);
//console.log(STARTED);
var clusterInit = Promise.all([
getAllNodes(),
getAllTasks()
Expand All @@ -204,7 +223,7 @@ class DataProvider extends EventEmitter {
reload() {
if(STARTED ==0) return;
STARTED++;
console.log(STARTED);
// console.log(STARTED);
var clusterInit = Promise.all([
getAllNodes(),
getAllTasks()
Expand Down
2 changes: 2 additions & 0 deletions src/utils/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ function filterStoppedNodes (objects) {
object.state = "down"
}
object.name = object.Description.Hostname;
object.name= object.name+" <br/>"+object.Spec.Role+
" <br/>"+(object.Description.Resources.MemoryBytes/1000000000).toFixed(0)+"G free";
readyNodes.push(object);
}
readyNodes.sort(function (a, b) {
Expand Down
14 changes: 7 additions & 7 deletions src/vis-physical/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,18 @@ function render ({root}) {

container
.classed('foreign', (d) => !d.state)
.attr('tag',(d) => _.kebabCase(d.tag))
.attr('tag',(d) => _.kebabCase(d.tag)).html((d) => d.tag)

container.on('mouseenter',null);
container.on('mouseleave',null);

container.on('mouseenter',function(){
d3.select(this).html((d) => d.name);
});
//container.on('mouseenter',function(){
// d3.select(this).html((d) => d.name);
//});

container.on('mouseleave',function(){
d3.select(this).html('');
});
//container.on('mouseleave',function(){
// d3.select(this).html('');
//});

cluster.exit().remove();
container.exit().remove();
Expand Down
2 changes: 1 addition & 1 deletion src/vis-physical/styles.less
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
}

.node-meta{
line-height: 2;
//line-height: 0;
font-size: 20pt;
text-align: center;
text-indent: -3px;
Expand Down