1
0
mirror of https://github.com/pavel-odintsov/fastnetmon synced 2024-11-22 20:42:03 +01:00

Added logic to correctly parse ARM cpuinfo on ARM based macOS Docker

This commit is contained in:
Pavel Odintsov 2024-07-30 12:42:55 +03:00
parent 3cca3b594e
commit 5f7ce6b6a5
3 changed files with 20 additions and 14 deletions

@ -2193,28 +2193,30 @@ bool get_cpu_flags(std::vector<std::string>& flags) {
return false;
}
std::string get_cpu_model() {
bool get_cpu_model(std::string& cpu_model) {
extern log4cpp::Category& logger;
std::ifstream cpuinfo_file("/proc/cpuinfo");
boost::regex processor_model_pattern("^model name\\s+:\\s(.*?)$");
if (!cpuinfo_file.is_open()) {
logger << log4cpp::Priority::ERROR << "License: could not open cpuinfo";
return "";
logger << log4cpp::Priority::ERROR << "Could not open /proc/cpuinfo";
return false;
}
boost::regex processor_model_pattern("^model name\\s+:\\s(.*?)$");
std::string line;
while (getline(cpuinfo_file, line)) {
boost::match_results<std::string::const_iterator> regex_results;
if (boost::regex_match(line, regex_results, processor_model_pattern)) {
return regex_results[1];
cpu_model = regex_results[1];
return true;
}
}
// For new ARMs (Cavium Thunder X for example) we do not have model name in 4.10 kernel
#ifdef __aarch64__
// For ARM CPUs we have another format
// Even if we run in x86_64 mode we can have cpuinfo with such information on ARM64 based macOS platforms
std::string implementer;
std::string part;
std::string revision;
@ -2247,13 +2249,13 @@ std::string get_cpu_model() {
// If we fould all of them, use these fields as model
if (implementer.size() > 0 && part.size() > 0 && revision.size() > 0) {
return "implementer: " + implementer + " part: " + part + " revision: " + revision;
} else {
// logger << log4cpp::Priority::ERROR << "implementer: " << implementer << " part: " << part << " revision: " << revision;
cpu_model = "implementer: " + implementer + " part: " + part + " revision: " + revision;
return true;
}
#endif
return "";
// logger << log4cpp::Priority::ERROR << "implementer: " << implementer << " part: " << part << " revision: " << revision;
return false;
}
// returns forwarding status as string

@ -139,7 +139,7 @@ bool execute_web_request(const std::string& address_param,
const std::map<std::string, std::string>& headers,
std::string& error_text);
unsigned int get_total_memory();
std::string get_cpu_model();
bool get_cpu_model(std::string& cpu_model);
bool execute_web_request_secure(std::string address,
std::string request_type,
std::string post_data,

@ -3083,7 +3083,11 @@ void send_usage_data_to_reporting_server() {
stats["traffic_db"] = false;
stats["prometheus"] = false;
stats["cpu_model"] = get_cpu_model();
std::string cpu_model;
get_cpu_model(cpu_model);
stats["cpu_model"] = cpu_model;
stats["cpu_logical_cores"] = get_logical_cpus_number();
// Mbytes