Commit 57d157f62464dc5c12520c28c5bb9bdd250bc737
1 parent
50743446
Exists in
master
add stats post
Showing
5 changed files
with
31 additions
and
9 deletions
Show diff stats
controllers/preference/index.js
@@ -34,13 +34,23 @@ router.get('/:collection',async function (req, res,next) { | @@ -34,13 +34,23 @@ router.get('/:collection',async function (req, res,next) { | ||
34 | }); | 34 | }); |
35 | 35 | ||
36 | router.post('/:collection',async function (req, res,next) { | 36 | router.post('/:collection',async function (req, res,next) { |
37 | - start(req) | ||
38 | - var collection = req.params.collection; | 37 | + var cmd = req.params.collection; |
39 | 38 | ||
40 | - var query = req.body; | ||
41 | - var result = await connection.reqMongo(req,req.method,query,collection) | 39 | + var checkStart = start(req,cmd); |
40 | + if(checkStart.err) | ||
41 | + { | ||
42 | + var result = checkStart.err; | ||
43 | + end(req,"Unknow"); | ||
42 | 44 | ||
43 | - end(req); | 45 | + }else |
46 | + { | ||
47 | + var collection = req.params.collection; | ||
48 | + | ||
49 | + var query = req.body; | ||
50 | + var result = await connection.reqMongo(req,req.method,query,collection) | ||
51 | + | ||
52 | + end(req,cmd); | ||
53 | + } | ||
44 | res.status(200).json(result); | 54 | res.status(200).json(result); |
45 | next(); | 55 | next(); |
46 | }); | 56 | }); |
package.json
@@ -6,7 +6,8 @@ | @@ -6,7 +6,8 @@ | ||
6 | "scripts": { | 6 | "scripts": { |
7 | "test": "mocha unitTest", | 7 | "test": "mocha unitTest", |
8 | "start": "npm run test && node app.js", | 8 | "start": "npm run test && node app.js", |
9 | - "gentest": "mocha unitTest && NODE_ENV=gentest node app.js" | 9 | + "gentest": "mocha unitTest && NODE_ENV=gentest node app.js", |
10 | + "pull" : "git pull && npm install && pm2 stop hospital && pm2 start node app.js --name=hospital " | ||
10 | }, | 11 | }, |
11 | "author": "Source Code", | 12 | "author": "Source Code", |
12 | "license": "ISC", | 13 | "license": "ISC", |
utils/log.js
@@ -228,6 +228,7 @@ logger.detailSqlQuery = function(req,collection,data) | @@ -228,6 +228,7 @@ logger.detailSqlQuery = function(req,collection,data) | ||
228 | logger.detailSqlResult = function(req,collection,data) | 228 | logger.detailSqlResult = function(req,collection,data) |
229 | { | 229 | { |
230 | logger4jDetail.info(logPrefix(req)+"BE Receive Mongo Collection: \""+collection+"\" Result: "+JSON.stringify(data)); | 230 | logger4jDetail.info(logPrefix(req)+"BE Receive Mongo Collection: \""+collection+"\" Result: "+JSON.stringify(data)); |
231 | + | ||
231 | } | 232 | } |
232 | 233 | ||
233 | logger.detailRequestBE = function(req,data) | 234 | logger.detailRequestBE = function(req,data) |
utils/mongoDB.js
1 | const log = require('./log'); | 1 | const log = require('./log'); |
2 | +const stat = require('./stats'); | ||
2 | var constants = require('./constants'); | 3 | var constants = require('./constants'); |
3 | var MongoClient = require('mongodb').MongoClient; | 4 | var MongoClient = require('mongodb').MongoClient; |
4 | var config = require('./config'); | 5 | var config = require('./config'); |
@@ -18,10 +19,20 @@ connection.reqMongo = async function (req,method, query, collection) { | @@ -18,10 +19,20 @@ connection.reqMongo = async function (req,method, query, collection) { | ||
18 | 19 | ||
19 | function mongoReq(req,url,database,method, query, collection){ | 20 | function mongoReq(req,url,database,method, query, collection){ |
20 | 21 | ||
22 | + | ||
21 | var nodeName = "MongoDB"; | 23 | var nodeName = "MongoDB"; |
22 | var funStats = { | 24 | var funStats = { |
23 | - detailSqlQuery : function(query){log.detailSqlQuery(req,collection,query);}, | ||
24 | - detailSqlResult : function(result, err){log.detailSqlResult(req,collection,result || err);}, | 25 | + detailSqlQuery : function(query){ |
26 | + log.detailSqlQuery(req,collection,query); | ||
27 | + stat.sendQuery(collection); | ||
28 | + }, | ||
29 | + detailSqlResult : function(result, err){ | ||
30 | + log.detailSqlResult(req,collection,result || err); | ||
31 | + if(result) | ||
32 | + stat.receiveQuery(collection); | ||
33 | + else | ||
34 | + stat.receiveBadQuery(collection); | ||
35 | + }, | ||
25 | addSuccessSummary : function(result){log.addSuccessSummary(req,nodeName,collection,result);}, | 36 | addSuccessSummary : function(result){log.addSuccessSummary(req,nodeName,collection,result);}, |
26 | addErrorSummary : function(result){log.addErrorSummary(req,nodeName,collection,result);} | 37 | addErrorSummary : function(result){log.addErrorSummary(req,nodeName,collection,result);} |
27 | }; | 38 | }; |
utils/stats.js
1 | var config = require('./config'); | 1 | var config = require('./config'); |
2 | var log = require('./log.js'); | 2 | var log = require('./log.js'); |
3 | -var constants = require('./constants.js'); | ||
4 | 3 | ||
5 | var nodeName = config.get("appName"); | 4 | var nodeName = config.get("appName"); |
6 | var stat = []; | 5 | var stat = []; |