yach.util.bpit
v0.1.8
Published
bpit upload elk data
Downloads
3
Readme
安装
npm i yach.util.bpit
使用
浏览器使用
<!-- 引入 -->
<script src="node_modules/yach.util.bpit/dist/yach.util.bpit.b.js"></script>
<!-- 使用 -->
window.bpitCommonDataLog(options);
npm使用
// 引入
var bpitCommonData = require('yach.util.bpit');
// 使用
bpitCommonData.log(options);
options
公用
|key|必填|备注|举例| |------|------|------|------| |group|是|项目组|yach| |project|是|项目名|yach_86_index| |env|是|环境|dev,test,pre,online| |version|是|版本|yach端内上传yach端版本,其他上传业务版本| |yachid|否|yach用户id| |workcode|否|工号|
页面响应时间
|key|必填|备注|举例| |------|------|------|------| |page|否|页面|index| |time|否|响应时间|100|
接口响应时间
|key|必填|备注|举例| |------|------|------|------| |api|否|api地址|/ucenter/user/login| |time|否|响应时间|100|
页面响应时间示例1:js库类的应用
在html的head中记录页面开始加载时间
<script type="text/javascript">
window.bpit_elk_page_start_time = (new Date()).getTime();
</script>
在body末尾适当位置记录结束时间
<script src="node_modules/yach.util.bpit/dist/yach.util.bpit.b.js"></script>
<script>
if(window.bpit_elk_page_start_time){
var end_time = (new Date()).getTime();
var load_time = end_time - window.bpit_elk_page_start_time;
window.bpitCommonDataLog({
group : 'yach',
project : 'yach_86_index',
env : 'online',
page : 'index',
time : load_time,
yachid : '123',
workcode: '123',
version : '0.0.1'
});
}
</script>
页面响应时间示例2:react类的应用
在html的head中记录页面开始加载时间
<script type="text/javascript">
window.bpit_elk_page_start_time = (new Date()).getTime();
</script>
在页面渲染完成后计算页面加载时间(componentDidMount)
var bpitCommonData = require('yach.util.bpit');
componentDidMount(){
if(window.bpit_elk_page_start_time){
var end_time = (new Date()).getTime();
var load_time = end_time - window.bpit_elk_page_start_time;
bpitCommonData.log({
group : 'yach',
project : 'yach_86_index',
env : 'online',
page : 'index',
time : load_time,
yachid : '123',
workcode: '123',
version : '0.0.1'
});
}
}
接口响应时间示例1:js库类应用-ajax请求接口
<script src="node_modules/yach.util.bpit/dist/yach.util.bpit.b.js"></script>
<script>
// 在请求开始时记录开始时间
var bpit_elk_api_start_time = (new Date()).getTime();
// ajax请求
ajax...
// 在请求结束时计算请求响应时间
if(bpit_elk_api_start_time){
var end_time = (new Date()).getTime();
var load_time = end_time - bpit_elk_api_start_time;
window.bpitCommonDataLog({
group : 'yach',
project : 'yach_86_index',
env : 'online',
api : '/ucenter/user/login',
time : load_time,
yachid : '123',
workcode: '123',
version : '0.0.1'
});
}
</script>
接口响应时间示例2:react类的应用-ajax请求接口
var bpitCommonData = require('yach.util.bpit');
// 在请求开始时记录开始时间
var bpit_elk_api_start_time = (new Date()).getTime();
// ajax请求
ajax...
// 在请求结束时计算请求响应时间
if(bpit_elk_api_start_time){
var end_time = (new Date()).getTime();
var load_time = end_time - bpit_elk_api_start_time;
bpitCommonData.log({
group : 'yach',
project : 'yach_86_index',
env : 'online',
api : '/ucenter/user/login',
time : load_time,
yachid : '123',
workcode: '123',
version : '0.0.1'
});
}
接口响应时间示例3:nodejs
封装request方法,在这个方法内计算接口响应时间
/**
* post
*/
qiao.post = async function(options){
// api start
var api_start_time = (new Date()).getTime();
// api
var item = await qiao.ajax.postSync(options);
// api end
var api_end_time = (new Date()).getTime();
var load_time = api_end_time - api_start_time;
qiao.log({
group : 'yach',
project : 'yach_86_index',
env : qiao.config.env,
api : qiao.configServer.url.getVersion,
time : load_time,
yachid : '123',
workcode: '123',
version : '0.0.1'
});
return item;
};
数据打点,异步请求无需等待结果
/**
* log
*/
qiao.log = function(options){
// upload data
var uploadData = ["https://es.zhiyinlou.com/log.js?"];
uploadData.push("group=" + options.group);
uploadData.push("&project=" + options.project);
uploadData.push("&env=" + options.env);
// api load time
if(options.api && options.time){
uploadData.push("&api=" + options.api);
uploadData.push("&load_time=" + options.time);
}
var uploadDataUrl = uploadData.join('');
qiao.ajax.get({url : uploadDataUrl});
console.log(uploadDataUrl);
};
version
0.0.8.20201224
- add universal
- rename to yach.util.bpit from bpit.common.data
0.0.7.20200521
- add agora
0.0.6.20200513
- add os
0.0.5.20200329
- add version
0.0.4.20200318
- add yachid
- add workcode
0.0.3.20200114
- publish
- del log
0.0.2.20191230
- load_time --> time
- modify readme.md
- add api load time
- md
0.0.1.20191219
- init
- modify readme.md
- add dist