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

Commit

Permalink
Added the $SYS/<brokerId>/version stat data.
Browse files Browse the repository at this point in the history
  • Loading branch information
mcollina committed Feb 18, 2014
1 parent 6460c5a commit 9be1a9c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
2 changes: 2 additions & 0 deletions lib/stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ OTHER DEALINGS IN THE SOFTWARE.
"use strict";

var moment = require("moment");
var version = "mosca " + require("../package").version;

/**
* Create a new load object.
Expand Down Expand Up @@ -145,6 +146,7 @@ Stats.prototype.wire = function wire(server) {
count = 0;
}

doPublish("version", version);
doPublish("uptime", mom.from(Date.now(), true));
doPublish("connectedClients", stats.connectedClients);
doPublish("publishedMessages", stats.publishedMessages);
Expand Down
21 changes: 15 additions & 6 deletions test/stats_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,18 @@ describe("mosca.Stats", function() {
});
});

it("should publish the version", function(done) {
var version = require("../package").version;
server.on("testPublished", function(packet) {
if (packet.topic === "$SYS/42/version") {
expect(packet.payload).to.eql("mosca " + version);
done();
}
});

clock.tick(60 * 1000);
});

it("should publish the uptime", function(done) {
server.on("testPublished", function(packet) {
if (packet.topic === "$SYS/42/uptime") {
Expand All @@ -213,13 +225,10 @@ describe("mosca.Stats", function() {

it("should publish the uptime (bis)", function(done) {
var count = 0;
server.on("testPublished", function(packet) {
count++;
if (count < 3) {
clock.tick(60 * 1000);
return;
}

clock.tick(60 * 1000 * 2);

server.on("testPublished", function(packet) {
if (packet.topic === "$SYS/42/uptime") {
expect(packet.payload).to.eql("3 minutes");
done();
Expand Down

0 comments on commit 9be1a9c

Please sign in to comment.