diff --git a/src/components/memory.cpp b/src/components/memory.cpp index f8eb5b6..bdcc549 100644 --- a/src/components/memory.cpp +++ b/src/components/memory.cpp @@ -6,7 +6,7 @@ #include "memory.hpp" -void memory::getProcMem(crow::json::wvalue& ret){ +bool memory::getProcMem(crow::json::wvalue& ret){ std::ifstream f ("/proc/meminfo"); std::string line; if(f.is_open()){ @@ -20,11 +20,27 @@ void memory::getProcMem(crow::json::wvalue& ret){ last_space = i; } - std::cerr << colon << " " << last_space << std::endl; - ret[line.substr(0,colon)] = line.substr(last_space); } } else { ret["message"] = "Failed to open proc filesystem"; + return false; } + + return true; +} + +bool memory::getRawProcMem(std::string& ret){ + std::ifstream f ("/proc/meminfo"); + std::string line; + if(f.is_open()){ + while(std::getline(f, line)){ + ret += line; + } + } else { + ret = "Failed to open proc filesystem"; + return false; + } + + return true; } diff --git a/src/components/memory.hpp b/src/components/memory.hpp index a452830..3d55e97 100644 --- a/src/components/memory.hpp +++ b/src/components/memory.hpp @@ -12,6 +12,7 @@ #include namespace memory{ - void getProcMem(crow::json::wvalue&); - void getEasyMem(crow::json::wvalue&); + bool getProcMem(crow::json::wvalue&); + bool getRawProcMem(std::string&); + bool getEasyMem(crow::json::wvalue&); } diff --git a/src/routes.cpp b/src/routes.cpp index b6758d1..87ec0a8 100644 --- a/src/routes.cpp +++ b/src/routes.cpp @@ -7,11 +7,15 @@ #include "routes.hpp" void setRoutes(crow::SimpleApp& app){ - CROW_ROUTE(app, "/proc/meminfo")([]{ + CROW_ROUTE(app, "/proc/meminfo")([](const crow::request& req){ crow::json::wvalue json; - memory::getProcMem(json); - return json; + std::cerr << "Accept: " << req.get_header_value("Accept") << "\n"; + + if(memory::getProcMem(json)) + return crow::response(200, json.dump()); + else + return crow::response(503, json.dump()); }); CROW_ROUTE(app, "/mem")([]{