diff options
author | nga <nga@yandex-team.ru> | 2022-02-10 16:48:09 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:48:09 +0300 |
commit | c2a1af049e9deca890e9923abe64fe6c59060348 (patch) | |
tree | b222e5ac2e2e98872661c51ccceee5da0d291e13 /library/cpp/monlib/service | |
parent | 1f553f46fb4f3c5eec631352cdd900a0709016af (diff) | |
download | ydb-c2a1af049e9deca890e9923abe64fe6c59060348.tar.gz |
Restoring authorship annotation for <nga@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/monlib/service')
18 files changed, 290 insertions, 290 deletions
diff --git a/library/cpp/monlib/service/mon_service_http_request.cpp b/library/cpp/monlib/service/mon_service_http_request.cpp index b8d1d27b98..5d805631d9 100644 --- a/library/cpp/monlib/service/mon_service_http_request.cpp +++ b/library/cpp/monlib/service/mon_service_http_request.cpp @@ -1,8 +1,8 @@ #include "mon_service_http_request.h" -#include "monservice.h" - -using namespace NMonitoring; - +#include "monservice.h" + +using namespace NMonitoring; + IMonHttpRequest::~IMonHttpRequest() { } @@ -10,9 +10,9 @@ TMonService2HttpRequest::~TMonService2HttpRequest() { } TString TMonService2HttpRequest::GetServiceTitle() const { - return MonService->GetTitle(); -} - + return MonService->GetTitle(); +} + IOutputStream& TMonService2HttpRequest::Output() { return *Out; } diff --git a/library/cpp/monlib/service/mon_service_http_request.h b/library/cpp/monlib/service/mon_service_http_request.h index 8dd75044cf..b4f2f8f0c5 100644 --- a/library/cpp/monlib/service/mon_service_http_request.h +++ b/library/cpp/monlib/service/mon_service_http_request.h @@ -1,13 +1,13 @@ -#pragma once - +#pragma once + #include "service.h" -#include <util/stream/output.h> - -namespace NMonitoring { +#include <util/stream/output.h> + +namespace NMonitoring { class TMonService2; class IMonPage; - + // XXX: IHttpRequest is already taken struct IMonHttpRequest { virtual ~IMonHttpRequest(); @@ -40,12 +40,12 @@ namespace NMonitoring { IMonPage* const MonPage; const TString PathInfo; TMonService2HttpRequest* const Parent; - + TMonService2HttpRequest( IOutputStream* out, const IHttpRequest* httpRequest, - TMonService2* monService, IMonPage* monPage, + TMonService2* monService, IMonPage* monPage, const TString& pathInfo, - TMonService2HttpRequest* parent) + TMonService2HttpRequest* parent) : Out(out) , HttpRequest(httpRequest) , MonService(monService) @@ -54,9 +54,9 @@ namespace NMonitoring { , Parent(parent) { } - + ~TMonService2HttpRequest() override; - + IOutputStream& Output() override; HTTP_METHOD GetMethod() const override; TStringBuf GetPath() const override; @@ -67,7 +67,7 @@ namespace NMonitoring { TStringBuf GetPostContent() const override { return HttpRequest->GetPostContent(); } - + TStringBuf GetHeader(TStringBuf name) const override; TStringBuf GetCookie(TStringBuf name) const override; const THttpHeaders& GetHeaders() const override; @@ -86,5 +86,5 @@ namespace NMonitoring { TString GetServiceTitle() const override; }; - + } diff --git a/library/cpp/monlib/service/monservice.cpp b/library/cpp/monlib/service/monservice.cpp index 49a1c941e4..d1b9cda1d2 100644 --- a/library/cpp/monlib/service/monservice.cpp +++ b/library/cpp/monlib/service/monservice.cpp @@ -1,17 +1,17 @@ -#include "monservice.h" +#include "monservice.h" #include <library/cpp/malloc/api/malloc.h> #include <library/cpp/string_utils/base64/base64.h> #include <library/cpp/svnversion/svnversion.h> -#include <util/generic/map.h> +#include <util/generic/map.h> #include <util/generic/ptr.h> -#include <util/system/hostname.h> +#include <util/system/hostname.h> #include <google/protobuf/text_format.h> - -using namespace NMonitoring; - + +using namespace NMonitoring; + TMonService2::TMonService2(ui16 port, const TString& host, ui32 threads, const TString& title, THolder<IAuthProvider> auth) : TMonService2(HttpServerOptions(port, host, threads), title, std::move(auth)) { @@ -19,15 +19,15 @@ TMonService2::TMonService2(ui16 port, const TString& host, ui32 threads, const T TMonService2::TMonService2(const THttpServerOptions& options, const TString& title, THolder<IAuthProvider> auth) : NMonitoring::TMtHttpServer(options, std::bind(&TMonService2::ServeRequest, this, std::placeholders::_1, std::placeholders::_2)) - , Title(title) - , IndexMonPage(new TIndexMonPage("", Title)) + , Title(title) + , IndexMonPage(new TIndexMonPage("", Title)) , AuthProvider_{std::move(auth)} -{ +{ Y_VERIFY(!!title); time_t t = time(nullptr); - ctime_r(&t, StartTime); -} - + ctime_r(&t, StartTime); +} + TMonService2::TMonService2(const THttpServerOptions& options, TSimpleSharedPtr<IThreadPool> pool, const TString& title, THolder<IAuthProvider> auth) : NMonitoring::TMtHttpServer(options, std::bind(&TMonService2::ServeRequest, this, std::placeholders::_1, std::placeholders::_2), std::move(pool)) , Title(title) @@ -50,33 +50,33 @@ TMonService2::TMonService2(ui16 port, const TString& title, THolder<IAuthProvide } void TMonService2::OutputIndex(IOutputStream& out) { - IndexMonPage->OutputIndex(out, true); -} - + IndexMonPage->OutputIndex(out, true); +} + void TMonService2::OutputIndexPage(IOutputStream& out) { - out << HTTPOKHTML; - out << "<html>\n"; - IndexMonPage->OutputHead(out); - OutputIndexBody(out); - out << "</html>\n"; -} - + out << HTTPOKHTML; + out << "<html>\n"; + IndexMonPage->OutputHead(out); + OutputIndexBody(out); + out << "</html>\n"; +} + void TMonService2::OutputIndexBody(IOutputStream& out) { - out << "<body>\n"; - - // part of common navbar - out << "<ol class='breadcrumb'>\n"; - out << "<li class='active'>" << Title << "</li>\n"; - out << "</ol>\n"; - - out << "<div class='container'>\n" - << "<h2>" << Title << "</h2>\n"; - OutputIndex(out); - out - << "<div>\n" - << "</body>\n"; -} - + out << "<body>\n"; + + // part of common navbar + out << "<ol class='breadcrumb'>\n"; + out << "<li class='active'>" << Title << "</li>\n"; + out << "</ol>\n"; + + out << "<div class='container'>\n" + << "<h2>" << Title << "</h2>\n"; + OutputIndex(out); + out + << "<div>\n" + << "</body>\n"; +} + void TMonService2::ServeRequest(IOutputStream& out, const NMonitoring::IHttpRequest& request) { TString path = request.GetPath(); Y_VERIFY(path.StartsWith('/')); @@ -95,34 +95,34 @@ void TMonService2::ServeRequest(IOutputStream& out, const NMonitoring::IHttpRequ } } - if (path == "/") { - OutputIndexPage(out); - } else { - TMonService2HttpRequest monService2HttpRequest( + if (path == "/") { + OutputIndexPage(out); + } else { + TMonService2HttpRequest monService2HttpRequest( &out, &request, this, IndexMonPage.Get(), path, nullptr); - IndexMonPage->Output(monService2HttpRequest); - } -} - + IndexMonPage->Output(monService2HttpRequest); + } +} + void TMonService2::Register(IMonPage* page) { - IndexMonPage->Register(page); -} - + IndexMonPage->Register(page); +} + void TMonService2::Register(TMonPagePtr page) { IndexMonPage->Register(std::move(page)); } TIndexMonPage* TMonService2::RegisterIndexPage(const TString& path, const TString& title) { return IndexMonPage->RegisterIndexPage(path, title); -} - +} + IMonPage* TMonService2::FindPage(const TString& relativePath) { - return IndexMonPage->FindPage(relativePath); -} - + return IndexMonPage->FindPage(relativePath); +} + TIndexMonPage* TMonService2::FindIndexPage(const TString& relativePath) { - return IndexMonPage->FindIndexPage(relativePath); -} + return IndexMonPage->FindIndexPage(relativePath); +} void TMonService2::SortPages() { IndexMonPage->SortPages(); diff --git a/library/cpp/monlib/service/monservice.h b/library/cpp/monlib/service/monservice.h index 288c6089a1..8f5e52fcdb 100644 --- a/library/cpp/monlib/service/monservice.h +++ b/library/cpp/monlib/service/monservice.h @@ -1,5 +1,5 @@ -#pragma once - +#pragma once + #include "service.h" #include "auth.h" #include "mon_service_http_request.h" @@ -7,18 +7,18 @@ #include <library/cpp/monlib/service/pages/index_mon_page.h> #include <library/cpp/monlib/service/pages/mon_page.h> -#include <util/system/progname.h> +#include <util/system/progname.h> #include <functional> - -namespace NMonitoring { + +namespace NMonitoring { class TMonService2: public TMtHttpServer { protected: const TString Title; char StartTime[26]; TIntrusivePtr<TIndexMonPage> IndexMonPage; THolder<IAuthProvider> AuthProvider_; - + public: static THttpServerOptions HttpServerOptions(ui16 port, const TString& host, ui32 threads) { THttpServerOptions opts(port); @@ -32,7 +32,7 @@ namespace NMonitoring { opts.EnableRejectExcessConnections(true); return opts; } - + static THttpServerOptions HttpServerOptions(ui16 port, ui32 threads) { return HttpServerOptions(port, TString(), threads); } @@ -43,31 +43,31 @@ namespace NMonitoring { explicit TMonService2(ui16 port, const TString& host, ui32 threads, const TString& title = GetProgramName(), THolder<IAuthProvider> auth = nullptr); explicit TMonService2(const THttpServerOptions& options, const TString& title = GetProgramName(), THolder<IAuthProvider> auth = nullptr); explicit TMonService2(const THttpServerOptions& options, TSimpleSharedPtr<IThreadPool> pool, const TString& title = GetProgramName(), THolder<IAuthProvider> auth = nullptr); - + ~TMonService2() override { } - + const char* GetStartTime() const { return StartTime; } - + const TString& GetTitle() const { return Title; } - + virtual void ServeRequest(IOutputStream& out, const NMonitoring::IHttpRequest& request); virtual void OutputIndex(IOutputStream& out); virtual void OutputIndexPage(IOutputStream& out); virtual void OutputIndexBody(IOutputStream& out); - + void Register(IMonPage* page); void Register(TMonPagePtr page); TIndexMonPage* RegisterIndexPage(const TString& path, const TString& title); - + IMonPage* FindPage(const TString& relativePath); TIndexMonPage* FindIndexPage(const TString& relativePath); void SortPages(); }; - + } diff --git a/library/cpp/monlib/service/pages/diag_mon_page.cpp b/library/cpp/monlib/service/pages/diag_mon_page.cpp index cf073e9224..2493ff4fba 100644 --- a/library/cpp/monlib/service/pages/diag_mon_page.cpp +++ b/library/cpp/monlib/service/pages/diag_mon_page.cpp @@ -1,9 +1,9 @@ -#include "diag_mon_page.h" - -using namespace NMonitoring; - +#include "diag_mon_page.h" + +using namespace NMonitoring; + void TDiagMonPage::OutputText(IOutputStream& out, NMonitoring::IMonHttpRequest& request) { out << "uri: " << request.GetUri() << "\n"; out << "path: " << request.GetPath() << "\n"; out << "path info: " << request.GetPathInfo() << "\n"; -} +} diff --git a/library/cpp/monlib/service/pages/diag_mon_page.h b/library/cpp/monlib/service/pages/diag_mon_page.h index bb16711700..761194d4ec 100644 --- a/library/cpp/monlib/service/pages/diag_mon_page.h +++ b/library/cpp/monlib/service/pages/diag_mon_page.h @@ -1,16 +1,16 @@ -#pragma once - -#include "pre_mon_page.h" - -namespace NMonitoring { +#pragma once + +#include "pre_mon_page.h" + +namespace NMonitoring { // internal diagnostics page struct TDiagMonPage: public TPreMonPage { TDiagMonPage() : TPreMonPage("diag", "Diagnostics Page") { } - + void OutputText(IOutputStream& out, NMonitoring::IMonHttpRequest&) override; }; - + } diff --git a/library/cpp/monlib/service/pages/html_mon_page.cpp b/library/cpp/monlib/service/pages/html_mon_page.cpp index 7b2a7cb135..eb4eb3b66c 100644 --- a/library/cpp/monlib/service/pages/html_mon_page.cpp +++ b/library/cpp/monlib/service/pages/html_mon_page.cpp @@ -1,20 +1,20 @@ -#include "html_mon_page.h" - +#include "html_mon_page.h" + #include <library/cpp/monlib/service/pages/templates.h> - -using namespace NMonitoring; - + +using namespace NMonitoring; + void THtmlMonPage::Output(NMonitoring::IMonHttpRequest& request) { IOutputStream& out = request.Output(); - out << HTTPOKHTML; + out << HTTPOKHTML; HTML(out) { - out << "<!DOCTYPE html>\n"; + out << "<!DOCTYPE html>\n"; HTML_TAG() { HEAD() { - if (!!Title) { - out << "<title>" << Title << "</title>\n"; - } + if (!!Title) { + out << "<title>" << Title << "</title>\n"; + } out << "<link rel='stylesheet' href='https://yastatic.net/bootstrap/3.3.1/css/bootstrap.min.css'>\n"; out << "<script language='javascript' type='text/javascript' src='https://yastatic.net/jquery/2.1.3/jquery.min.js'></script>\n"; out << "<script language='javascript' type='text/javascript' src='https://yastatic.net/bootstrap/3.3.1/js/bootstrap.min.js'></script>\n"; @@ -35,17 +35,17 @@ void THtmlMonPage::Output(NMonitoring::IMonHttpRequest& request) { } BODY() { OutputNavBar(out); - + DIV_CLASS("container") { - if (!!Title) { - out << "<h2>" << Title << "</h2>"; - } - OutputContent(request); + if (!!Title) { + out << "<h2>" << Title << "</h2>"; + } + OutputContent(request); } } } } -} +} void THtmlMonPage::NotFound(NMonitoring::IMonHttpRequest& request) const { IOutputStream& out = request.Output(); diff --git a/library/cpp/monlib/service/pages/html_mon_page.h b/library/cpp/monlib/service/pages/html_mon_page.h index a3e260866e..e87c53b62b 100644 --- a/library/cpp/monlib/service/pages/html_mon_page.h +++ b/library/cpp/monlib/service/pages/html_mon_page.h @@ -1,8 +1,8 @@ -#pragma once - -#include "mon_page.h" - -namespace NMonitoring { +#pragma once + +#include "mon_page.h" + +namespace NMonitoring { struct THtmlMonPage: public IMonPage { THtmlMonPage(const TString& path, const TString& title = TString(), @@ -11,9 +11,9 @@ namespace NMonitoring { , OutputTableSorterJsCss(outputTableSorterJsCss) { } - + void Output(NMonitoring::IMonHttpRequest& request) override; - + void NotFound(NMonitoring::IMonHttpRequest& request) const; void NoContent(NMonitoring::IMonHttpRequest& request) const; @@ -21,5 +21,5 @@ namespace NMonitoring { bool OutputTableSorterJsCss; }; - + } diff --git a/library/cpp/monlib/service/pages/index_mon_page.cpp b/library/cpp/monlib/service/pages/index_mon_page.cpp index 108c1945cd..83ff8b529a 100644 --- a/library/cpp/monlib/service/pages/index_mon_page.cpp +++ b/library/cpp/monlib/service/pages/index_mon_page.cpp @@ -1,72 +1,72 @@ #include "index_mon_page.h" -#include <util/generic/cast.h> +#include <util/generic/cast.h> #include <util/string/ascii.h> - -using namespace NMonitoring; - + +using namespace NMonitoring; + void TIndexMonPage::OutputIndexPage(IMonHttpRequest& request) { request.Output() << HTTPOKHTML; request.Output() << "<html>\n"; OutputHead(request.Output()); - OutputBody(request); + OutputBody(request); request.Output() << "</html>\n"; -} - +} + void TIndexMonPage::Output(IMonHttpRequest& request) { TStringBuf pathInfo = request.GetPathInfo(); if (pathInfo.empty() || pathInfo == TStringBuf("/")) { - OutputIndexPage(request); - return; - } - + OutputIndexPage(request); + return; + } + Y_VERIFY(pathInfo.StartsWith('/')); - - TMonPagePtr found; - // analogous to CGI PATH_INFO - { - TGuard<TMutex> g(Mtx); + + TMonPagePtr found; + // analogous to CGI PATH_INFO + { + TGuard<TMutex> g(Mtx); TStringBuf pathTmp = request.GetPathInfo(); - for (;;) { - TPagesByPath::iterator i = PagesByPath.find(pathTmp); - if (i != PagesByPath.end()) { - found = i->second; + for (;;) { + TPagesByPath::iterator i = PagesByPath.find(pathTmp); + if (i != PagesByPath.end()) { + found = i->second; pathInfo = request.GetPathInfo().substr(pathTmp.size()); Y_VERIFY(pathInfo.empty() || pathInfo.StartsWith('/')); - break; - } - size_t slash = pathTmp.find_last_of('/'); + break; + } + size_t slash = pathTmp.find_last_of('/'); Y_VERIFY(slash != TString::npos); - pathTmp = pathTmp.substr(0, slash); - if (!pathTmp) { - break; - } - } - } + pathTmp = pathTmp.substr(0, slash); + if (!pathTmp) { + break; + } + } + } if (found) { THolder<IMonHttpRequest> child(request.MakeChild(found.Get(), TString{pathInfo})); found->Output(*child); - } else { + } else { request.Output() << HTTPNOTFOUND; - } -} - + } +} + void TIndexMonPage::OutputIndex(IOutputStream& out, bool pathEndsWithSlash) { - TGuard<TMutex> g(Mtx); + TGuard<TMutex> g(Mtx); for (auto& Page : Pages) { IMonPage* page = Page.Get(); - if (page->IsInIndex()) { + if (page->IsInIndex()) { TString pathToDir = ""; - if (!pathEndsWithSlash) { - pathToDir = this->GetPath() + "/"; - } - out << "<a href='" << pathToDir << page->GetPath() << "'>" << page->GetTitle() << "</a><br/>\n"; - } - } -} - + if (!pathEndsWithSlash) { + pathToDir = this->GetPath() + "/"; + } + out << "<a href='" << pathToDir << page->GetPath() << "'>" << page->GetTitle() << "</a><br/>\n"; + } + } +} + void TIndexMonPage::Register(TMonPagePtr page) { - TGuard<TMutex> g(Mtx); + TGuard<TMutex> g(Mtx); auto insres = PagesByPath.insert(std::make_pair("/" + page->GetPath(), page)); if (insres.second) { // new unique page just inserted, update Pages @@ -81,8 +81,8 @@ void TIndexMonPage::Register(TMonPagePtr page) { insres.first->second = page; } page->Parent = this; -} - +} + TIndexMonPage* TIndexMonPage::RegisterIndexPage(const TString& path, const TString& title) { TGuard<TMutex> g(Mtx); TIndexMonPage* page = VerifyDynamicCast<TIndexMonPage*>(FindPage(path)); @@ -92,50 +92,50 @@ TIndexMonPage* TIndexMonPage::RegisterIndexPage(const TString& path, const TStri page = new TIndexMonPage(path, title); Register(page); return VerifyDynamicCast<TIndexMonPage*>(page); -} - +} + IMonPage* TIndexMonPage::FindPage(const TString& relativePath) { - TGuard<TMutex> g(Mtx); - + TGuard<TMutex> g(Mtx); + Y_VERIFY(!relativePath.StartsWith('/')); - TPagesByPath::iterator i = PagesByPath.find("/" + relativePath); - if (i == PagesByPath.end()) { + TPagesByPath::iterator i = PagesByPath.find("/" + relativePath); + if (i == PagesByPath.end()) { return nullptr; - } else { - return i->second.Get(); - } -} - + } else { + return i->second.Get(); + } +} + TIndexMonPage* TIndexMonPage::FindIndexPage(const TString& relativePath) { - return VerifyDynamicCast<TIndexMonPage*>(FindPage(relativePath)); -} - + return VerifyDynamicCast<TIndexMonPage*>(FindPage(relativePath)); +} + void TIndexMonPage::OutputCommonJsCss(IOutputStream& out) { out << "<link rel='stylesheet' href='https://yastatic.net/bootstrap/3.3.1/css/bootstrap.min.css'>\n"; out << "<script language='javascript' type='text/javascript' src='https://yastatic.net/jquery/2.1.3/jquery.min.js'></script>\n"; out << "<script language='javascript' type='text/javascript' src='https://yastatic.net/bootstrap/3.3.1/js/bootstrap.min.js'></script>\n"; -} - +} + void TIndexMonPage::OutputHead(IOutputStream& out) { - out << "<head>\n"; - OutputCommonJsCss(out); - out << "<title>" << Title << "</title>\n"; - out << "</head>\n"; -} - + out << "<head>\n"; + OutputCommonJsCss(out); + out << "<title>" << Title << "</title>\n"; + out << "</head>\n"; +} + void TIndexMonPage::OutputBody(IMonHttpRequest& req) { auto& out = req.Output(); out << "<body>\n"; - - // part of common navbar + + // part of common navbar OutputNavBar(out); - + out << "<div class='container'>\n" << "<h2>" << Title << "</h2>\n"; OutputIndex(out, req.GetPathInfo().EndsWith('/')); out << "<div>\n" - << "</body>\n"; -} + << "</body>\n"; +} void TIndexMonPage::SortPages() { TGuard<TMutex> g(Mtx); diff --git a/library/cpp/monlib/service/pages/index_mon_page.h b/library/cpp/monlib/service/pages/index_mon_page.h index 9a1ff45145..bf514a3105 100644 --- a/library/cpp/monlib/service/pages/index_mon_page.h +++ b/library/cpp/monlib/service/pages/index_mon_page.h @@ -1,38 +1,38 @@ -#pragma once - -#include "mon_page.h" - -namespace NMonitoring { +#pragma once + +#include "mon_page.h" + +namespace NMonitoring { struct TIndexMonPage: public IMonPage { TMutex Mtx; typedef TVector<TMonPagePtr> TPages; TPages Pages; typedef THashMap<TString, TMonPagePtr> TPagesByPath; TPagesByPath PagesByPath; - + TIndexMonPage(const TString& path, const TString& title) : IMonPage(path, title) { } - + ~TIndexMonPage() override { } - + void Output(IMonHttpRequest& request) override; void OutputIndexPage(IMonHttpRequest& request); virtual void OutputIndex(IOutputStream& out, bool pathEndsWithSlash); virtual void OutputCommonJsCss(IOutputStream& out); void OutputHead(IOutputStream& out); void OutputBody(IMonHttpRequest& out); - + void Register(TMonPagePtr page); TIndexMonPage* RegisterIndexPage(const TString& path, const TString& title); IMonPage* FindPage(const TString& relativePath); TIndexMonPage* FindIndexPage(const TString& relativePath); - + void SortPages(); void ClearPages(); }; - + } diff --git a/library/cpp/monlib/service/pages/mon_page.cpp b/library/cpp/monlib/service/pages/mon_page.cpp index d5860f56b3..72033b1699 100644 --- a/library/cpp/monlib/service/pages/mon_page.cpp +++ b/library/cpp/monlib/service/pages/mon_page.cpp @@ -1,14 +1,14 @@ -#include "mon_page.h" - -using namespace NMonitoring; - +#include "mon_page.h" + +using namespace NMonitoring; + IMonPage::IMonPage(const TString& path, const TString& title) - : Path(path) - , Title(title) -{ + : Path(path) + , Title(title) +{ Y_VERIFY(!Path.StartsWith('/')); Y_VERIFY(!Path.EndsWith('/')); -} +} void IMonPage::OutputNavBar(IOutputStream& out) { TVector<const IMonPage*> parents; diff --git a/library/cpp/monlib/service/pages/mon_page.h b/library/cpp/monlib/service/pages/mon_page.h index 3d85131536..e396612bb0 100644 --- a/library/cpp/monlib/service/pages/mon_page.h +++ b/library/cpp/monlib/service/pages/mon_page.h @@ -1,12 +1,12 @@ -#pragma once - +#pragma once + #include <library/cpp/monlib/service/service.h> #include <library/cpp/monlib/service/mon_service_http_request.h> #include <util/generic/string.h> -#include <util/generic/ptr.h> - -namespace NMonitoring { +#include <util/generic/ptr.h> + +namespace NMonitoring { static const char HTTPOKTEXT[] = "HTTP/1.1 200 Ok\r\nContent-Type: text/plain\r\nConnection: Close\r\n\r\n"; static const char HTTPOKBIN[] = "HTTP/1.1 200 Ok\r\nContent-Type: application/octet-stream\r\nConnection: Close\r\n\r\n"; static const char HTTPOKHTML[] = "HTTP/1.1 200 Ok\r\nContent-Type: text/html\r\nConnection: Close\r\n\r\n"; @@ -19,48 +19,48 @@ namespace NMonitoring { static const char HTTPNOTFOUND[] = "HTTP/1.1 404 Invalid URI\r\nConnection: Close\r\n\r\nInvalid URL\r\n"; static const char HTTPUNAUTHORIZED[] = "HTTP/1.1 401 Unauthorized\r\nConnection: Close\r\n\r\nUnauthorized\r\n"; static const char HTTPFORBIDDEN[] = "HTTP/1.1 403 Forbidden\r\nConnection: Close\r\n\r\nForbidden\r\n"; - + // Fonts static const char HTTPOKFONTEOT[] = "HTTP/1.1 200 Ok\r\nContent-Type: application/vnd.ms-fontobject\r\nConnection: Close\r\n\r\n"; static const char HTTPOKFONTTTF[] = "HTTP/1.1 200 Ok\r\nContent-Type: application/x-font-ttf\r\nConnection: Close\r\n\r\n"; static const char HTTPOKFONTWOFF[] = "HTTP/1.1 200 Ok\r\nContent-Type: application/font-woff\r\nConnection: Close\r\n\r\n"; static const char HTTPOKFONTWOFF2[] = "HTTP/1.1 200 Ok\r\nContent-Type: application/font-woff2\r\nConnection: Close\r\n\r\n"; - + // Images static const char HTTPOKPNG[] = "HTTP/1.1 200 Ok\r\nContent-Type: image/png\r\nConnection: Close\r\n\r\n"; static const char HTTPOKSVG[] = "HTTP/1.1 200 Ok\r\nContent-Type: image/svg+xml\r\nConnection: Close\r\n\r\n"; class IMonPage; - + using TMonPagePtr = TIntrusivePtr<IMonPage>; - + class IMonPage: public TAtomicRefCount<IMonPage> { public: const TString Path; const TString Title; const IMonPage* Parent = nullptr; - + public: IMonPage(const TString& path, const TString& title = TString()); - + virtual ~IMonPage() { } - + void OutputNavBar(IOutputStream& out); virtual const TString& GetPath() const { return Path; } - + virtual const TString& GetTitle() const { return Title; } - + bool IsInIndex() const { return !Title.empty(); } - + virtual void Output(IMonHttpRequest& request) = 0; }; - -} + +} diff --git a/library/cpp/monlib/service/pages/pre_mon_page.cpp b/library/cpp/monlib/service/pages/pre_mon_page.cpp index c2244d559a..fc03a19b80 100644 --- a/library/cpp/monlib/service/pages/pre_mon_page.cpp +++ b/library/cpp/monlib/service/pages/pre_mon_page.cpp @@ -1,18 +1,18 @@ -#include "pre_mon_page.h" - -using namespace NMonitoring; - +#include "pre_mon_page.h" + +using namespace NMonitoring; + void TPreMonPage::OutputContent(NMonitoring::IMonHttpRequest& request) { auto& out = request.Output(); if (PreTag) { - BeforePre(request); + BeforePre(request); out << "<pre>\n"; OutputText(out, request); out << "</pre>\n"; } else { OutputText(out, request); } -} - +} + void TPreMonPage::BeforePre(NMonitoring::IMonHttpRequest&) { -} +} diff --git a/library/cpp/monlib/service/pages/pre_mon_page.h b/library/cpp/monlib/service/pages/pre_mon_page.h index e9cc871d8c..c9a923d39a 100644 --- a/library/cpp/monlib/service/pages/pre_mon_page.h +++ b/library/cpp/monlib/service/pages/pre_mon_page.h @@ -1,8 +1,8 @@ -#pragma once - -#include "html_mon_page.h" - -namespace NMonitoring { +#pragma once + +#include "html_mon_page.h" + +namespace NMonitoring { struct TPreMonPage: public THtmlMonPage { TPreMonPage(const TString& path, const TString& title = TString(), @@ -12,15 +12,15 @@ namespace NMonitoring { , PreTag(preTag) { } - + void OutputContent(NMonitoring::IMonHttpRequest& request) override; - + // hook to customize output virtual void BeforePre(NMonitoring::IMonHttpRequest& request); - + // put your text here virtual void OutputText(IOutputStream& out, NMonitoring::IMonHttpRequest&) = 0; - + const bool PreTag; }; diff --git a/library/cpp/monlib/service/pages/templates.cpp b/library/cpp/monlib/service/pages/templates.cpp index a155b3bab4..ece12bea71 100644 --- a/library/cpp/monlib/service/pages/templates.cpp +++ b/library/cpp/monlib/service/pages/templates.cpp @@ -1,9 +1,9 @@ #include "templates.h" namespace NMonitoring { - extern const char HtmlTag[] = "html"; - extern const char HeadTag[] = "head"; - extern const char BodyTag[] = "body"; + extern const char HtmlTag[] = "html"; + extern const char HeadTag[] = "head"; + extern const char BodyTag[] = "body"; extern const char DivTag[] = "div"; extern const char TableTag[] = "table"; extern const char TableHeadTag[] = "thead"; @@ -15,14 +15,14 @@ namespace NMonitoring { extern const char LabelTag[] = "label"; extern const char SpanTag[] = "span"; extern const char CaptionTag[] = "caption"; - extern const char PreTag[] = "pre"; + extern const char PreTag[] = "pre"; extern const char ParaTag[] = "p"; - extern const char H1Tag[] = "h1"; - extern const char H2Tag[] = "h2"; - extern const char H3Tag[] = "h3"; - extern const char H4Tag[] = "h4"; - extern const char H5Tag[] = "h5"; - extern const char H6Tag[] = "h6"; + extern const char H1Tag[] = "h1"; + extern const char H2Tag[] = "h2"; + extern const char H3Tag[] = "h3"; + extern const char H4Tag[] = "h4"; + extern const char H5Tag[] = "h5"; + extern const char H6Tag[] = "h6"; extern const char SmallTag[] = "small"; extern const char StrongTag[] = "strong"; extern const char ListTag[] = "li"; diff --git a/library/cpp/monlib/service/pages/templates.h b/library/cpp/monlib/service/pages/templates.h index 0c70fb8555..b4656f059f 100644 --- a/library/cpp/monlib/service/pages/templates.h +++ b/library/cpp/monlib/service/pages/templates.h @@ -19,7 +19,7 @@ #define TAG_CLASS_ID(name, cls, id) WITH_SCOPED(tmp, NMonitoring::name(__stream, cls, "", id)) #define TAG_CLASS_FOR(name, cls, for0) WITH_SCOPED(tmp, NMonitoring::name(__stream, cls, for0)) #define TAG_ATTRS(name, ...) WITH_SCOPED(tmp, NMonitoring::name(__stream, ##__VA_ARGS__)) - + #define HTML(str) WITH_SCOPED(__stream, NMonitoring::TOutputStreamRef(str)) #define HEAD() TAG(THead) @@ -54,7 +54,7 @@ #define PARA() TAG(TPara) #define PARA_CLASS(cls) TAG_CLASS(TPara, cls) - + #define H1() TAG(TH1) #define H1_CLASS(cls) TAG_CLASS(TH1, cls) #define H2() TAG(TH2) @@ -235,9 +235,9 @@ namespace NMonitoring { extern const char DTermTag[3]; extern const char DDescTag[3]; - typedef TTag<HtmlTag> THtml; - typedef TTag<HeadTag> THead; - typedef TTag<BodyTag> TBody; + typedef TTag<HtmlTag> THtml; + typedef TTag<HeadTag> THead; + typedef TTag<BodyTag> TBody; typedef TTag<DivTag> TDiv; typedef TTag<TableTag> TTable; typedef TTag<TableHeadTag> TTableHead; @@ -249,14 +249,14 @@ namespace NMonitoring { typedef TTag<LabelTag> TLabelC; typedef TTag<SpanTag> TSpanC; typedef TTag<CaptionTag> TCaption; - typedef TTag<PreTag> TPre; + typedef TTag<PreTag> TPre; typedef TTag<ParaTag> TPara; - typedef TTag<H1Tag> TH1; - typedef TTag<H2Tag> TH2; - typedef TTag<H3Tag> TH3; - typedef TTag<H4Tag> TH4; - typedef TTag<H5Tag> TH5; - typedef TTag<H6Tag> TH6; + typedef TTag<H1Tag> TH1; + typedef TTag<H2Tag> TH2; + typedef TTag<H3Tag> TH3; + typedef TTag<H4Tag> TH4; + typedef TTag<H5Tag> TH5; + typedef TTag<H6Tag> TH6; typedef TTag<SmallTag> TSMALL; typedef TTag<StrongTag> TSTRONG; typedef TTag<ListTag> TLIST; diff --git a/library/cpp/monlib/service/pages/version_mon_page.cpp b/library/cpp/monlib/service/pages/version_mon_page.cpp index 0afc042cc1..41e29417da 100644 --- a/library/cpp/monlib/service/pages/version_mon_page.cpp +++ b/library/cpp/monlib/service/pages/version_mon_page.cpp @@ -1,16 +1,16 @@ #include <library/cpp/svnversion/svnversion.h> #include <library/cpp/build_info/build_info.h> #include <library/cpp/malloc/api/malloc.h> - -#include "version_mon_page.h" - -using namespace NMonitoring; - + +#include "version_mon_page.h" + +using namespace NMonitoring; + void TVersionMonPage::OutputText(IOutputStream& out, NMonitoring::IMonHttpRequest&) { - const char* version = GetProgramSvnVersion(); - out << version; + const char* version = GetProgramSvnVersion(); + out << version; if (!TString(version).EndsWith("\n")) - out << "\n"; + out << "\n"; out << GetBuildInfo() << "\n\n"; - out << "linked with malloc: " << NMalloc::MallocInfo().Name << "\n"; -} + out << "linked with malloc: " << NMalloc::MallocInfo().Name << "\n"; +} diff --git a/library/cpp/monlib/service/pages/version_mon_page.h b/library/cpp/monlib/service/pages/version_mon_page.h index 2b342c679a..f7649947e4 100644 --- a/library/cpp/monlib/service/pages/version_mon_page.h +++ b/library/cpp/monlib/service/pages/version_mon_page.h @@ -1,15 +1,15 @@ -#pragma once - -#include "pre_mon_page.h" - -namespace NMonitoring { +#pragma once + +#include "pre_mon_page.h" + +namespace NMonitoring { struct TVersionMonPage: public TPreMonPage { TVersionMonPage(const TString& path = "ver", const TString& title = "Version") : TPreMonPage(path, title) { } - + void OutputText(IOutputStream& out, NMonitoring::IMonHttpRequest&) override; }; - + } |