rocksdb/scribe/scribe_logger.h
heyongqiang 6ba1f17789 adding a scribe logger in leveldb to log leveldb deploy stats
Summary:
as subject.

A new log is written to scribe via thrift client when a new db is opened and when there is
a compaction.

a new option var scribe_log_db_stats is added.

Test Plan: manually checked using command "ptail -time 0 leveldb_deploy_stats"

Reviewers: dhruba

Differential Revision: https://reviews.facebook.net/D4659
2012-08-21 11:43:22 -07:00

72 lines
1.7 KiB
C++

#ifndef SCRIBE_LOGGER_H_
#define SCRIBE_LOGGER_H_
#include "scribe/if/gen-cpp/scribe.h"
#include "scribe/if/gen-cpp/scribe_types.h"
#include "thrift/lib/cpp/protocol/TProtocol.h"
#include "thrift/lib/cpp/transport/TSocket.h"
#include "thrift/lib/cpp/protocol/TBinaryProtocol.h"
#include "thrift/lib/cpp/transport/TBufferTransports.h"
#include "leveldb/env.h"
#include "port/port.h"
#include "util/stats_logger.h"
#include "boost/lexical_cast.hpp"
using namespace Tleveldb;
using Tleveldb::scribeClient;
using namespace apache::thrift;
using namespace apache::thrift::protocol;
using namespace apache::thrift::transport;
using boost::shared_ptr;
using namespace ::Tleveldb;
namespace leveldb {
class ScribeLogger : public StatsLogger{
private:
std::string host_;
int port_;
int batch_size_;
scribeClient* scribe_client_;
std::vector<LogEntry> logs_;
port::Mutex logger_mutex_;
int retry_times_;
uint32_t retry_intervals_;
void MakeScribeMessage(std::string& output, std::vector<std::string>& cols);
public:
static const std::string COL_SEPERATOR;
static const std::string DEPLOY_STATS_CATEGORY;
ScribeLogger(const std::string& host, int port,
int retry_times=3, uint32_t retry_intervals=1000000,
int batch_size=1);
virtual ~ScribeLogger();
virtual void Log(const std::string& category, const std::string& message);
virtual void Log_Deploy_Stats(
const std::string& db_version,
const std::string& machine_info,
const std::string& data_dir,
const uint64_t data_size,
const uint32_t file_number,
const std::string& data_size_per_level,
const std::string& file_number_per_level,
const int64_t& ts_unix
);
};
}
#endif /* SCRIBE_LOGGER_H_ */