aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/monlib/service/monservice.h
blob: 492bd9bec7683e6c70fbe85554b2235acc58fa98 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#pragma once

#include "service.h" 
#include "auth.h"
#include "mon_service_http_request.h" 
 
#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 <functional>

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); 
            if (!host.empty()) {
                opts.SetHost(host);
            }
            opts.SetClientTimeout(TDuration::Minutes(1)); 
            opts.EnableCompression(true); 
            opts.SetThreads(threads); 
            opts.SetMaxConnections(std::max<ui32>(100, threads));
            opts.EnableRejectExcessConnections(true);
            return opts; 
        } 

        static THttpServerOptions HttpServerOptions(ui16 port, ui32 threads) {
            return HttpServerOptions(port, TString(), threads);
        }

    public: 
        explicit TMonService2(ui16 port, const TString& title = GetProgramName(), THolder<IAuthProvider> auth = nullptr);
        explicit TMonService2(ui16 port, ui32 threads, const TString& title = GetProgramName(), THolder<IAuthProvider> auth = nullptr);
        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(); 
    }; 

}