Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
KayzzzZ committed Oct 17, 2024
1 parent c637478 commit 4fc5dd1
Show file tree
Hide file tree
Showing 16 changed files with 284 additions and 217 deletions.
168 changes: 64 additions & 104 deletions core/ebpf/SelfMonitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,71 +41,43 @@ void BaseBPFMonitor::ReleaseMetric() {
mMetricInited = false;
}

std::string BaseBPFMonitor::PluginTypeToString(const nami::PluginType pluginType) {
switch (pluginType)
{
case nami::PluginType::NETWORK_OBSERVE:
return METRIC_LABEL_VALUE_RUNNER_PLUGIN_TYPE_NETWORK_OBSERVER;
break;
case nami::PluginType::NETWORK_SECURITY:
return METRIC_LABEL_VALUE_RUNNER_PLUGIN_TYPE_NETWORK_SECURITY;
break;
case nami::PluginType::PROCESS_OBSERVE:
return METRIC_LABEL_VALUE_RUNNER_PLUGIN_TYPE_PROCESS_OBSERVER;
break;
case nami::PluginType::PROCESS_SECURITY:
return METRIC_LABEL_VALUE_RUNNER_PLUGIN_TYPE_PROCESS_SECURITY;
break;
case nami::PluginType::FILE_OBSERVE:
return METRIC_LABEL_VALUE_RUNNER_PLUGIN_TYPE_FILE_OBSERVER;
break;
case nami::PluginType::FILE_SECURITY:
return METRIC_LABEL_VALUE_RUNNER_PLUGIN_TYPE_FILE_SECURITY;
break;
default:
return "";
break;
}
}

void BaseBPFMonitor::InitInnerMetric() {
// init base metrics, only plugin relative
// poll kernel events
MetricLabels pollKernelEventsLabels = {
{METRIC_LABEL_KEY_RUNNER_RECV_EVENT_STAGE, METRIC_LABEL_VALUE_RUNNER_RECV_EVENT_STAGE_POLL_KERNEL}
{METRIC_LABEL_KEY_RECV_EVENT_STAGE, METRIC_LABEL_VALUE_RECV_EVENT_STAGE_POLL_KERNEL}
};
auto ref = mPluginMetricMgr->GetOrCreateReentrantMetricsRecordRef(pollKernelEventsLabels);
mRecvKernelEventsTotal = ref->GetCounter(METRIC_RUNNER_IN_EVENTS_TOTAL);
mRefAndLabels.emplace_back(std::make_pair<>(ref, pollKernelEventsLabels));

mRecvKernelEventsTotal = ref->GetCounter(METRIC_PLUGIN_IN_EVENTS_TOTAL);
// loss kernel events
mLossKernelEventsTotal = mRef.CreateCounter(METRIC_RUNNER_EBPF_LOSS_KERNEL_EVENTS_TOTAL);
mProcessCacheEntitiesNum = mRef.CreateIntGauge(METRIC_RUNNER_EBPF_PROCESS_CACHE_ENTRIES_NUM);
mProcessCacheMissTotal = mRef.CreateCounter(METRIC_RUNNER_EBPF_PROCESS_CACHE_MISS_TOTAL);
mLossKernelEventsTotal = ref->GetCounter(METRIC_PLUGIN_EBPF_LOSS_KERNEL_EVENTS_TOTAL);
mProcessCacheEntitiesNum = ref->GetIntGauge(METRIC_PLUGIN_EBPF_PROCESS_CACHE_ENTRIES_NUM);
mProcessCacheMissTotal = ref->GetCounter(METRIC_PLUGIN_EBPF_PROCESS_CACHE_MISS_TOTAL);
mRefAndLabels.emplace_back(std::make_pair<>(ref, pollKernelEventsLabels));

// push logs/spans/metrics
MetricLabels pushLogsLabels = {
{METRIC_LABEL_KEY_RUNNER_RECV_EVENT_STAGE, METRIC_LABEL_VALUE_RUNNER_RECV_EVENT_STAGE_REPORT_TO_LC},
{METRIC_LABEL_KEY_RUNNER_EVENT_TYPE, METRIC_LABEL_VALUE_RUNNER_EVENT_TYPE_LOG}
{METRIC_LABEL_KEY_RECV_EVENT_STAGE, METRIC_LABEL_VALUE_RECV_EVENT_STAGE_REPORT_TO_LC},
{METRIC_LABEL_KEY_EVENT_TYPE, METRIC_LABEL_VALUE_EVENT_TYPE_LOG}
};
ref = mPluginMetricMgr->GetOrCreateReentrantMetricsRecordRef(pushLogsLabels);
mPushEventsTotal = ref->GetCounter(METRIC_RUNNER_IN_EVENTS_TOTAL);
mPushEventsTotal = ref->GetCounter(METRIC_PLUGIN_IN_EVENTS_TOTAL);
mRefAndLabels.emplace_back(std::make_pair<>(ref, pushLogsLabels));

MetricLabels pushMetricsLabels = {
{METRIC_LABEL_KEY_RUNNER_RECV_EVENT_STAGE, METRIC_LABEL_VALUE_RUNNER_RECV_EVENT_STAGE_REPORT_TO_LC},
{METRIC_LABEL_KEY_RUNNER_EVENT_TYPE, METRIC_LABEL_VALUE_RUNNER_EVENT_TYPE_METRIC}
{METRIC_LABEL_KEY_RECV_EVENT_STAGE, METRIC_LABEL_VALUE_RECV_EVENT_STAGE_REPORT_TO_LC},
{METRIC_LABEL_KEY_EVENT_TYPE, METRIC_LABEL_VALUE_EVENT_TYPE_METRIC}
};
ref = mPluginMetricMgr->GetOrCreateReentrantMetricsRecordRef(pushMetricsLabels);
mPushMetricsTotal = ref->GetCounter(METRIC_RUNNER_IN_EVENTS_TOTAL);
mPushMetricsTotal = ref->GetCounter(METRIC_PLUGIN_IN_EVENTS_TOTAL);
mRefAndLabels.emplace_back(std::make_pair<>(ref, pushMetricsLabels));

MetricLabels pushSpansLabels = {
{METRIC_LABEL_KEY_RUNNER_RECV_EVENT_STAGE, METRIC_LABEL_VALUE_RUNNER_RECV_EVENT_STAGE_REPORT_TO_LC},
{METRIC_LABEL_KEY_RUNNER_EVENT_TYPE, METRIC_LABEL_VALUE_RUNNER_EVENT_TYPE_TRACE}
{METRIC_LABEL_KEY_RECV_EVENT_STAGE, METRIC_LABEL_VALUE_RECV_EVENT_STAGE_REPORT_TO_LC},
{METRIC_LABEL_KEY_EVENT_TYPE, METRIC_LABEL_VALUE_EVENT_TYPE_TRACE}
};
ref = mPluginMetricMgr->GetOrCreateReentrantMetricsRecordRef(pushSpansLabels);
mPushSpansTotal = ref->GetCounter(METRIC_RUNNER_IN_EVENTS_TOTAL);
mPushSpansTotal = ref->GetCounter(METRIC_PLUGIN_IN_EVENTS_TOTAL);
mRefAndLabels.emplace_back(std::make_pair<>(ref, pushSpansLabels));
}

Expand All @@ -128,61 +100,66 @@ void NetworkObserverSelfMonitor::InitMetric() {
InitInnerMetric();

// use default labels ...
mConnTrackerNum = mRef.CreateIntGauge(METRIC_RUNNER_EBPF_NETWORK_OBSERVER_CONNTRACKER_NUM);
mAggMapEntitiesNum = mRef.CreateIntGauge(METRIC_RUNNER_EBPF_NETWORK_OBSERVER_AGGREGATE_KEY_NUM);
MetricLabels recvEventLabels = {
{METRIC_LABEL_KEY_RECV_EVENT_STAGE, METRIC_LABEL_VALUE_RECV_EVENT_STAGE_AFTER_PERF_WORKER},
};
auto ref = mPluginMetricMgr->GetOrCreateReentrantMetricsRecordRef(recvEventLabels);

mConnTrackerNum = ref->GetIntGauge(METRIC_PLUGIN_EBPF_NETWORK_OBSERVER_CONNTRACKER_NUM);
mAggMapEntitiesNum = ref->GetIntGauge(METRIC_PLUGIN_EBPF_NETWORK_OBSERVER_AGGREGATE_KEY_NUM);
mRefAndLabels.emplace_back(std::make_pair<>(ref, recvEventLabels));

// event type relative labels ...
MetricLabels eventTypeLabels = {
{METRIC_LABEL_KEY_RUNNER_RECV_EVENT_STAGE, METRIC_LABEL_VALUE_RUNNER_RECV_EVENT_STAGE_AFTER_PERF_WORKER},
{METRIC_LABEL_KEY_RUNNER_EVENT_TYPE, METRIC_LABEL_VALUE_RUNNER_EVENT_TYPE_CONN_STATS}
{METRIC_LABEL_KEY_RECV_EVENT_STAGE, METRIC_LABEL_VALUE_RECV_EVENT_STAGE_AFTER_PERF_WORKER},
{METRIC_LABEL_KEY_EVENT_TYPE, METRIC_LABEL_VALUE_EVENT_TYPE_CONN_STATS}
};
auto ref = mPluginMetricMgr->GetOrCreateReentrantMetricsRecordRef(eventTypeLabels);
mRecvConnStatsTotal = ref->GetCounter(METRIC_RUNNER_EBPF_NETWORK_OBSERVER_WORKER_HANDLE_EVENTS_TOTAL);
ref = mPluginMetricMgr->GetOrCreateReentrantMetricsRecordRef(eventTypeLabels);
mRecvConnStatsTotal = ref->GetCounter(METRIC_PLUGIN_EBPF_NETWORK_OBSERVER_WORKER_HANDLE_EVENTS_TOTAL);
mRefAndLabels.emplace_back(std::make_pair<>(ref, eventTypeLabels));

eventTypeLabels = {
{METRIC_LABEL_KEY_RUNNER_RECV_EVENT_STAGE, METRIC_LABEL_VALUE_RUNNER_RECV_EVENT_STAGE_AFTER_PERF_WORKER},
{METRIC_LABEL_KEY_RUNNER_EVENT_TYPE, METRIC_LABEL_VALUE_RUNNER_EVENT_TYPE_CTRL_EVENT}
{METRIC_LABEL_KEY_RECV_EVENT_STAGE, METRIC_LABEL_VALUE_RECV_EVENT_STAGE_AFTER_PERF_WORKER},
{METRIC_LABEL_KEY_EVENT_TYPE, METRIC_LABEL_VALUE_EVENT_TYPE_CTRL_EVENT}
};
ref = mPluginMetricMgr->GetOrCreateReentrantMetricsRecordRef(eventTypeLabels);
mRecvCtrlEventsTotal = ref->GetCounter(METRIC_RUNNER_EBPF_NETWORK_OBSERVER_WORKER_HANDLE_EVENTS_TOTAL);
mRecvCtrlEventsTotal = ref->GetCounter(METRIC_PLUGIN_EBPF_NETWORK_OBSERVER_WORKER_HANDLE_EVENTS_TOTAL);
mRefAndLabels.emplace_back(std::make_pair<>(ref, eventTypeLabels));

//
MetricLabels eventTypeAndProtocolLbales = {
{METRIC_LABEL_KEY_RUNNER_RECV_EVENT_STAGE, METRIC_LABEL_VALUE_RUNNER_RECV_EVENT_STAGE_AFTER_PERF_WORKER},
{METRIC_LABEL_KEY_RUNNER_EVENT_TYPE, METRIC_LABEL_VALUE_RUNNER_EVENT_TYPE_DATA_EVENT},
{METRIC_LABEL_KEY_RUNNER_PARSER_PROTOCOL, METRIC_LABEL_VALUE_RUNNER_PARSER_PROTOCOL_HTTP},
{METRIC_LABEL_KEY_RECV_EVENT_STAGE, METRIC_LABEL_VALUE_RECV_EVENT_STAGE_AFTER_PERF_WORKER},
{METRIC_LABEL_KEY_EVENT_TYPE, METRIC_LABEL_VALUE_EVENT_TYPE_DATA_EVENT},
{METRIC_LABEL_KEY_PARSER_PROTOCOL, METRIC_LABEL_VALUE_PARSER_PROTOCOL_HTTP},
};
ref = mPluginMetricMgr->GetOrCreateReentrantMetricsRecordRef(eventTypeAndProtocolLbales);
mRecvHTTPDataEventsTotal = ref->GetCounter(METRIC_RUNNER_EBPF_NETWORK_OBSERVER_WORKER_HANDLE_EVENTS_TOTAL);
mRecvHTTPDataEventsTotal = ref->GetCounter(METRIC_PLUGIN_EBPF_NETWORK_OBSERVER_WORKER_HANDLE_EVENTS_TOTAL);
mRefAndLabels.emplace_back(std::make_pair<>(ref, eventTypeAndProtocolLbales));

// protocol relative labels ...
MetricLabels httpSuccessLabels = {
{METRIC_LABEL_KEY_RUNNER_RECV_EVENT_STAGE, METRIC_LABEL_VALUE_RUNNER_RECV_EVENT_STAGE_AFTER_PERF_WORKER},
{METRIC_LABEL_KEY_RUNNER_EVENT_TYPE, METRIC_LABEL_VALUE_RUNNER_EVENT_TYPE_DATA_EVENT},
{METRIC_LABEL_KEY_RUNNER_PARSER_PROTOCOL, METRIC_LABEL_VALUE_RUNNER_PARSER_PROTOCOL_HTTP},
{METRIC_LABEL_KEY_RUNNER_PARSE_STATUS, METRIC_LABEL_VALUE_RUNNER_PARSE_STATUS_SUCCESS}
{METRIC_LABEL_KEY_RECV_EVENT_STAGE, METRIC_LABEL_VALUE_RECV_EVENT_STAGE_AFTER_PERF_WORKER},
{METRIC_LABEL_KEY_EVENT_TYPE, METRIC_LABEL_VALUE_EVENT_TYPE_DATA_EVENT},
{METRIC_LABEL_KEY_PARSER_PROTOCOL, METRIC_LABEL_VALUE_PARSER_PROTOCOL_HTTP},
{METRIC_LABEL_KEY_PARSE_STATUS, METRIC_LABEL_VALUE_PARSE_STATUS_SUCCESS}
};
ref = mPluginMetricMgr->GetOrCreateReentrantMetricsRecordRef(httpSuccessLabels);
mParseHTTPEventsSuccessTotal = ref->GetCounter(METRIC_RUNNER_EBPF_NETWORK_OBSERVER_PROTOCOL_PARSE_RECORDS_TOTAL);
mParseHTTPEventsSuccessTotal = ref->GetCounter(METRIC_PLUGIN_EBPF_NETWORK_OBSERVER_PROTOCOL_PARSE_RECORDS_TOTAL);
mRefAndLabels.emplace_back(std::make_pair<>(ref, httpSuccessLabels));

MetricLabels httpFailLabels = {
{METRIC_LABEL_KEY_RUNNER_RECV_EVENT_STAGE, METRIC_LABEL_VALUE_RUNNER_RECV_EVENT_STAGE_AFTER_PERF_WORKER},
{METRIC_LABEL_KEY_RUNNER_EVENT_TYPE, METRIC_LABEL_VALUE_RUNNER_EVENT_TYPE_DATA_EVENT},
{METRIC_LABEL_KEY_RUNNER_PARSER_PROTOCOL, METRIC_LABEL_VALUE_RUNNER_PARSER_PROTOCOL_HTTP},
{METRIC_LABEL_KEY_RUNNER_PARSE_STATUS, METRIC_LABEL_VALUE_RUNNER_PARSE_STATUS_FAILED}
{METRIC_LABEL_KEY_RECV_EVENT_STAGE, METRIC_LABEL_VALUE_RECV_EVENT_STAGE_AFTER_PERF_WORKER},
{METRIC_LABEL_KEY_EVENT_TYPE, METRIC_LABEL_VALUE_EVENT_TYPE_DATA_EVENT},
{METRIC_LABEL_KEY_PARSER_PROTOCOL, METRIC_LABEL_VALUE_PARSER_PROTOCOL_HTTP},
{METRIC_LABEL_KEY_PARSE_STATUS, METRIC_LABEL_VALUE_PARSE_STATUS_FAILED}
};
ref = mPluginMetricMgr->GetOrCreateReentrantMetricsRecordRef(httpFailLabels);
mParseHTTPEventsFailTotal = ref->GetCounter(METRIC_RUNNER_EBPF_NETWORK_OBSERVER_PROTOCOL_PARSE_RECORDS_TOTAL);
mParseHTTPEventsFailTotal = ref->GetCounter(METRIC_PLUGIN_EBPF_NETWORK_OBSERVER_PROTOCOL_PARSE_RECORDS_TOTAL);
mRefAndLabels.emplace_back(std::make_pair<>(ref, httpFailLabels));
}

void NetworkObserverSelfMonitor::HandleStatistic(nami::eBPFStatistics& stats) {
if (!stats.updated_) return;
// std::lock_guard<std::mutex> lk(mStatsMtx);
UpdateInnerMetric(stats);
// recv kernel events metric
assert(stats.plugin_type_ == nami::PluginType::NETWORK_OBSERVE);
Expand All @@ -200,54 +177,32 @@ void NetworkObserverSelfMonitor::HandleStatistic(nami::eBPFStatistics& stats) {
mAggMapEntitiesNum->Set(currNetworkStatsPtr->agg_map_entities_num_);
}

void eBPFSelfMonitorMgr::Init(const nami::PluginType type, MetricsRecordRef& ref, const std::string& name, const std::string& logstore) {
if (mInited[int(type)]) {
return;
}
eBPFSelfMonitorMgr::eBPFSelfMonitorMgr() : mSelfMonitors({}), mInited({}) {}

static const std::unordered_map<std::string, MetricType> metricKeys = {
{METRIC_RUNNER_IN_EVENTS_TOTAL, MetricType::METRIC_TYPE_COUNTER},
{METRIC_RUNNER_EBPF_LOSS_KERNEL_EVENTS_TOTAL, MetricType::METRIC_TYPE_COUNTER},
{METRIC_RUNNER_EBPF_PROCESS_CACHE_ENTRIES_NUM, MetricType::METRIC_TYPE_INT_GAUGE},
{METRIC_RUNNER_EBPF_PROCESS_CACHE_MISS_TOTAL, MetricType::METRIC_TYPE_COUNTER},
};
void eBPFSelfMonitorMgr::Init(const nami::PluginType type, std::shared_ptr<PluginMetricManager> mgr, const std::string& name, const std::string& logstore) {
if (mInited[int(type)]) return;

// Add project to labels
// Add Runner Name to labels
MetricLabelsPtr labelsPtr = ref.GetLabels();
labelsPtr->push_back({METRIC_LABEL_KEY_RUNNER_NAME, METRIC_LABEL_VALUE_RUNNER_NAME_EBPF_SERVER});
labelsPtr->push_back({METRIC_LABEL_KEY_LOGSTORE, logstore});
WriteLock lk(mLock);

// double check
if (mInited[int(type)]) return;

switch (type)
{
case nami::PluginType::NETWORK_OBSERVE: {
std::unordered_map<std::string, MetricType> keys = metricKeys;
keys.insert({METRIC_RUNNER_EBPF_NETWORK_OBSERVER_CONNTRACKER_NUM, MetricType::METRIC_TYPE_INT_GAUGE});
keys.insert({METRIC_RUNNER_EBPF_NETWORK_OBSERVER_AGGREGATE_KEY_NUM, MetricType::METRIC_TYPE_INT_GAUGE});
keys.insert({METRIC_RUNNER_EBPF_NETWORK_OBSERVER_WORKER_HANDLE_EVENTS_TOTAL, MetricType::METRIC_TYPE_COUNTER});
keys.insert({METRIC_RUNNER_EBPF_NETWORK_OBSERVER_PROTOCOL_PARSE_RECORDS_TOTAL, MetricType::METRIC_TYPE_COUNTER});
auto pluginMetricManager
= std::make_shared<PluginMetricManager>(labelsPtr, keys);
mSelfMonitors[int(type)] = std::make_unique<NetworkObserverSelfMonitor>(name, pluginMetricManager, ref);
mSelfMonitors[int(type)] = std::make_unique<NetworkObserverSelfMonitor>(name, mgr);
break;
}
case nami::PluginType::NETWORK_SECURITY: {
auto pluginMetricManager
= std::make_shared<PluginMetricManager>(labelsPtr, metricKeys);
mSelfMonitors[int(type)] = std::make_unique<NetworkSecuritySelfMonitor>(name, pluginMetricManager, ref);
mSelfMonitors[int(type)] = std::make_unique<NetworkSecuritySelfMonitor>(name, mgr);
break;
}
case nami::PluginType::FILE_SECURITY: {
auto pluginMetricManager
= std::make_shared<PluginMetricManager>(labelsPtr, metricKeys);
mSelfMonitors[int(type)] = std::make_unique<FileSecuritySelfMonitor>(name, pluginMetricManager, ref);
mSelfMonitors[int(type)] = std::make_unique<FileSecuritySelfMonitor>(name, mgr);
break;
}
case nami::PluginType::PROCESS_SECURITY: {
auto pluginMetricManager
= std::make_shared<PluginMetricManager>(labelsPtr, metricKeys);
mSelfMonitors[int(type)] = std::make_unique<ProcessSecuritySelfMonitor>(name, pluginMetricManager, ref);
mSelfMonitors[int(type)] = std::make_unique<ProcessSecuritySelfMonitor>(name, mgr);
break;
}
default:
Expand All @@ -258,9 +213,11 @@ void eBPFSelfMonitorMgr::Init(const nami::PluginType type, MetricsRecordRef& ref
}

void eBPFSelfMonitorMgr::Release(const nami::PluginType type) {
if (!mInited[int(type)]) {
return;
}
if (!mInited[int(type)]) return;

WriteLock lk(mLock);
// double check
if (!mInited[int(type)]) return;
if (mSelfMonitors[int(type)]) {
mSelfMonitors[int(type)]->ReleaseMetric();
mSelfMonitors[int(type)].reset();
Expand All @@ -281,8 +238,11 @@ void eBPFSelfMonitorMgr::HandleStatistic(std::vector<nami::eBPFStatistics>&& sta
continue;
}
auto type = stat.plugin_type_;
if (mInited[int(type)] && mSelfMonitors[int(type)]) {
mSelfMonitors[int(type)]->HandleStatistic(stat);
{
ReadLock lk(mLock);
if (mInited[int(type)] && mSelfMonitors[int(type)]) {
mSelfMonitors[int(type)]->HandleStatistic(stat);
}
}
}
}
Expand Down
30 changes: 15 additions & 15 deletions core/ebpf/SelfMonitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,8 @@ class BaseBPFMonitor {
virtual void ReleaseMetric();
virtual ~BaseBPFMonitor() = default;
protected:
BaseBPFMonitor(const std::string& name, PluginMetricManagerPtr mgr, MetricsRecordRef& ref)
: mPipelineName(name), mPluginMetricMgr(mgr), mRef(ref) {}

std::string PluginTypeToString(const nami::PluginType pluginType);
BaseBPFMonitor(const std::string& name, PluginMetricManagerPtr mgr)
: mPipelineName(name), mPluginMetricMgr(mgr) {}

// attention: not thread safe!!
void InitInnerMetric();
Expand All @@ -47,7 +45,7 @@ class BaseBPFMonitor {

std::string mPipelineName;
PluginMetricManagerPtr mPluginMetricMgr;
MetricsRecordRef& mRef;
// MetricsRecordRef& mRef;
std::vector<std::pair<ReentrantMetricsRecordRef, MetricLabels>> mRefAndLabels;

std::atomic_bool mMetricInited = false;
Expand All @@ -67,8 +65,8 @@ class BaseBPFMonitor {

class NetworkObserverSelfMonitor : public BaseBPFMonitor {
public:
NetworkObserverSelfMonitor(const std::string& name, PluginMetricManagerPtr mgr, MetricsRecordRef& ref)
: BaseBPFMonitor(name, mgr, ref) {}
NetworkObserverSelfMonitor(const std::string& name, PluginMetricManagerPtr mgr/**/)
: BaseBPFMonitor(name, mgr) {}

void InitMetric() override;

Expand Down Expand Up @@ -97,8 +95,8 @@ class NetworkObserverSelfMonitor : public BaseBPFMonitor {

class NetworkSecuritySelfMonitor : public BaseBPFMonitor {
public:
NetworkSecuritySelfMonitor(const std::string& name, PluginMetricManagerPtr mgr, MetricsRecordRef& ref)
: BaseBPFMonitor(name, mgr, ref) {}
NetworkSecuritySelfMonitor(const std::string& name, PluginMetricManagerPtr mgr)
: BaseBPFMonitor(name, mgr) {}

void HandleStatistic(nami::eBPFStatistics& stats) override {
if (!stats.updated_) return;
Expand All @@ -108,27 +106,29 @@ class NetworkSecuritySelfMonitor : public BaseBPFMonitor {

class ProcessSecuritySelfMonitor : public BaseBPFMonitor {
public:
ProcessSecuritySelfMonitor(const std::string& name, PluginMetricManagerPtr mgr, MetricsRecordRef& ref)
: BaseBPFMonitor(name, mgr, ref) {}
ProcessSecuritySelfMonitor(const std::string& name, PluginMetricManagerPtr mgr)
: BaseBPFMonitor(name, mgr) {}
};

class FileSecuritySelfMonitor : public BaseBPFMonitor {
public:
FileSecuritySelfMonitor(const std::string& name, PluginMetricManagerPtr mgr, MetricsRecordRef& ref)
: BaseBPFMonitor(name, mgr, ref) {}
FileSecuritySelfMonitor(const std::string& name, PluginMetricManagerPtr mgr)
: BaseBPFMonitor(name, mgr) {}
};

/**
* eBPFSelfMonitorMgr is only used to manage the self-monitoring data in libnetwork_observer.so, updating the statistics through callbacks.
*/
class eBPFSelfMonitorMgr {
public:
eBPFSelfMonitorMgr() : mSelfMonitors({}), mInited({}) {}
void Init(const nami::PluginType type, MetricsRecordRef& ref, const std::string& name, const std::string& logstore);
eBPFSelfMonitorMgr();
void Init(const nami::PluginType type, std::shared_ptr<PluginMetricManager> mgr, const std::string& name, const std::string& project);
void Release(const nami::PluginType type);
void Suspend(const nami::PluginType type);
void HandleStatistic(std::vector<nami::eBPFStatistics>&& stats);
private:
// `mLock` is used to protect mSelfMonitors
ReadWriteLock mLock;
std::array<std::unique_ptr<BaseBPFMonitor>, int(nami::PluginType::MAX)> mSelfMonitors;
std::array<std::atomic_bool, int(nami::PluginType::MAX)> mInited;

Expand Down
Loading

0 comments on commit 4fc5dd1

Please sign in to comment.