Commit 0edbbcb6 authored by 智勇's avatar 智勇

statistics 1

parent 86f33567
...@@ -137,8 +137,6 @@ exports.get_db_config = async function () { ...@@ -137,8 +137,6 @@ exports.get_db_config = async function () {
if (db.passwd === default_passwd) { if (db.passwd === default_passwd) {
db.passwd = '' db.passwd = ''
} }
// process.env.TZ = 'Asia/Shanghai';
// db.update_at = db.update_at.toLocaleString()
} }
this.body = db_configs; this.body = db_configs;
} }
...@@ -283,12 +281,25 @@ exports.db_sync = async function () { ...@@ -283,12 +281,25 @@ exports.db_sync = async function () {
try { try {
this.logger.info( this.logger.info(
" active:", "db_sync", {
"namespace:", req.name_space, namespace: req.name_space,
"sync_db_name:", req.sync_db_name, active: "reset_binlog",
"not_delete_business_data:", req.not_delete_business_data, microservice_name: req.sync_db_name,
"use_cache:", req.use_cache, user: `${this.user.name}`,
" user:", this.user); user_email: `${this.user.mail}`,
detail: {
"sync_db_name:": req.sync_db_name,
"not_delete_business_data:": req.not_delete_business_data,
"use_cache:": req.use_cache,
}
})
// " active:", "db_sync",
// "namespace:", req.name_space,
// "sync_db_name:", req.sync_db_name,
// "not_delete_business_data:", req.not_delete_business_data,
// "use_cache:", req.use_cache,
// " user:", this.user);
} catch (error) { } catch (error) {
} }
...@@ -344,17 +355,15 @@ exports.reset_binlog = async function () { ...@@ -344,17 +355,15 @@ exports.reset_binlog = async function () {
} catch (error) { } catch (error) {
} }
try { try {
this.logger.info( this.logger.info(
{ {
active: "reset_binlog",
namespace: req.name_space, namespace: req.name_space,
active: "reset_binlog",
microservice_name: "", microservice_name: "",
user: `${this.user.name}`, user: `${this.user.name}`,
user_email: `${this.user.mail}`, user_email: `${this.user.mail}`,
} }
// "| active:", "reset_binlog", // "| active:", "reset_binlog",
// "| namespace:", req.name_space, // "| namespace:", req.name_space,
// "| microservice_name:", "", // "| microservice_name:", "",
...@@ -363,9 +372,8 @@ exports.reset_binlog = async function () { ...@@ -363,9 +372,8 @@ exports.reset_binlog = async function () {
// "~" // "~"
); );
} catch (error) { } catch (error) {
console.log(error)
} }
} }
exports.binlog_to_sql = async function () { exports.binlog_to_sql = async function () {
......
...@@ -923,7 +923,8 @@ exports.reload_mq = async function () { ...@@ -923,7 +923,8 @@ exports.reload_mq = async function () {
this.logger.info( this.logger.info(
"namespace:", this.request.body.host, "namespace:", this.request.body.host,
" active:", "reload_mq", " active:", "reload_mq",
" user:", this.user); " user:", this.user
);
} catch (error) { } catch (error) {
} }
...@@ -1060,9 +1061,16 @@ exports.flush_redis = async function () { ...@@ -1060,9 +1061,16 @@ exports.flush_redis = async function () {
try { try {
this.logger.info( this.logger.info(
"namespace:", req.namespace, {
" active:", "flush_redis", namespace: req.namespace,
" user:", this.user); active: "flush_redis",
user: `${this.user.name}`,
user_email: `${this.user.mail}`,
}
// "namespace:", req.namespace,
// " active:", "flush_redis",
// " user:", this.user
);
} catch (error) { } catch (error) {
} }
......
let readline = require('readline');
let fs = require('fs');
exports.get = async function () {
let rl = readline.createInterface({
input: fs.createReadStream('logs/access.log')
});
let log = '', logs = [], time, namespace, active
rl.on('line', (line) => {
log = log + line
logs = log.split('~')
// for (let _log of logs) {
// time = _log.substring(1, 24)
// console.log(11, _log)
// namespace = _log.substring(_log.indexOf("{"), _log.indexOf("}") + 1)
// _log = _log.substring(_log.indexOf("}") + 1)
// console.log(22, _log)
// active = _log.split(":")[1]
// console.log(active)
// }
this.body = {
code: "0000", data: logs
}
})
}
exports.get_log = async function () {
await this.bindDefault();
let item = await this.mongo("statisticslog").getLog(this.request.body);
this.body = item
return
}
\ No newline at end of file
'use strict'; 'use strict';
// model名称,即表名 // model名称,即表名
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
exports.model = 'dbconfig'; exports.model = 'dbconfig';
// 表结构 // 表结构
......
exports.model = 'statisticslog';
exports.schema = [{
}, {
autoIndex: false,
versionKey: false
}];
exports.methods = {
getLog: async function (query, sort) {
if (query.namespace || query.namespace === '') {
query.namespace = new RegExp(query.namespace);
}
if (query.active || query.active === '') {
query.active = new RegExp(query.active);
}
if (query.microservice_name || query.microservice_name === '') {
query.microservice_name = new RegExp(query.microservice_name);
}
return await this.model("statisticslog").find(query).sort(sort)
}
}
\ No newline at end of file
'use strict'; 'use strict';
var extend = require('extend');
const path = require('path'); const path = require('path');
const koa = require('koa'); const koa = require('koa');
const Middles = require('../middleware/') const Middles = require('../middleware/')
var request = require('request'); var request = require('request');
var log4js = require('log4js'); var log4js = require('log4js');
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
let session = {}; let session = {};
const app = new koa(); const app = new koa();
...@@ -15,25 +17,56 @@ log4js.configure({ ...@@ -15,25 +17,56 @@ log4js.configure({
const _logger = log4js.getLogger('cheese'); const _logger = log4js.getLogger('cheese');
var StatisticsSchema = new Schema({
namespace: String,
active: String,
microservice_name: String,
user: String,
user_mail: String,
detail: String,
create_time: Date
});
// mongo 链接操作。 moogose // mongoose.connect('mongodb://192.168.28.179:27017/qaHome')
mongoose.connect('mongodb://172.30.220.22:27017/qaHome')
var StatisticsLogModel = mongoose.model('StatisticsLog', StatisticsSchema);
var logger = { var logger = {
info: ()=>{ info: (...args) => {
// mongo操作 // mongo操作
let _log = {
_logger.info(arguments) namespace: "",
},debug: ()=>{ active: "",
microservice_name: "",
user: "",
user_mail: "",
detail: "",
create_time: new Date()
}
if (typeof args[0] === "string") {
console.log(1111)
_logger.info(args)
} else {
console.log(222)
extend(_log, args[0]);
var log = new StatisticsLogModel(_log)
log.save(function (err) {
if (err) {
console.log('save error:' + err);
}
console.log('save sucess');
});
_logger.info(_log)
}
}, debug: () => {
// mongo操作 // mongo操作
_logger.debug(arguments) _logger.debug(arguments)
},error: () =>{ }, error: () => {
// mongo操作 // mongo操作
_logger.error(arguments) _logger.error(arguments)
} }
}; };
// compress(gzip) // compress(gzip)
app.use(Middles.compress()); app.use(Middles.compress());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment