Skip to content

Commit

Permalink
Merge pull request #13 from uupers/nodeapp
Browse files Browse the repository at this point in the history
added database stats to the app
  • Loading branch information
emptymalei authored Feb 25, 2018
2 parents 744a0fe + 4a2f03b commit c8efd9b
Show file tree
Hide file tree
Showing 6 changed files with 177 additions and 131 deletions.
14 changes: 13 additions & 1 deletion app/assets/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,19 @@
}

#log-pre {
height: auto;
height: 200px;
max-height: 200px;
min-height: 200px;
overflow: auto
}


#data-html {
height: 200px;
max-height: 200px;
min-height: 200px;
overflow: auto
}
.db-span {
display: block;
}
46 changes: 22 additions & 24 deletions app/assets/mongo.js
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>";
}
39 changes: 0 additions & 39 deletions app/assets/vue-app.js

This file was deleted.

38 changes: 15 additions & 23 deletions app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,33 +40,25 @@ <h1 class="title is-1">
</div>
</div>
</section>

<section>
<div id="log-pre">
<span class="tag is-light">LOG:</span>
<pre id="log-process">

<section>
<div class="columns is-mobile">
<div class="column is-two-thirds" id="log-pre">
<span class="tag is-light">LOG:</span>
<pre id="log-process"></pre>
</div>

<div class="column" id="data-html">
<span class="tag is-light">Database:</span>
<pre id="db-info"></pre>
</div>
</div>
</section>

</pre>
</div>
</section>

<!-- <section>
<div>
<span class="tag is-light">Database:</span>
<div id="data-html">
{{ loaded }}
</div>
</div>
</section> -->



<script src = "./assets/vue/vue.min.js" ></script>
<script src = "./bilicrawler.js" ></script>
<!-- <script src = "./assets/mongo.js" ></script> -->
<!-- <script src = "./assets/vue-app.js" ></script> -->
<script src = "./assets/mongo.js" ></script>
<script>
// You can also require other files to run in this process
require('./renderer.js')
Expand Down
Loading

0 comments on commit c8efd9b

Please sign in to comment.