Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add ckv report #167

Merged
merged 3 commits into from
Jul 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bin/tsw/api/tnm2/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@


const serverInfo = require('serverInfo.js');
const mapping = require('./mapping.json');
const mapping = require('api/tnm2/mapping.json');
const url = require('url');
const Deferred = require('util/Deferred');
const cluster = require('cluster');
Expand Down
4 changes: 4 additions & 0 deletions bin/tsw/api/tnm2/mapping.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@
"SUM_TSW_WEBSOCKET_ERROR" : 1253122,
"SUM_TSW_WEBSOCKET_CLOSE" : 1253126,

"SUM_TSW_CKV_CMD" : 1253127,
"AVG_TSW_CKV_QUEUE_COST" : 1253128,
"AVG_TSW_CKV_CMD_COST" : 1253129,

"AVG_TSW_CPU_LOAD_1" : 1280713,
"AVG_TSW_CPU_LOAD_5" : 1280714,
"AVG_TSW_CPU_LOAD_15" : 1280716,
Expand Down
9 changes: 9 additions & 0 deletions bin/tsw/pool/cmem.l5.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
const logger = require('logger');
const Queue = require('util/Queue');
const dcapi = require('api/libdcapi/dcapi.js');
const tnm2 = require('api/tnm2');
const L5 = require('api/L5/L5.api.js');
const { isWin32Like } = require('util/isWindows.js');
let cache = global[__filename];
Expand Down Expand Up @@ -83,7 +84,13 @@ function queueWrap(memcached) {
const servers = memcached.servers && memcached.servers[0];
const start = Date.now();

tnm2.Attr_API('SUM_TSW_CKV_CMD', 1);

queue.queue(function() {
const startQueue = Date.now();
const costQueue = startQueue - start;

tnm2.Attr_API_Set('AVG_TSW_CKV_QUEUE_COST', costQueue);

const fn = (function(queryCompiler) {
return function() {
Expand Down Expand Up @@ -119,6 +126,8 @@ function queueWrap(memcached) {
}
}

tnm2.Attr_API_Set('AVG_TSW_CKV_CMD_COST', Date.now() - startQueue);

dcapi.report({
key: 'EVENT_TSW_MEMCACHED',
toIp: toIp,
Expand Down
13 changes: 7 additions & 6 deletions bin/tsw/util/h5-test/add.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ module.exports.addTestUser = function(uin, val) {
logger.debug('addTestUser:' + uin);
val = val || true;
const memcached = isTest.cmem();
let keyText = isTest.keyBitmap();
const defer = Deferred.create();
let appid = '';
const appid = context.appid || '';
const appkey = context.appkey;
let keyText = isTest.keyBitmap();

if (context.appid && context.appkey) {
if (appid && appkey) {
// 开平过来的
appid = context.appid;
keyText = `${keyText}.${appid}`;
}

Expand All @@ -76,11 +76,12 @@ module.exports.addTestUser = function(uin, val) {
return defer.reject('memcached not exists');
}


memcached.get(keyText, function(err, data) {

if (appid && typeof data === 'string') {
// 解密
data = post.decode(context.appid, context.appkey, data);
data = post.decode(appid, appkey, data);
}

const expire = 24 * 60 * 60;
Expand All @@ -104,7 +105,7 @@ module.exports.addTestUser = function(uin, val) {

if (appid) {
// 加密
text = post.encode(context.appid, context.appkey, text);
text = post.encode(appid, appkey, text);
}

memcached.set(keyText, text, expire, function(err, ret) {
Expand Down
10 changes: 5 additions & 5 deletions bin/tsw/util/h5-test/del.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@ const returnJson = function(json) {
module.exports.deleteTestUser = function(uin) {
logger.debug('deleteTestUser:' + uin);
const memcached = isTest.cmem();
let keyText = isTest.keyBitmap();
const defer = Deferred.create();
let appid = '';
const appid = context.appid || '';
const appkey = context.appkey;
let keyText = isTest.keyBitmap();

if (!uin) {
return defer.reject();
Expand All @@ -66,7 +67,6 @@ module.exports.deleteTestUser = function(uin) {

if (context.appid && context.appkey) {
// 开平过来的
appid = context.appid;
keyText = `${keyText}.${appid}`;
}

Expand All @@ -78,7 +78,7 @@ module.exports.deleteTestUser = function(uin) {

if (appid && typeof data === 'string') {
// 解密
data = post.decode(context.appid, context.appkey, data);
data = post.decode(appid, appkey, data);
}

const expire = 24 * 60 * 60;
Expand All @@ -104,7 +104,7 @@ module.exports.deleteTestUser = function(uin) {

if (appid) {
// 加密
text = post.encode(context.appid, context.appkey, text);
text = post.encode(appid, appkey, text);
}

memcached.set(keyText, text, expire, function(err, ret) {
Expand Down
10 changes: 5 additions & 5 deletions bin/tsw/util/h5-test/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ module.exports.getTestUser = function() {

// 从内存中读取testTargetMap
const memcached = isTest.cmem();
let keyText = isTest.keyBitmap();
const defer = Deferred.create();
let appid = '';
const appid = context.appid || '';
const appkey = context.appkey;
let keyText = isTest.keyBitmap();

if (context.appid && context.appkey) {
if (appid && appkey) {
// 开平过来的
appid = context.appid;
keyText = `${keyText}.${appid}`;
}

Expand All @@ -55,7 +55,7 @@ module.exports.getTestUser = function() {

if (appid && typeof data === 'string') {
// 解密
data = post.decode(context.appid, context.appkey, data);
data = post.decode(appid, appkey, data);
}

if (err) {
Expand Down