2016-08-19 8 views
0

MongoDBが最後の1時間に読み込みに対して行った書き込み回数を把握する必要があります。MongDBレベルの書き込み回数

アラームを作成するために必要なこれらの統計情報を簡単に見つける方法はありますか?ソリューションがコマンド駆動型またはJavaベースの場合は、本当に便利です。

+0

あなたはどのような問題を解決しようとしていますか? – profesor79

+0

DBの統計情報を返すためのいくつかのコマンドを見てください。https://docs.mongodb.com/manual/administration/monitoring/ – yellowB

+0

これはプログラミング上の問題よりもデータベース管理上の問題ですか? http://dba.stackexchange.com/であなたが望む答えが見つかるかもしれません。 –

答えて

0

MongoDB jdbcドライバのソースコードを掘り起こした後。私はついに必要なものを手に入れることができました。以下はそのコードです

public class MongoJmxStat { 

    private MongoClient mongo; 

    public MongoJmxStat(MongoClient mongo) { 
     this.mongo = mongo; 
    } 

    public CommandResult getServerStatus() { 
     CommandResult result = getDb("mongoDB").command("serverStatus"); 
     if (!result.ok()) { 

      throw new MongoException("could not query for server status. Command Result = " + result); 
     } 

     return result; 
    } 

    public DB getDb(String databaseName) { 
     return MongoDbUtils.getDB(mongo, databaseName); 
    } 

    private int getOpCounter(String key) { 
     DBObject opCounters = (DBObject) getServerStatus().get("opcounters"); 
     return (Integer) opCounters.get(key); 
    } 

    @ManagedMetric(metricType = MetricType.COUNTER, displayName = "Write operation count") 
    public int getWriteCount() { 
     return getOpCounter("insert") + getOpCounter("update") + getOpCounter("delete"); 
    } 

    @ManagedMetric(metricType = MetricType.COUNTER, displayName = "Read operation count") 
    public int getReadCount() { 
     return getOpCounter("query") + getOpCounter("getmore"); 
    } 

} 
関連する問題