-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
147 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#include "ps_cmd.h" | ||
#include <drogon/drogon.h> | ||
#include <httplib.h> | ||
#include <string> | ||
#include <tabulate/table.hpp> | ||
#include "nlohmann/json.hpp" | ||
#include "utils/logging_utils.h" | ||
#include "utils/string_utils.h" | ||
|
||
namespace commands { | ||
|
||
void PsCmd::Exec(const std::string& host, int port) { | ||
auto host_and_port{host + ":" + std::to_string(port)}; | ||
httplib::Client cli(host_and_port); | ||
|
||
auto res = cli.Get("/inferences/server/models"); | ||
if (!res || res->status != httplib::StatusCode::OK_200) { | ||
CLI_LOG("No model loaded!"); | ||
return; | ||
} | ||
|
||
auto body = nlohmann::json::parse(res->body); | ||
auto data = body["data"]; | ||
std::vector<ModelLoadedStatus> model_status_list; | ||
try { | ||
for (const auto& item : data) { | ||
ModelLoadedStatus model_status; | ||
model_status.engine = item["engine"]; | ||
model_status.model = item["id"]; | ||
model_status.ram = item["ram"]; | ||
model_status.start_time = item["start_time"]; | ||
model_status.vram = item["vram"]; | ||
model_status_list.push_back(model_status); | ||
} | ||
} catch (const std::exception& e) { | ||
CLI_LOG("Fail to get list model information: " + std::string(e.what())); | ||
} | ||
|
||
PrintModelStatusList(model_status_list); | ||
} | ||
|
||
void PsCmd::PrintModelStatusList( | ||
const std::vector<ModelLoadedStatus>& model_status_list) const { | ||
if (model_status_list.empty()) { | ||
CLI_LOG("No model loaded!"); | ||
return; | ||
} | ||
|
||
tabulate::Table table; | ||
table.add_row({"Model", "Engine", "RAM", "VRAM", "Up time"}); | ||
for (const auto& model_status : model_status_list) { | ||
table.add_row({ | ||
model_status.model, | ||
model_status.engine, | ||
model_status.ram, | ||
model_status.vram, | ||
string_utils::FormatTimeElapsed(model_status.start_time), | ||
}); | ||
} | ||
std::cout << table << std::endl; | ||
} | ||
|
||
}; // namespace commands |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#pragma once | ||
|
||
#include <string> | ||
#include <vector> | ||
|
||
namespace commands { | ||
|
||
struct ModelLoadedStatus { | ||
std::string engine; | ||
std::string model; | ||
std::string ram; | ||
uint64_t start_time; | ||
std::string vram; | ||
}; | ||
|
||
class PsCmd { | ||
public: | ||
explicit PsCmd() = default; | ||
|
||
void Exec(const std::string& host, int port); | ||
|
||
private: | ||
void PrintModelStatusList( | ||
const std::vector<ModelLoadedStatus>& model_status_list) const; | ||
}; | ||
|
||
} // namespace commands |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters