Skip to content
This repository has been archived by the owner on Jun 11, 2021. It is now read-only.

Commit

Permalink
Merge pull request #152 from kitematic/jmorgan_fix_metrics_images
Browse files Browse the repository at this point in the history
Fix metrics & hide images with <none>:<none> tag
  • Loading branch information
JeffDM committed Jan 7, 2015
2 parents 593e793 + eaaf813 commit ad8cfbe
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 41 deletions.
5 changes: 2 additions & 3 deletions meteor/client/lib/apputil.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ AppUtil.run = function (app, callback) {
}});
return;
}
// Set a delay for app to spin up
Apps.update(app._id, {$set: {
docker: data,
status: 'READY'
Expand Down Expand Up @@ -167,7 +166,7 @@ AppUtil.sync = function (callback) {
var diffApps = _.difference(guiIds, containerIds);
_.each(diffApps, function (appContainerId) {
var app = Apps.findOne({'docker.Id': appContainerId});
if (app && app.status === 'READY') {
if (app && app.status !== 'STARTING') {
AppUtil.remove(app._id);
}
});
Expand All @@ -180,7 +179,7 @@ AppUtil.sync = function (callback) {
return app.status === 'STARTING' && app.name === appName;
});

if (startingApp || _.isEmpty(container.NetworkSettings.Ports)) {
if (startingApp || _.isEmpty(container.NetworkSettings.Ports) || !_.pairs(container.NetworkSettings.Ports)[0][1]) {
return;
}

Expand Down
3 changes: 0 additions & 3 deletions meteor/client/lib/docker.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,6 @@ Docker.runContainer = function (app, image, callback) {
containerOpts.ExposedPorts = app.docker.NetworkSettings.Ports;
}

console.log(containerOpts);

Docker.client().createContainer(containerOpts, function (err, container) {
if (err) { callback(err, null); return; }
console.log('Created container: ' + container.id);
Expand All @@ -135,7 +133,6 @@ Docker.runContainer = function (app, image, callback) {
startOpts.PublishAllPorts = true;
}

console.log(startOpts);
container.start(startOpts, function (err) {
if (err) { callback(err, null); return; }
console.log('Started container: ' + container.id);
Expand Down
4 changes: 2 additions & 2 deletions meteor/client/lib/imageutil.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ ImageUtil.sync = function (callback) {
var diffImages = _.difference(kitematicIds, daemonIds);
_.each(diffImages, function (imageId) {
var image = Images.findOne({'docker.Id': imageId});
if (image && image.status === 'READY') {
if (image && image.status !== 'BUILDING') {
Images.remove(image._id);
}
});
Expand All @@ -269,7 +269,7 @@ ImageUtil.sync = function (callback) {
return _.contains(kitematicIds, image.Id);
});
_.each(diffDockerImages, function (image) {
if (!image.RepoTags || !image.Config || _.isEmpty(image.Config.ExposedPorts)) {
if (!image.RepoTags || !image.RepoTags || image.RepoTags[0] === '<none>:<none>' || !image.Config || _.isEmpty(image.Config.ExposedPorts)) {
return;
}

Expand Down
36 changes: 26 additions & 10 deletions meteor/client/lib/metrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ var remote = require('remote');
var app = remote.require('app');
var crypto = require('crypto');
var uuid = require('node-uuid');
var level = require('levelup');
var path = require('path');
var db = level(path.join(process.env[(process.platform === 'win32') ? 'USERPROFILE' : 'HOME'], 'Library/Application Support/Kitematic/data', 'db'));
var fs = require('fs');

var level = require('levelup');
var db;

Metrics = {};

Expand Down Expand Up @@ -49,20 +51,34 @@ Metrics.trackEvent = function (name) {
});
};

Metrics.prepareTracking = function () {
Metrics.prepareUUID = function (callback) {
db.get('metrics.uuid', function (err, value) {
if (err && err.notFound) {
db.put('metrics.uuid', uuid.v4(), function (err) {
callback();
});
} else {
callback();
}
});
};

Metrics.prepareTracking = function (callback) {
db = level(Util.getMetricsDir());
db.get('metrics.enabled', function (err, value) {
if (err && err.notFound) {
var settings = Settings.findOne();
if (settings && settings.tracking) {
db.put('metrics.enabled', !!settings.tracking);
db.put('metrics.enabled', !!settings.tracking, function(err) {
Metrics.prepareUUID(callback);
});
} else {
db.put('metrics.enabled', true);
db.put('metrics.enabled', true, function (err) {
Metrics.prepareUUID(callback);
});
}
} else {
Metrics.prepareUUID(callback);
}
db.get('metrics.uuid', function (err, value) {
if (err && err.notFound) {
db.put('metrics.uuid', uuid.v4());
}
});
});
};
32 changes: 12 additions & 20 deletions meteor/client/lib/startup.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,20 @@ var fs = require('fs');

Meteor.startup(function () {
console.log('Kitematic started.');
if (!fs.existsSync(Util.KITE_PATH)) {
console.log('Created Kitematic directory.');
fs.mkdirSync(Util.KITE_PATH);
}
if (!fs.existsSync(Util.KITE_TAR_PATH)) {
console.log('Created Kitematic .tar directory.');
fs.mkdirSync(Util.KITE_TAR_PATH);
}
if (!fs.existsSync(Util.KITE_IMAGES_PATH)) {
console.log('Created Kitematic .images directory.');
fs.mkdirSync(Util.KITE_IMAGES_PATH);
}
if (!fs.existsSync(Util.getResourceDir())) {
fs.mkdirSync(Util.getResourceDir());
}

Metrics.prepareTracking();
Metrics.trackEvent('app started');
Metrics.trackEvent('app heartbeat');
Meteor.setInterval(function () {
[Util.KITE_PATH, Util.KITE_TAR_PATH, Util.KITE_IMAGES_PATH, Util.getAppSupportDir(), Util.getResourceDir(), Util.getDataDir(), Util.getMetricsDir()].forEach(function (d) {
if (!fs.existsSync(d)) {
fs.mkdirSync(d);
}
});

Metrics.prepareTracking(function() {
Metrics.trackEvent('app started');
Metrics.trackEvent('app heartbeat');
}, 14400000);
Meteor.setInterval(function () {
Metrics.trackEvent('app heartbeat');
}, 14400000);
});

Boot2Docker.ip(function (err, ip) {
if (!err) {
Expand Down
8 changes: 8 additions & 0 deletions meteor/client/lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ Util.getBinDir = function () {
return path.join(process.env.DIR, 'resources');
};

Util.getAppSupportDir = function () {
return path.join(Util.getHomePath(), 'Library/Application Support/Kitematic');
};

Util.getResourceDir = function () {
return path.join(Util.getHomePath(), 'Library/Application Support/Kitematic/Resources');
};
Expand All @@ -25,6 +29,10 @@ Util.getDataDir = function () {
return path.join(Util.getHomePath(), 'Library/Application Support/Kitematic/data');
};

Util.getMetricsDir = function () {
return path.join(Util.getHomePath(), 'Library/Application Support/Kitematic/data/db');
};

Util.KITE_PATH = path.join(Util.getHomePath(), 'Kitematic');
Util.KITE_TAR_PATH = path.join(Util.KITE_PATH, '.tar');
Util.KITE_IMAGES_PATH = path.join(Util.KITE_PATH, '.images');
Expand Down
4 changes: 2 additions & 2 deletions meteor/client/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ updateBoot2DockerUtilization = function (callback) {

startUpdatingBoot2DockerUtilization = function () {
updateBoot2DockerUtilization(function (err) { if (err) {console.log(err);} });
Meteor.setTimeout(startUpdatingBoot2DockerUtilization, 2000);
Meteor.setTimeout(startUpdatingBoot2DockerUtilization, 8000);
};

startSyncingAppState = function () {
Expand All @@ -239,5 +239,5 @@ startSyncingAppState = function () {
}
});
});
Meteor.setTimeout(startSyncingAppState, 2000);
Meteor.setTimeout(startSyncingAppState, 8000);
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Kitematic",
"version": "0.4.3",
"version": "0.4.4",
"author": "Kitematic",
"description": "Simple Docker App management for Mac OS X.",
"homepage": "https://kitematic.com/",
Expand Down

0 comments on commit ad8cfbe

Please sign in to comment.