-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from uupers/nodeapp
added database stats to the app
- Loading branch information
Showing
6 changed files
with
177 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,32 @@ | ||
var msg; | ||
// get database stats | ||
var getDbStats = function(db, callback) { | ||
db.command({'dbStats': 1}, | ||
function(err, results) { | ||
console.log(results); | ||
callback(); | ||
return results; | ||
} | ||
); | ||
}; | ||
|
||
var MongoClient = require('mongodb').MongoClient | ||
, assert = require('assert'); | ||
|
||
|
||
const dbhtml = document.getElementById('db-info') | ||
|
||
// Connection URL | ||
var url = 'mongodb://spiderrd:[email protected]:37017/bilibili_spider'; | ||
|
||
const dbName = 'bilibili_spider'; | ||
var mongojs = require('mongojs'); | ||
var db = mongojs(url); | ||
var db_member = db.collection('member_card'); | ||
|
||
MongoClient.connect(url, function (err, client) { | ||
assert.equal(null, err); | ||
|
||
var db = client.db('bilibili_spider'); | ||
var db_size = 0; | ||
var db_objects = 0 ; | ||
var db_storageSize = 0; | ||
|
||
msg = getDbStats(db, function() { | ||
client.close(); | ||
}); | ||
}); | ||
|
||
setInterval( | ||
db.stats(function () { | ||
console.log(arguments); | ||
db_size = arguments[1].dataSize/1024/1024/1024; | ||
dbit("数据库大小:" + db_size.toString().substring(0,5) + "G;"); | ||
db_storageSize = arguments[1].storageSize/1024/1024/1024; | ||
dbit("存储空间:" + db_storageSize.toString().substring(0,5) + "G;"); | ||
db_objects = arguments[1].objects; | ||
dbit("用户数:" + db_objects+";"); | ||
}), | ||
600000); | ||
|
||
|
||
|
||
function dbit(elem) { | ||
dbhtml.innerHTML += "<span class='db-span'>"+elem+"</span>"; | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.