簡體   English   中英

MongoDB搜索查詢統計信息

[英]MongoDB search query for stats

我在MongoDB中有一個事件集合,其中包含一些HTTP請求信息。 我想知道是否有一種方法可以根據特定的“路徑”值找到反應最強烈的“測功機”。 例如,對於“ random_path_users”,對於這種特定類型的請求,我想找到其“ dyno”值,其計數值優於其他dyno。

{"_id"=>BSON::ObjectId('54738b3ff572e27e6b4b2a3b'), "method"=>"GET", "path"=>"users_count_pending_msg", "dyno"=>"web.1", "connect"=>1, "service"=>10}
{"_id"=>BSON::ObjectId('54738b3ff572e27e6b4b2a3c'), "method"=>"GET", "path"=>"users_count_pending_msg", "dyno"=>"web.1", "connect"=>6, "service"=>13}
{"_id"=>BSON::ObjectId('54738b3ff572e27e6b4b2a3d'), "method"=>"GET", "path"=>"users_get_score", "dyno"=>"web.5", "connect"=>3, "service"=>155}
{"_id"=>BSON::ObjectId('54738b3ff572e27e6b4b2a3e'), "method"=>"GET", "path"=>"users_get_msg", "dyno"=>"web.10", "connect"=>1, "service"=>32}
{"_id"=>BSON::ObjectId('54738b3ff572e27e6b4b2a53'), "method"=>"POST", "path"=>"random_path_users", "dyno"=>"web.3", "connect"=>3, "service"=>55}
{"_id"=>BSON::ObjectId('54738b3ff572e27e6b4b2a54'), "method"=>"GET", "path"=>"random_path_users", "dyno"=>"web.10", "connect"=>1, "service"=>45}
{"_id"=>BSON::ObjectId('54738b3ff572e27e6b4b2a55'), "method"=>"GET", "path"=>"users_get_msg", "dyno"=>"web.10", "connect"=>2, "service"=>41}
{"_id"=>BSON::ObjectId('54738b3ff572e27e6b4b2a56'), "method"=>"POST", "path"=>"random_path_users", "dyno"=>"web.3", "connect"=>2, "service"=>31}
{"_id"=>BSON::ObjectId('54738b3ff572e27e6b4b2a57'), "method"=>"GET", "path"=>"users_count_pending_msg", "dyno"=>"web.11", "connect"=>1, "service"=>232}
{"_id"=>BSON::ObjectId('54738b3ff572e27e6b4b2a58'), "method"=>"POST", "path"=>"api_users", "dyno"=>"web.4", "connect"=>3, "service"=>37}
{"_id"=>BSON::ObjectId('54738b3ff572e27e6b4b2a59'), "method"=>"GET", "path"=>"users_count_pending_msg", "dyno"=>"web.6", "connect"=>0, "service"=>10}

使用聚合框架:

db.events.aggregate([
    { "$match" : { "path" : "random_path_users" } },
    { "$group" : { "_id" : "$dyno", "count" : { "$sum" : 1 } } },
    { "$sort" : { "count" : -1 } },
    { "$limit" : 1 }
])

這將返回的值dyno與所有請求中請求的最大數path等於“random_path_users”。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM