您的位置:首页 > 其它

行情分发节点信息统计(登陆人数, 合约数)

2014-05-30 16:54 309 查看
h2. 需求

* 实时统计行情分发节点的登录人数

* 以图形形式显示所有行情分发节点登陆人数总和以及

单个行情分发节点上登陆的人数

* 以图形形式现实所有行情节点带宽消耗

h2. 方案

* 行情分发节点之间一个搭建rabbit-mq节点

* 客户端连接行情分发节点时向rabbit-mq节点发送连接消息 {connetced, Login, Node, Time}

* 客户端断线时向rabbit-mq节点发送断开消息 {disconnected, Login, Node, Time}

* bigwig订阅rabbitmq,并统计各个行情分发节点的人数变化和订阅合约数量变化发送到页面(websocket)

* 页面获取websocket数据,并以Stacked column和basic area图形动态显示.

* 每天24点,页面清空,显示新一天的数据.

<pre>

{ok, Timer} = timer:send_after(EndTime, clear_charts),

{ok, #state{node_client_instrument_count = orddict:new(),

timer = Timer}}.

</pre>

* 稳定性问题

* market_dispatcher将小时用户数和合约订阅数保存在本地mnesia数据库。market_dispatcher重启时需要从mnesia load当天的统计数据

* market_dispatcher进程保存本节点的总人数和合约总订阅数目,并将总人数发送到rabbit-mq

* market_auth 重启,需要重新向rabbit-mq重新订阅统计信息

h2. 实现

* 在market_dispatch_subscribe_handler中订阅和退订的方法内调用market_subscriber_statistic模块的

on_subscribe和on_unsubscribe

<pre>

process_action(?MARKET_SUB, InstrumentIds, #state{session = Session})

process_action(?MARKET_UNSUB, [], #state{session = Session})

</pre>

* market_dispatcher中增加 market_subscriber_statistic 模块

* on_connected(Access): 向rabbitmq发送 {connected, Node, Time} (RoutingKey = <<"md_stat">>)

* on_disconnected(Access): 向rabbitmq发送 {disconnected, Node, Time}

* on_subscribe(Access): 向rabbitmq节点发送消息 {subscribe, Node, Time, Count} (Count为订阅和退订合约的数量)

* on_unsubscribe(Access): 向rabbit-mq节点发送消息 {unsubscribe, Node, Time, Count}

* market_auth中增加 market_dispatcher_amqp_subscriber 模块, http_md_stream.erl模块, http_md_statistic模块

* market_dispatcher_amqp_subscriber: 从rabbitmq接受消息,并进行统计,将数据存入orddict. (RoutingKey = <<"md_stat">>)

* node_count: {Node, Time, ClientCount, InstrumentCount}

* handle_info(clear_charts, #state{} = State)

* http_md_statistic.erl: 获取当前时间及当天之前时段的统计信息

* GET /md/statistic

* 消息格式 [[MDNode, Time, ClientCount, InstrumentCount]|...] (MDNode由原来的node()改为 market_dispatcher record 中的id)

* http_md_stream.erl: 将当前时间统计信息用websocket方式发送到浏览器

* 消息格式 [MDNode, Time, ClientCount, InstrumentCount] (MDNode由原来的node()改为 market_dispatcher record 中的id)

* websocket url: ws://localhost/md/stream

h2. 资源

* Charts 效果: http://www.highcharts.com/demo/column-stacked
* charts获取数据: http://www.highcharts.com/docs/working-with-data/preprocessing-live-data
* http://www.blueflame-software.com/blog/demo/stacked-column-chart-with-data-from-mysql-using-highcharts/
* http://jsfiddle.net/cspider/uNvnH/
h2. 待考虑问题

* rabbit-mq 重启

* market_dispatcher 重启

* market_auth 重启
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐