]>
Commit | Line | Data |
---|---|---|
12c86877 | 1 | /* |
12471842 PL |
2 | * This file is part of PowerDNS or dnsdist. |
3 | * Copyright -- PowerDNS.COM B.V. and its contributors | |
4 | * | |
5 | * This program is free software; you can redistribute it and/or modify | |
6 | * it under the terms of version 2 of the GNU General Public License as | |
7 | * published by the Free Software Foundation. | |
8 | * | |
9 | * In addition, for the avoidance of any doubt, permission is granted to | |
10 | * link this program with OpenSSL and to (re)distribute the binaries | |
11 | * produced as the result of such linking. | |
12 | * | |
13 | * This program is distributed in the hope that it will be useful, | |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | * GNU General Public License for more details. | |
17 | * | |
18 | * You should have received a copy of the GNU General Public License | |
19 | * along with this program; if not, write to the Free Software | |
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |
21 | */ | |
12c86877 BH |
22 | #ifndef WS_HH |
23 | #define WS_HH | |
24 | #include <string> | |
25 | #include <map> | |
26 | #include <time.h> | |
27 | #include <pthread.h> | |
12c86877 | 28 | #include "misc.hh" |
10f4eea8 | 29 | #include "namespaces.hh" |
12c86877 BH |
30 | |
31 | class Ewma | |
32 | { | |
33 | public: | |
34 | Ewma() : d_last(0), d_10(0), d_5(0), d_1(0), d_max(0){dt.set();} | |
35 | void submit(int val) | |
36 | { | |
37 | int rate=val-d_last; | |
38 | double difft=dt.udiff()/1000000.0; | |
39 | dt.set(); | |
40 | ||
41 | d_10=((600.0-difft)*d_10+(difft*rate))/600.0; | |
42 | d_5=((300.0-difft)*d_5+(difft*rate))/300.0; | |
43 | d_1=((60.0-difft)*d_1+(difft*rate))/60.0; | |
44 | d_max=max(d_1,d_max); | |
45 | ||
46 | d_last=val; | |
47 | } | |
48 | double get10() | |
49 | { | |
50 | return d_10; | |
51 | } | |
52 | double get5() | |
53 | { | |
54 | return d_5; | |
55 | } | |
56 | double get1() | |
57 | { | |
58 | return d_1; | |
59 | } | |
60 | double getMax() | |
61 | { | |
62 | return d_max; | |
63 | } | |
64 | private: | |
65 | DTime dt; | |
66 | int d_last; | |
67 | double d_10, d_5, d_1, d_max; | |
68 | }; | |
69 | ||
96d299db | 70 | class WebServer; |
02c04144 | 71 | class HttpRequest; |
80d59cd1 | 72 | class HttpResponse; |
12c86877 | 73 | |
dea47634 | 74 | class AuthWebServer |
12c86877 BH |
75 | { |
76 | public: | |
dea47634 | 77 | AuthWebServer(); |
12c86877 | 78 | void go(); |
b6f57093 | 79 | static string makePercentage(const double& val); |
c67bf8c5 | 80 | |
12c86877 | 81 | private: |
dea47634 | 82 | static void *webThreadHelper(void *); |
12c86877 | 83 | static void *statThreadHelper(void *p); |
80d59cd1 CH |
84 | void indexfunction(HttpRequest* req, HttpResponse* resp); |
85 | void cssfunction(HttpRequest* req, HttpResponse* resp); | |
86 | void jsonstat(HttpRequest* req, HttpResponse* resp); | |
87 | void registerApiHandler(const string& url, boost::function<void(HttpRequest*, HttpResponse*)> handler); | |
12c86877 BH |
88 | void printvars(ostringstream &ret); |
89 | void printargs(ostringstream &ret); | |
dea47634 | 90 | void webThread(); |
12c86877 BH |
91 | void statThread(); |
92 | pthread_t d_tid; | |
93 | ||
94 | time_t d_start; | |
95 | double d_min10, d_min5, d_min1; | |
96 | Ewma d_queries, d_cachehits, d_cachemisses; | |
97 | Ewma d_qcachehits, d_qcachemisses; | |
eace2c24 | 98 | WebServer *d_ws{nullptr}; |
12c86877 BH |
99 | }; |
100 | ||
101 | #endif |