开发分布式网络监控分析之前端ajax展现那些事

简介:

周六自己在家甚是无聊,看到朋友们在讨论分布式监控分析,要的效果是 阿里测,17ce那种形式的,想查询监控啥的时候,在一个页面上能看到所以监控点提供的数据。比如,我想要查询针对一个url的get,dig数据。在这边直接采用zabbix、nagios的数据不太合理,因为我想要是给客服和客户用的界面。 像zabbix这样,咱们只能是提前先配置好。




以前做过类似的全网监控检测,但是做的有些简陋,但也和这次聊的话题不一样,有兴趣的朋友可以看看以前的我写的关于大屏幕开发的文章。 http://rfyiamcool.blog.51cto.com/1030776/1302398


本来以为不算难的东西,只要我从前端把你要查询的节点数据给后端,然后用table展现不就行了。 自己写demo的时候,遇见了不少的问题。


真正做的时候,我发现浏览器是有线程并发限制的,firefox是6个,chrome也是6个,ie 6/7 是2个吧 。ie8 才是6个。


wKiom1M_YDfAvKUtAADdcq2q7kM852.jpg


firefox的修改线程的方式,这里是告诉大家,这东西是可以改的。 但是对于客户来说,你不能老让他改呀。  

1
2
3
4
5
6
// if network.http.keep-alive is true, and if NOT connecting via a proxy, then
pref( "network.http.m camerabagss.us a x-persistent-connections-per-server" 6 );
// if network.http.keep- camerabagss.us a live is true,  camerabagss.us a nd if connecting vi camerabagss.us a   camerabagss.us a  proxy, then  camerabagss.us a
// new connection will only be  camerabagss.us a ttempted if the number of  camerabagss.us a ctive persistent
// connections to the proxy is less then m camerabagss.us a x-persistent-connections-per-proxy.
pref( "network.http.max-persistent-connections-per-proxy" 8 );



一开始我的做法是、从这个页面确定用户要查询的监控节点。然后each遍历数据,ajax 异步执行。但这个时候,我前面说的线程数超过6个后,后面的任务会堵塞,这个堵塞会总是浏览器的崩溃。  

wKiom1NDbqaTeWN-AAQaf1WjEUY073.jpg


不能让用户改线程数,不改的话,浏览器会卡掉的。不知道用websocket的方式,能不能突破浏览器的限制,以前做websockek都是分段提供的数据,一下子超过6条的堵塞数据,还真没有尝试过。


这个是刚才写的例子,li模拟了100个,结果很很卡。数据的返回是每次6个 。


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<script type= "text/javascript" >
$(document).ready( function (){
           $( "[ id = nima ]" ).click( function (){
                 $( "[ id =kk] li" ). each ( function (){
  //                   alertify.log($(this).text())
                          zhi=$( this ).text();
                          $.ajax({
                              type:  "POST" ,
                              url:  "/queue" ,
                              data : { 'key' :zhi},
                              async: true ,
                              error:  function (){
                                      alert( 'nima' );
                              },
                              success:  function (data,status){
                                      alertify.log(data);
                              }
                          });
                                                                                                                                                                                                                                                                                                                                                                                                              
                 });
            });
   });
</script>


原文:http://rfyiamcool.blog.51cto.com/1030776/1390890

wKioL1M_Yi2xSZR3AAENXVNzDYs872.jpg




这个时候看了下别人的做过,他们都是把压力放到了后端。也就是说,我从前边发出了一个请求后,我会每隔一段时间去访问后端的接口,然后把数据渲染后页面上,这里会做相应的判断,已经展现的数据,我就不重复展现了,还没有展现的我继续渲染页面。


wKioL1M_aOHitBqYAANeP0fKZ7k761.jpg


这个是后端接口返回的json数据。


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
{ "url" : "www.youku.com" , "host" : "www.youku.com" , "srcip" : "" , "tid" : "201404_f5d00f83f4ba8ab6fab0df23fc8823a4" , "pre" : "201404" , "type" : 1 , "taskstatus" : "2" , "teststatus" : 1 , "message" : "" , "num" : "5" , "num2" : "5" ,"
xmlfile ":" "," check_time ":" "," freshdata ":{3:{" linkname ":" "," link ":" "," name ":" 上海市电信 "," isp ":" 电信 "," view ":" 上海市 "," sid ":" 3 "," SrcIP ":{" srcip ":" 101.227 . 10.19 "," ipfrom ":" 上海市 电信 "}," IP ":" 61.172 . 249.96 "," HttpCode ":" 200 "," T
otalTime ":" 0 .011s "," NsLookup ":" 0 .001s "," ConnectTime ":" 0 .001s "," downtime ":" 0 .008s "," FileSize ":" 62 .13KB "," realsize ":" 62 .13KB "," speed ":" 7 .349MB\/s "," HpptHead ":" HTTP\/ 1.0  200  OK\r<br>Expires: Sat,  05  Apr  2014  01 : 26 : 18  GMT\r<br>Cache-Control: max-age= 120 \r<br>L
ast-Modified: Sat,  05  Apr  2014  01 : 23 : 56  GMT\r<br>ETag: \" 4100116602 \"\r<br>Content-Encoding: deflate\r<br>Content-Type: text\/html\r<br>Vary: Accept-Encoding\r<br>Content-Length:  63621 \r<br>Connection: close\r<br> Date : Sat
05  Apr  2014  01 : 24 : 18  GMT\r<br>Server: jinjingwww01 "},32:{" linkname ":" "," link ":" "," name ":" 厦门市电信 "," isp ":" 电信 "," view ":" 福建省 "," sid ":" 32 "," SrcIP ":{" srcip ":" 183.61 . 116.212 "," ipfrom ":" 广东省广州市 电信 "}," IP ":" 222.76 . 219.7 "," HttpCode ":" 200 "
, "TotalTime" : "0.096s" , "NsLookup" : "0.001s" , "ConnectTime" : "0.018s" , "downtime" : "0.077s" , "FileSize" : "62.13KB" , "realsize" : "62.13KB" , "speed" : "805.166KB\/s" , "HpptHead" :"HTTP\/ 1.0  200  OK\r<br>Expires: Sat,  05  Apr  2014  01 : 26 : 18  GMT\r<br>Cache-Control: max-age= 120 \
r<br>Last-Modified: Sat,  05  Apr  2014  01 : 23 : 56  GMT\r<br>ETag: \" 1533679214 \"\r<br>Content-Encoding: deflate\r<br>Content-Type: text\/html\r<br>Vary: Accept-Encoding\r<br>Content-Length:  63621 \r<br>Connection: close\r<br> Date : Sat,  05  Apr  2014  01 : 24 : 18  GMT\r<br>Server:
gzwww5 "},665:{" linkname ":" "," link ":" "," name ":" 安徽移动 "," isp ":" 移动 "," view ":" 安徽省 "," sid ":" 665 "," SrcIP ":{" srcip ":" 221.181 . 195.121 "," ipfrom ":" 江苏省常州市 移动 "}," IP ":" 120.209 . 138.81 "," HttpCode ":" 200 "," TotalTime ":" 0 .052s "," NsLookup ":" 0 .001s "," ConnectTime ":" 0 .008s "," d
owntime ":" 0 .043s "," FileSize ":" 62 .13KB "," realsize ":" 62 .13KB "," speed ":" 1 .401MB\/s "," HpptHead ":" HTTP\/ 1.0  200  OK\r<br>Expires: Sat,  05  Apr  2014  01 : 26 : 18  GMT\r<br>Cache-Control: max-age= 120 \r<br>Last-Modified: Sat,  05  Apr  2014  01 : 23 : 56  GMT\r<br>ETag: \" 1952045240 \"\r<br
>Content-Encoding: deflate\r<br>Content-Type: text\/html\r<br>Vary: Accept-Encoding\r<br>Content-Length:  63621 \r<br>Connection: close\r<br> Date : Sat,  05  Apr  2014  01 : 24 : 18  GMT\r<br>Server: nj_mob_www_3 "},250:{" linkname ":" "," link ":" "," name ":" 滁州市双线 "," isp ":" 电信联通 "," view ":" 安徽省 "," sid ":" 250
"," SrcIP ":{" srcip ":" 116.211 . 115.228 "," ipfrom ":" 湖北省 电信 "}," IP ":" 27.54 . 247.9 "," HttpCode ":" 200 "," TotalTime ":" 0 .132s "," NsLookup ":" 0 .072s "," ConnectTime ":" 0 .014s "," downtime ":" 0 .046s "," FileSize ":" 62 .13KB "," realsize ":" 62 .13KB "," speed ":" 1 .327MB\/s "," HpptHead ":" HTTP\/ 1.0  200  OK\r<br>Expires: Sat,  05  A
pr  2014  01 : 26 : 18  GMT\r<br>Cache-Control: max-age= 120 \r<br>Last-Modified: Sat,  05  Apr  2014  01 : 23 : 56  GMT\r<br>ETag: \" 4217557738 \"\r<br>Content-Encoding: deflate\r<br>Content-Type: text\/html\r<br>Vary: Accept-Encoding\r<br>Content-Length:  63621 \r<br>Connection: close\r<br> Date : Sat,  05  Apr  2014  01 : 2
4 : 18  GMT\r<br>Server: whwww5 "},853:{" linkname ":" "," link ":" "," name ":" 东莞市电信 "," isp ":" 电信 "," view ":" 广东省 "," sid ":" 853 "," SrcIP ":{" srcip ":" 183.61 . 116.213 "," ipfrom ":" 广东省广州市 电信 "}," IP ":" 121.12 . 169.41 "," HttpCode ":" 200 "," TotalTime ":" 0 .037s "," NsLookup ":" 0 .003s "," ConnectTime ":" 0 .006s "," downtime ":" 0
.028s "," FileSize ":" 62 .13KB "," realsize ":" 62 .13KB "," speed ":" 2 .187MB\/s "," HpptHead ":" HTTP\/ 1.0  200  OK\r<br>Expires: Sat,  05  Apr  2014  01 : 26 : 18  GMT\r<br>Cache-Control: max-age= 120 \r<br>Last-Modified: Sat,  05  Apr  2014  01 : 23 : 56  GMT\r<br>ETag: \" 1332352621 \"\r<br>Content-Encoding: deflate\r<br>Content-Type:
text\/html\r<br>Vary: Accept-Encoding\r<br>Content-Length:  63621 \r<br>Connection: close\r<br> Date : Sat,  05  Apr  2014  01 : 24 : 18  GMT\r<br>Server: gzwww6"}},
"backdata" :[], "accuracy_backdata" :[], "time_backdata" :[], "speed_backdata" :[], "average_data" :[], "ajax_over" : 0 , "port" : 80 }



原文:http://rfyiamcool.blog.51cto.com/1030776/1390890

总觉得用saltstack也是可以试试的,有时间的朋友可以做些测试。  不用太复杂,用他的模块,提供url的参数就可以了。






 本文转自 rfyiamcool 51CTO博客,原文链接:http://blog.51cto.com/rfyiamcool/1390890 ,如需转载请自行联系原作者

相关文章
|
26天前
|
Linux 开发工具 Android开发
FFmpeg开发笔记(六十)使用国产的ijkplayer播放器观看网络视频
ijkplayer是由Bilibili基于FFmpeg3.4研发并开源的播放器,适用于Android和iOS,支持本地视频及网络流媒体播放。本文详细介绍如何在新版Android Studio中导入并使用ijkplayer库,包括Gradle版本及配置更新、导入编译好的so文件以及添加直播链接播放代码等步骤,帮助开发者顺利进行App调试与开发。更多FFmpeg开发知识可参考《FFmpeg开发实战:从零基础到短视频上线》。
101 2
FFmpeg开发笔记(六十)使用国产的ijkplayer播放器观看网络视频
|
8天前
|
数据采集 缓存 定位技术
网络延迟对Python爬虫速度的影响分析
网络延迟对Python爬虫速度的影响分析
|
1月前
|
机器学习/深度学习 数据采集 存储
时间序列预测新突破:深入解析循环神经网络(RNN)在金融数据分析中的应用
【10月更文挑战第7天】时间序列预测是数据科学领域的一个重要课题,特别是在金融行业中。准确的时间序列预测能够帮助投资者做出更明智的决策,比如股票价格预测、汇率变动预测等。近年来,随着深度学习技术的发展,尤其是循环神经网络(Recurrent Neural Networks, RNNs)及其变体如长短期记忆网络(LSTM)和门控循环单元(GRU),在处理时间序列数据方面展现出了巨大的潜力。本文将探讨RNN的基本概念,并通过具体的代码示例展示如何使用这些模型来进行金融数据分析。
218 2
|
4天前
|
API
鸿蒙开发:切换至基于rcp的网络请求
本文的内容主要是把之前基于http封装的库,修改为当前的Remote Communication Kit(远场通信服务),无非就是通信的方式变了,其他都大差不差。
鸿蒙开发:切换至基于rcp的网络请求
|
24天前
|
运维 供应链 安全
SD-WAN分布式组网:构建高效、灵活的企业网络架构
本文介绍了SD-WAN(软件定义广域网)在企业分布式组网中的应用,强调其智能化流量管理、简化的网络部署、弹性扩展能力和增强的安全性等核心优势,以及在跨国企业、多云环境、零售连锁和制造业中的典型应用场景。通过合理设计网络架构、选择合适的网络连接类型、优化应用流量优先级和定期评估网络性能等最佳实践,SD-WAN助力企业实现高效、稳定的业务连接,加速数字化转型。
SD-WAN分布式组网:构建高效、灵活的企业网络架构
|
9天前
|
存储 安全 网络安全
网络安全法律框架:全球视角下的合规性分析
网络安全法律框架:全球视角下的合规性分析
21 1
|
9天前
|
存储 监控 安全
查看并处理分布式网络中的内部威胁
查看并处理分布式网络中的内部威胁
17 1
|
16天前
|
JavaScript 前端开发 开发者
前端框架对比:Vue.js与Angular的优劣分析与选择建议
【10月更文挑战第27天】在前端开发领域,Vue.js和Angular是两个备受瞩目的框架。本文对比了两者的优劣,Vue.js以轻量级和易上手著称,适合快速开发小型到中型项目;Angular则由Google支持,功能全面,适合大型企业级应用。选择时需考虑项目需求、团队熟悉度和长期维护等因素。
22 1
|
30天前
|
前端开发 JavaScript
回顾前端页面发送ajax请求方式
回顾前端页面发送ajax请求方式
37 18
|
17天前
|
JavaScript 前端开发 API
前端框架对比:Vue.js与Angular的优劣分析与选择建议
【10月更文挑战第26天】前端技术的飞速发展让开发者在构建用户界面时有了更多选择。本文对比了Vue.js和Angular两大框架,介绍了它们的特点和优劣,并给出了在实际项目中如何选择的建议。Vue.js轻量级、易上手,适合小型项目;Angular结构化、功能强大,适合大型项目。
16 1