2010-02-01 16:38:00 +01:00
|
|
|
// counters.h
|
2010-02-09 22:48:21 +01:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2010 10gen Inc.
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License, version 3,
|
|
|
|
* as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2010-04-20 21:05:48 +02:00
|
|
|
#pragma once
|
2010-01-16 06:50:02 +01:00
|
|
|
|
2010-04-27 21:33:27 +02:00
|
|
|
#include "../../pch.h"
|
2010-02-02 02:50:14 +01:00
|
|
|
#include "../jsobj.h"
|
2010-02-01 16:38:00 +01:00
|
|
|
#include "../../util/message.h"
|
|
|
|
#include "../../util/processinfo.h"
|
2010-11-09 06:14:52 +01:00
|
|
|
#include "../../util/concurrency/spin_lock.h"
|
2010-01-16 06:50:02 +01:00
|
|
|
|
|
|
|
namespace mongo {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* for storing operation counters
|
|
|
|
* note: not thread safe. ok with that for speed
|
|
|
|
*/
|
|
|
|
class OpCounters {
|
|
|
|
public:
|
|
|
|
|
|
|
|
OpCounters();
|
|
|
|
|
2010-05-05 22:27:43 +02:00
|
|
|
AtomicUInt * getInsert(){ return _insert; }
|
|
|
|
AtomicUInt * getQuery(){ return _query; }
|
|
|
|
AtomicUInt * getUpdate(){ return _update; }
|
|
|
|
AtomicUInt * getDelete(){ return _delete; }
|
|
|
|
AtomicUInt * getGetMore(){ return _getmore; }
|
|
|
|
AtomicUInt * getCommand(){ return _command; }
|
2010-02-11 18:52:26 +01:00
|
|
|
|
2010-01-16 06:50:02 +01:00
|
|
|
void gotInsert(){ _insert[0]++; }
|
|
|
|
void gotQuery(){ _query[0]++; }
|
|
|
|
void gotUpdate(){ _update[0]++; }
|
|
|
|
void gotDelete(){ _delete[0]++; }
|
|
|
|
void gotGetMore(){ _getmore[0]++; }
|
2010-02-11 18:52:26 +01:00
|
|
|
void gotCommand(){ _command[0]++; }
|
2010-01-16 06:50:02 +01:00
|
|
|
|
2010-02-11 18:52:26 +01:00
|
|
|
void gotOp( int op , bool isCommand );
|
2010-01-16 06:50:02 +01:00
|
|
|
|
2010-11-11 07:30:21 +01:00
|
|
|
BSONObj& getObj();
|
|
|
|
|
2010-01-16 06:50:02 +01:00
|
|
|
private:
|
|
|
|
BSONObj _obj;
|
2010-05-05 22:27:43 +02:00
|
|
|
AtomicUInt * _insert;
|
|
|
|
AtomicUInt * _query;
|
|
|
|
AtomicUInt * _update;
|
|
|
|
AtomicUInt * _delete;
|
|
|
|
AtomicUInt * _getmore;
|
|
|
|
AtomicUInt * _command;
|
2010-01-16 06:50:02 +01:00
|
|
|
};
|
2010-01-28 20:14:47 +01:00
|
|
|
|
2010-01-16 06:50:02 +01:00
|
|
|
extern OpCounters globalOpCounters;
|
2010-11-09 23:01:58 +01:00
|
|
|
extern OpCounters replOpCounters;
|
|
|
|
|
2010-01-16 06:50:02 +01:00
|
|
|
|
2010-01-28 20:14:47 +01:00
|
|
|
class IndexCounters {
|
|
|
|
public:
|
|
|
|
IndexCounters();
|
|
|
|
|
|
|
|
void btree( char * node ){
|
|
|
|
if ( ! _memSupported )
|
|
|
|
return;
|
|
|
|
if ( _sampling++ % _samplingrate )
|
|
|
|
return;
|
|
|
|
btree( _pi.blockInMemory( node ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
void btree( bool memHit ){
|
|
|
|
if ( memHit )
|
|
|
|
_btreeMemHits++;
|
|
|
|
else
|
|
|
|
_btreeMemMisses++;
|
|
|
|
_btreeAccesses++;
|
|
|
|
}
|
|
|
|
void btreeHit(){ _btreeMemHits++; _btreeAccesses++; }
|
|
|
|
void btreeMiss(){ _btreeMemMisses++; _btreeAccesses++; }
|
|
|
|
|
|
|
|
void append( BSONObjBuilder& b );
|
|
|
|
|
|
|
|
private:
|
|
|
|
ProcessInfo _pi;
|
|
|
|
bool _memSupported;
|
|
|
|
|
|
|
|
int _sampling;
|
|
|
|
int _samplingrate;
|
|
|
|
|
|
|
|
int _resets;
|
|
|
|
long long _maxAllowed;
|
|
|
|
|
|
|
|
long long _btreeMemMisses;
|
|
|
|
long long _btreeMemHits;
|
|
|
|
long long _btreeAccesses;
|
|
|
|
};
|
|
|
|
|
|
|
|
extern IndexCounters globalIndexCounters;
|
|
|
|
|
2010-03-15 21:02:24 +01:00
|
|
|
class FlushCounters {
|
|
|
|
public:
|
|
|
|
FlushCounters();
|
|
|
|
|
|
|
|
void flushed(int ms);
|
|
|
|
|
|
|
|
void append( BSONObjBuilder& b );
|
|
|
|
|
|
|
|
private:
|
|
|
|
long long _total_time;
|
|
|
|
long long _flushes;
|
|
|
|
int _last_time;
|
|
|
|
Date_t _last;
|
|
|
|
};
|
|
|
|
|
|
|
|
extern FlushCounters globalFlushCounters;
|
2010-04-20 21:05:48 +02:00
|
|
|
|
|
|
|
|
|
|
|
class GenericCounter {
|
|
|
|
public:
|
2010-05-26 06:46:49 +02:00
|
|
|
GenericCounter() : _mutex("GenericCounter") { }
|
2010-04-20 21:05:48 +02:00
|
|
|
void hit( const string& name , int count=0 );
|
|
|
|
BSONObj getObj();
|
|
|
|
private:
|
|
|
|
map<string,long long> _counts; // TODO: replace with thread safe map
|
|
|
|
mongo::mutex _mutex;
|
|
|
|
};
|
2010-11-09 00:00:02 +01:00
|
|
|
|
|
|
|
class NetworkCounter {
|
|
|
|
public:
|
2010-11-09 06:14:52 +01:00
|
|
|
NetworkCounter() : _bytesIn(0), _bytesOut(0), _requests(0), _overflows(0){}
|
2010-11-09 00:00:02 +01:00
|
|
|
void hit( long long bytesIn , long long bytesOut );
|
2010-11-09 06:14:52 +01:00
|
|
|
void append( BSONObjBuilder& b );
|
2010-11-09 00:00:02 +01:00
|
|
|
private:
|
|
|
|
long long _bytesIn;
|
|
|
|
long long _bytesOut;
|
2010-11-09 06:14:52 +01:00
|
|
|
long long _requests;
|
|
|
|
|
2010-11-09 00:00:02 +01:00
|
|
|
long long _overflows;
|
2010-11-09 06:14:52 +01:00
|
|
|
|
|
|
|
SpinLock _lock;
|
2010-11-09 00:00:02 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
extern NetworkCounter networkCounter;
|
2010-01-16 06:50:02 +01:00
|
|
|
}
|