| 1 | /* |
|---|
| 2 | PowerDNS Versatile Database Driven Nameserver |
|---|
| 3 | Copyright (C) 2002 PowerDNS.COM BV |
|---|
| 4 | |
|---|
| 5 | This program is free software; you can redistribute it and/or modify |
|---|
| 6 | it under the terms of the GNU General Public License version 2 |
|---|
| 7 | as published by the Free Software Foundation |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | This program is distributed in the hope that it will be useful, |
|---|
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 13 | GNU General Public License for more details. |
|---|
| 14 | |
|---|
| 15 | You should have received a copy of the GNU General Public License |
|---|
| 16 | along with this program; if not, write to the Free Software |
|---|
| 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
|---|
| 18 | */ |
|---|
| 19 | #ifndef WS_HH |
|---|
| 20 | #define WS_HH |
|---|
| 21 | #include <string> |
|---|
| 22 | #include <map> |
|---|
| 23 | #include <time.h> |
|---|
| 24 | #include <pthread.h> |
|---|
| 25 | #include <sstream> |
|---|
| 26 | #include <iomanip> |
|---|
| 27 | |
|---|
| 28 | #ifndef WIN32 |
|---|
| 29 | # include <unistd.h> |
|---|
| 30 | #endif // WIN32 |
|---|
| 31 | |
|---|
| 32 | #ifdef HAVE_CONFIG_H |
|---|
| 33 | # include <config.h> |
|---|
| 34 | #endif // HAVE_CONFIG_H |
|---|
| 35 | |
|---|
| 36 | #include "misc.hh" |
|---|
| 37 | using namespace std; |
|---|
| 38 | |
|---|
| 39 | class Ewma |
|---|
| 40 | { |
|---|
| 41 | public: |
|---|
| 42 | Ewma() : d_last(0), d_10(0), d_5(0), d_1(0), d_max(0){dt.set();} |
|---|
| 43 | void submit(int val) |
|---|
| 44 | { |
|---|
| 45 | int rate=val-d_last; |
|---|
| 46 | double difft=dt.udiff()/1000000.0; |
|---|
| 47 | dt.set(); |
|---|
| 48 | |
|---|
| 49 | d_10=((600.0-difft)*d_10+(difft*rate))/600.0; |
|---|
| 50 | d_5=((300.0-difft)*d_5+(difft*rate))/300.0; |
|---|
| 51 | d_1=((60.0-difft)*d_1+(difft*rate))/60.0; |
|---|
| 52 | d_max=max(d_1,d_max); |
|---|
| 53 | |
|---|
| 54 | d_last=val; |
|---|
| 55 | } |
|---|
| 56 | double get10() |
|---|
| 57 | { |
|---|
| 58 | return d_10; |
|---|
| 59 | } |
|---|
| 60 | double get5() |
|---|
| 61 | { |
|---|
| 62 | return d_5; |
|---|
| 63 | } |
|---|
| 64 | double get1() |
|---|
| 65 | { |
|---|
| 66 | return d_1; |
|---|
| 67 | } |
|---|
| 68 | double getMax() |
|---|
| 69 | { |
|---|
| 70 | return d_max; |
|---|
| 71 | } |
|---|
| 72 | private: |
|---|
| 73 | DTime dt; |
|---|
| 74 | int d_last; |
|---|
| 75 | double d_10, d_5, d_1, d_max; |
|---|
| 76 | }; |
|---|
| 77 | |
|---|
| 78 | |
|---|
| 79 | class StatWebServer |
|---|
| 80 | { |
|---|
| 81 | public: |
|---|
| 82 | StatWebServer(); |
|---|
| 83 | void go(); |
|---|
| 84 | private: |
|---|
| 85 | static void *threadHelper(void *); |
|---|
| 86 | static void *statThreadHelper(void *p); |
|---|
| 87 | static string indexfunction(const map<string,string> &varmap, void *ptr, bool *custom); |
|---|
| 88 | void printvars(ostringstream &ret); |
|---|
| 89 | void printargs(ostringstream &ret); |
|---|
| 90 | void launch(); |
|---|
| 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; |
|---|
| 98 | }; |
|---|
| 99 | |
|---|
| 100 | #endif |
|---|