return 0;
}
+int show_snort_cpu(lua_State* L)
+{
+ ControlConn* ctrlconn = ControlConn::query_from_lua(L);
+ send_response(ctrlconn, "Id \tPid \t30sec \t2min \t5min\n\n");
+ main_broadcast_command(new ACShowSnortCPU(ctrlconn), ctrlconn);
+ return 0;
+}
+
//-------------------------------------------------------------------------
// housekeeping foo
//-------------------------------------------------------------------------
int main_quit(lua_State* = nullptr);
int main_help(lua_State* = nullptr);
int convert_counter_type(const char* type);
+int show_snort_cpu(lua_State* = nullptr);
#ifdef SHELL
int main_dump_plugins(lua_State* = nullptr);
#include "protocols/packet_manager.h"
#include "target_based/host_attributes.h"
#include "utils/stats.h"
+#include "packet_io/sfdaq_instance.h"
#include "analyzer.h"
#include "reload_tracker.h"
#include "reload_tuner.h"
#include "snort.h"
#include "snort_config.h"
+#include "thread_config.h"
#include "swapper.h"
using namespace snort;
{
return analyzer.get_daq_instance();
}
+
+ACShowSnortCPU::~ACShowSnortCPU()
+{
+ if (DAQ_SUCCESS == status)
+ {
+ LogRespond(ctrlcon, "\nSummary \t%.1f%% \t%.1f%% \t%.1f%%\n",
+ cpu_usage_30s/instance_num,
+ cpu_usage_120s/instance_num,
+ cpu_usage_300s/instance_num);
+ }
+}
+
+bool ACShowSnortCPU::execute(Analyzer& analyzer, void**)
+{
+ DIOCTL_GetCpuProfileData get_data = {};
+ do
+ {
+ std::lock_guard<std::mutex> lock(cpu_usage_mutex);
+ if (DAQ_SUCCESS != status)
+ break;
+
+ SFDAQInstance* instance = get_daq_instance(analyzer);
+ ThreadConfig *thread_config = SnortConfig::get_conf()->thread_config;
+ int tid = thread_config->get_instance_tid(get_instance_id());
+
+ status = instance->ioctl(
+ (DAQ_IoctlCmd)DIOCTL_GET_CPU_PROFILE_DATA,
+ (void *)(&get_data),
+ sizeof(DIOCTL_GetCpuProfileData));
+
+ if (DAQ_SUCCESS != status)
+ {
+ LogRespond(ctrlcon, "Fetching profile data failed from DAQ instance\n");
+ break;
+ }
+
+ // Print CPU usage
+ LogRespond(ctrlcon, "%-3d \t%-6d \t%.1f%% \t%.1f%% \t%.1f%%\n",
+ instance_num,
+ tid,
+ get_data.cpu_usage_percent_30s,
+ get_data.cpu_usage_percent_120s,
+ get_data.cpu_usage_percent_300s);
+
+ // Add CPU usage data
+ cpu_usage_30s += get_data.cpu_usage_percent_30s;
+ cpu_usage_120s += get_data.cpu_usage_percent_120s;
+ cpu_usage_300s += get_data.cpu_usage_percent_300s;
+ instance_num++;
+
+ } while (0);
+
+ return true;
+}
#ifndef ANALYZER_COMMANDS_H
#define ANALYZER_COMMANDS_H
+#include <daq_common.h>
+
#include <cstdarg>
#include <vector>
+#include <mutex>
#include "main/snort_types.h"
std::vector<snort::ScratchAllocator*>& handlers;
};
+class ACShowSnortCPU : public snort::AnalyzerCommand
+{
+public:
+ explicit ACShowSnortCPU(ControlConn* conn) : AnalyzerCommand(conn)
+ { }
+ bool execute(Analyzer&, void**) override;
+ const char* stringify() override { return "SHOW_SNORT_CPU"; }
+ ~ACShowSnortCPU() override;
+
+private:
+ int status = DAQ_SUCCESS;
+ float cpu_usage_30s = 0.0;
+ float cpu_usage_120s = 0.0;
+ float cpu_usage_300s = 0.0;
+ int instance_num = 0;
+ std::mutex cpu_usage_mutex;
+};
+
namespace snort
{
// from main.cc
{ "reload_hosts", main_reload_hosts, s_reload, "load a new hosts table" },
{ "log_command", main_log_command,main_log_command_param, "enable or disable command logging"},
{ "show_config_generation", main_show_config_generation, nullptr, "show loaded configuration ID"},
+ { "show_snort_cpu", show_snort_cpu, nullptr, "show snort cpu usage"},
// FIXIT-M rewrite trough to permit updates on the fly
//{ "process", main_process, nullptr, "process given pcap" },