Browse Source

Fixed metadata member order; added prometheus-specific endpoint

pull/15/head
Jessica James 4 years ago
parent
commit
e1e7320c82
  1. 24
      src/Plugins/RenX/RenX.ServerList/RenX_ServerList.cpp
  2. 7
      src/Plugins/RenX/RenX.ServerList/RenX_ServerList.h

24
src/Plugins/RenX/RenX.ServerList/RenX_ServerList.cpp

@ -151,6 +151,7 @@ bool RenX_ServerListPlugin::initialize()
RenX_ServerListPlugin::server_list_long_page_name = this->config.get("HumanServersPageName"_jrs, "servers_long"_jrs); RenX_ServerListPlugin::server_list_long_page_name = this->config.get("HumanServersPageName"_jrs, "servers_long"_jrs);
RenX_ServerListPlugin::server_page_name = this->config.get("ServerPageName"_jrs, "server"_jrs); RenX_ServerListPlugin::server_page_name = this->config.get("ServerPageName"_jrs, "server"_jrs);
RenX_ServerListPlugin::metadata_page_name = this->config.get("MetadataPageName"_jrs, "metadata"_jrs); RenX_ServerListPlugin::metadata_page_name = this->config.get("MetadataPageName"_jrs, "metadata"_jrs);
RenX_ServerListPlugin::metadata_prometheus_page_name = this->config.get("MetadataPrometheusPageName"_jrs, "metadata_prometheus"_jrs);
/** Initialize content */ /** Initialize content */
Jupiter::HTTP::Server &server = getHTTPServer(); Jupiter::HTTP::Server &server = getHTTPServer();
@ -187,6 +188,14 @@ bool RenX_ServerListPlugin::initialize()
content->free_result = false; content->free_result = false;
server.hook(RenX_ServerListPlugin::web_hostname, RenX_ServerListPlugin::web_path, content); server.hook(RenX_ServerListPlugin::web_hostname, RenX_ServerListPlugin::web_path, content);
// Metadata page
content = new Jupiter::HTTP::Server::Content(RenX_ServerListPlugin::metadata_prometheus_page_name, handle_metadata_prometheus_page);
content->language = &Jupiter::HTTP::Content::Language::ENGLISH;
content->type = &CONTENT_TYPE_APPLICATION_JSON;
content->charset = &Jupiter::HTTP::Content::Type::Text::Charset::UTF8;
content->free_result = false;
server.hook(RenX_ServerListPlugin::web_hostname, RenX_ServerListPlugin::web_path, content);
this->updateServerList(); this->updateServerList();
return true; return true;
} }
@ -214,6 +223,11 @@ Jupiter::ReadableString *RenX_ServerListPlugin::getMetadataJSON()
return &metadata_json; return &metadata_json;
} }
Jupiter::ReadableString *RenX_ServerListPlugin::getMetadataPrometheus()
{
return &metadata_prometheus;
}
constexpr const char *json_bool_as_cstring(bool in) constexpr const char *json_bool_as_cstring(bool in)
{ {
return in ? "true" : "false"; return in ? "true" : "false";
@ -602,7 +616,10 @@ void RenX_ServerListPlugin::updateMetadata() {
} }
metadata_json.format(R"json({"player_count":%u,"server_count":%u})json", metadata_json.format(R"json({"player_count":%u,"server_count":%u})json",
server_count, player_count); player_count, server_count);
metadata_prometheus.format("player_count %u\nserver_count %u\n",
player_count, server_count);
} }
Jupiter::ReferenceString RenX_ServerListPlugin::getListServerAddress(const RenX::Server& server) { Jupiter::ReferenceString RenX_ServerListPlugin::getListServerAddress(const RenX::Server& server) {
@ -771,6 +788,11 @@ Jupiter::ReadableString *handle_metadata_page(const Jupiter::ReadableString&)
return pluginInstance.getMetadataJSON(); return pluginInstance.getMetadataJSON();
} }
Jupiter::ReadableString *handle_metadata_prometheus_page(const Jupiter::ReadableString&)
{
return pluginInstance.getMetadataPrometheus();
}
extern "C" JUPITER_EXPORT Jupiter::Plugin *getPlugin() extern "C" JUPITER_EXPORT Jupiter::Plugin *getPlugin()
{ {
return &pluginInstance; return &pluginInstance;

7
src/Plugins/RenX/RenX.ServerList/RenX_ServerList.h

@ -37,6 +37,7 @@ public: // RenX_ServerListPlugin
Jupiter::ReadableString *getServerListJSON(); Jupiter::ReadableString *getServerListJSON();
Jupiter::ReadableString* getMetadataJSON(); Jupiter::ReadableString* getMetadataJSON();
Jupiter::ReadableString* getMetadataPrometheus();
void addServerToServerList(RenX::Server &server); void addServerToServerList(RenX::Server &server);
void updateServerList(); void updateServerList();
@ -57,13 +58,15 @@ public: // RenX::Plugin
void RenX_OnMapLoad(RenX::Server &server, const Jupiter::ReadableString &map) override; void RenX_OnMapLoad(RenX::Server &server, const Jupiter::ReadableString &map) override;
private: private:
Jupiter::StringS server_list_json, metadata_json; Jupiter::StringS server_list_json, metadata_json, metadata_prometheus;
Jupiter::StringS web_hostname, web_path, server_list_page_name, server_list_long_page_name, server_page_name, metadata_page_name; Jupiter::StringS web_hostname, web_path;
Jupiter::StringS server_list_page_name, server_list_long_page_name, server_page_name, metadata_page_name, metadata_prometheus_page_name;
}; };
Jupiter::ReadableString *handle_server_list_page(const Jupiter::ReadableString &); Jupiter::ReadableString *handle_server_list_page(const Jupiter::ReadableString &);
Jupiter::ReadableString *handle_server_list_long_page(const Jupiter::ReadableString &); Jupiter::ReadableString *handle_server_list_long_page(const Jupiter::ReadableString &);
Jupiter::ReadableString *handle_server_page(const Jupiter::ReadableString &); Jupiter::ReadableString *handle_server_page(const Jupiter::ReadableString &);
Jupiter::ReadableString *handle_metadata_page(const Jupiter::ReadableString &); Jupiter::ReadableString *handle_metadata_page(const Jupiter::ReadableString &);
Jupiter::ReadableString *handle_metadata_prometheus_page(const Jupiter::ReadableString&);
#endif // _RENX_SERVERLIST_H_HEADER #endif // _RENX_SERVERLIST_H_HEADER

Loading…
Cancel
Save