Skip to content

Commit

Permalink
Merge pull request #2 from matthewvon/master
Browse files Browse the repository at this point in the history
clean up to simplify library build/use via gradle
  • Loading branch information
matthewvon authored Jan 8, 2023
2 parents 7fa1a75 + c270945 commit ab7a3a6
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 32 deletions.
34 changes: 22 additions & 12 deletions stats_table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
*/

#include "stats_table.h"
#include "stats_table_impl.h"
#include "snmpagent/val_integer64.h"

#include "snmpagent/val_string.h"
/**
* Enterprise: 1.3.6.1.4.1
*Agent prefix: 38693 matthewv.com enterprise
Expand All @@ -35,12 +36,21 @@ static SnmpAgent::SnmpAgentId sAgentId = {
sAgentPrefix, sizeof(sAgentPrefix) / sizeof(sAgentPrefix[0]),
"RocksMonitor"};

StatsTable* StatsTable::NewStatsTable(bool StartWorker) {

return new StatsTableImpl(StartWorker);

} // StatsTable::NewStatsTable

StatsTable::StatsTable() {};


/**
* Initialize the data members.
* @date Created 05/21/12
* @author matthewv
*/
StatsTable::StatsTable(bool StartWorker) {
StatsTableImpl::StatsTableImpl(bool StartWorker) {

// everything is a "make_shared" object in libmevent & snmpagent world
m_Mgr = std::make_shared<MEventMgr>();
Expand All @@ -55,10 +65,10 @@ StatsTable::StatsTable(bool StartWorker) {
m_Mgr->AddEvent(mo_sa);
}

StatsTable::~StatsTable() {
StatsTableImpl::~StatsTableImpl() {
m_Mgr->Stop();
m_Mgr->ThreadWait();
} // StatsTable::~StatsTable
} // StatsTableImpl::~StatsTable

class SnmpValTicker : public SnmpValCounter64 {
protected:
Expand All @@ -80,7 +90,7 @@ class SnmpValTicker : public SnmpValCounter64 {
}
}; // class SnmpValTicker

bool StatsTable::AddTable(const std::shared_ptr<rocksdb::Statistics> &stats,
bool StatsTableImpl::AddTable(const std::shared_ptr<rocksdb::Statistics> &stats,
unsigned TableId, const std::string &TableName) {

SnmpValInfPtr shared;
Expand Down Expand Up @@ -121,7 +131,7 @@ bool StatsTable::AddTable(const std::shared_ptr<rocksdb::Statistics> &stats,

return true;

} // StatsTable::AddTable (statistics)
} // StatsTableImpl::AddTable (statistics)


typedef size_t (rocksdb::Cache::*CacheGetFunction)(void) const;
Expand Down Expand Up @@ -165,7 +175,7 @@ class CacheValCounter64 : public SnmpValUnsigned64 {
}; // CacheValCounter64


bool StatsTable::AddTable(const std::shared_ptr<rocksdb::Cache> &cache,
bool StatsTableImpl::AddTable(const std::shared_ptr<rocksdb::Cache> &cache,
unsigned TableId, const std::string &TableName) {

SnmpValInfPtr shared;
Expand Down Expand Up @@ -232,10 +242,10 @@ bool StatsTable::AddTable(const std::shared_ptr<rocksdb::Cache> &cache,

return true;

} // StatsTable::AddTable (cache)
} // StatsTableImpl::AddTable (cache)


void StatsTable::UpdateTableNameList(unsigned TableId, const std::string &TableName) {
void StatsTableImpl::UpdateTableNameList(unsigned TableId, const std::string &TableName) {
SnmpValInfPtr shared;
SnmpValStringPtr new_string;
OidVector_t table_prefix = {TableId};
Expand All @@ -253,7 +263,7 @@ void StatsTable::UpdateTableNameList(unsigned TableId, const std::string &TableN
shared = new_string->GetSnmpValInfPtr();
m_Agent->AddVariable(shared);

} // StatsTable::UpdateTableNameList
} // StatsTableImpl::UpdateTableNameList


class RocksValCounter64 : public SnmpValUnsigned64 {
Expand Down Expand Up @@ -293,7 +303,7 @@ class RocksValCounter64 : public SnmpValUnsigned64 {
}; // RocksValCounter64


bool StatsTable::AddTable(rocksdb::DB * DBase,
bool StatsTableImpl::AddTable(rocksdb::DB * DBase,
unsigned TableId, const std::string &TableName) {

SnmpValInfPtr shared;
Expand Down Expand Up @@ -348,4 +358,4 @@ bool StatsTable::AddTable(rocksdb::DB * DBase,

return true;

} // StatsTable::AddTable (db)
} // StatsTableImpl::AddTable (db)
31 changes: 11 additions & 20 deletions stats_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,56 +2,47 @@
* @file stats_table.h
* @author matthewv
* @date Sept 16, 2020
* @date Copyright 2012-2014
* @date Copyright 2012-present
*
* @brief
*/

#ifndef STATS_TABLE_H
#define STATS_TABLE_H

#include "meventmgr.h"

#include "rocksdb/cache.h"
#include "rocksdb/db.h"
#include "rocksdb/statistics.h"
#include "snmp_agent.h"
#include "val_integer64.h"
#include "val_string.h"

class StatsTable {
/****************************************************************
* Member objects
****************************************************************/
public:
protected:
MEventMgrPtr m_Mgr;
SnmpAgentPtr m_Agent; //!< snmp manager instance

private:
/****************************************************************
* Member functions
****************************************************************/
public:
StatsTable() = delete;
StatsTable(bool StartWorker = true);
StatsTable();

virtual ~StatsTable();

bool AddTable(const std::shared_ptr<rocksdb::Statistics> &stats,
unsigned TableId, const std::string &name);
static StatsTable* NewStatsTable(bool StartWorker = true);

bool AddTable(const std::shared_ptr<rocksdb::Cache> &cache,
unsigned TableId, const std::string &name);
virtual bool AddTable(const std::shared_ptr<rocksdb::Statistics> &stats,
unsigned TableId, const std::string &name) = 0;

bool AddTable(rocksdb::DB * dbase,
unsigned TableId, const std::string &name);
virtual bool AddTable(const std::shared_ptr<rocksdb::Cache> &cache,
unsigned TableId, const std::string &name) = 0;

/// debug
void Dump();
virtual bool AddTable(rocksdb::DB * dbase,
unsigned TableId, const std::string &name) = 0;

protected:
void UpdateTableNameList(unsigned TableId, const std::string &name);
/// debug
virtual void Dump() = 0;

private:
StatsTable(const StatsTable &); //!< disabled: copy operator
Expand Down
60 changes: 60 additions & 0 deletions stats_table_impl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/**
* @file stats_table_impl.h
* @author matthewv
* @date Jan 8, 2023
* @date Copyright 2012-2014
*
* @brief
*/

#ifndef STATS_TABLE_IMPL_H
#define STATS_TABLE_IMPL__H

#include "libmevent/meventmgr.h"

#include "rocksdb/cache.h"
#include "rocksdb/db.h"
#include "rocksdb/statistics.h"
#include "snmpagent/snmp_agent.h"

class StatsTableImpl : public StatsTable {
/****************************************************************
* Member objects
****************************************************************/
public:
protected:
MEventMgrPtr m_Mgr;
SnmpAgentPtr m_Agent; //!< snmp manager instance

private:
/****************************************************************
* Member functions
****************************************************************/
public:
StatsTableImpl() = delete;
StatsTableImpl(bool StartWorker = true);

virtual ~StatsTableImpl();

bool AddTable(const std::shared_ptr<rocksdb::Statistics> &stats,
unsigned TableId, const std::string &name) override;

bool AddTable(const std::shared_ptr<rocksdb::Cache> &cache,
unsigned TableId, const std::string &name) override;

bool AddTable(rocksdb::DB * dbase,
unsigned TableId, const std::string &name) override;

/// debug
void Dump() override;

protected:
void UpdateTableNameList(unsigned TableId, const std::string &name);

private:
StatsTableImpl(const StatsTableImpl &); //!< disabled: copy operator
StatsTableImpl &operator=(const StatsTableImpl &); //!< disabled: assignment operator

}; // StatsTable

#endif // ifndef STATS_TABLE_IMPL_H

0 comments on commit ab7a3a6

Please sign in to comment.