]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Move Ewma impl to ws-auth.cc
authorFred Morcos <fred.morcos@open-xchange.com>
Tue, 12 Dec 2023 13:48:37 +0000 (14:48 +0100)
committerFred Morcos <fred.morcos@open-xchange.com>
Thu, 21 Dec 2023 14:41:41 +0000 (15:41 +0100)
pdns/ws-auth.cc
pdns/ws-auth.hh

index 4d2482cc0d48e44658fd6482a235a300c76ef390..ec429a30e198e5403409227f4c4dc3c05a52e491 100644 (file)
@@ -52,6 +52,42 @@ using json11::Json;
 
 extern StatBag S;
 
+Ewma::Ewma() { dt.set(); }
+
+void Ewma::submit(int val)
+{
+  int rate = val - d_last;
+  double difft = dt.udiff() / 1000000.0;
+  dt.set();
+
+  d_10 = ((600.0 - difft) * d_10 + (difft * rate)) / 600.0;
+  d_5 = ((300.0 - difft) * d_5 + (difft * rate)) / 300.0;
+  d_1 = ((60.0 - difft) * d_1 + (difft * rate)) / 60.0;
+  d_max = max(d_1, d_max);
+
+  d_last = val;
+}
+
+double Ewma::get10() const
+{
+  return d_10;
+}
+
+double Ewma::get5() const
+{
+  return d_5;
+}
+
+double Ewma::get1() const
+{
+  return d_1;
+}
+
+double Ewma::getMax() const
+{
+  return d_max;
+}
+
 // NOLINTNEXTLINE(readability-identifier-length)
 static void patchZone(UeberBackend& B, const DNSName& zonename, DomainInfo& di, HttpRequest* req, HttpResponse* resp);
 
index 42beee75f831e9ff235df50fcfb55dac3fb81339..c306a1fa2a448e9d3bef192dd8a00d7709d05295 100644 (file)
 class Ewma
 {
 public:
-  Ewma() : d_last(0), d_10(0), d_5(0), d_1(0), d_max(0){dt.set();}
-  void submit(int val) 
-  {
-    int rate=val-d_last;
-    double difft=dt.udiff()/1000000.0;
-    dt.set();
-    
-    d_10=((600.0-difft)*d_10+(difft*rate))/600.0;
-    d_5=((300.0-difft)*d_5+(difft*rate))/300.0;
-    d_1=((60.0-difft)*d_1+(difft*rate))/60.0;
-    d_max=max(d_1,d_max);
-      
-    d_last=val;
-  }
-  double get10()
-  {
-    return d_10;
-  }
-  double get5()
-  {
-    return d_5;
-  }
-  double get1()
-  {
-    return d_1;
-  }
-  double getMax()
-  {
-    return d_max;
-  }
+  Ewma();
+
+  void submit(int val);
+  double get10() const;
+  double get5() const;
+  double get1() const;
+  double getMax() const;
+
 private:
   DTime dt;
-  int d_last;
-  double d_10, d_5, d_1, d_max;
+  int d_last{};
+  double d_10{}, d_5{}, d_1{}, d_max{};
 };
 
 class AuthWebServer