]> granicus.if.org Git - pdns/commitdiff
finally finally get rid of 1e2% - apologies to Jeff Sipek for lying that this bug...
authorBert Hubert <bert.hubert@netherlabs.nl>
Sun, 29 Mar 2009 21:34:17 +0000 (21:34 +0000)
committerBert Hubert <bert.hubert@netherlabs.nl>
Sun, 29 Mar 2009 21:34:17 +0000 (21:34 +0000)
git-svn-id: svn://svn.powerdns.com/pdns/trunk/pdns@1343 d19b8d6e-7fed-0310-83ef-9ca221ded41b

pdns/ws.cc
pdns/ws.hh

index f9eeac8b9e374d2d248b53a6e754a21128623d40..460a28e62ebab3e6903f51c9872850cfa8c87d17 100644 (file)
@@ -104,12 +104,12 @@ void printtable(ostringstream &ret, const string &ringname, const string &title,
 
   int printed=0;
   for(vector<pair<string,int> >::const_iterator i=ring.begin();limit && i!=ring.end();++i,--limit) {
-    ret<<"<tr><td>"<<i->first<<"</td><td>"<<i->second<<"</td><td align=right>"<< (boost::format("%.01f") % (i->second*100.0/tot))<<"%</td>"<<endl;
+    ret<<"<tr><td>"<<i->first<<"</td><td>"<<i->second<<"</td><td align=right>"<< StatWebServer::makePercentage(i->second*100.0/tot)<<"</td>"<<endl;
     printed+=i->second;
   }
   ret<<"<tr><td colspan=3></td></tr>"<<endl;
   if(printed!=tot)
-    ret<<"<tr><td><b>Rest:</b></td><td><b>"<<tot-printed<<"</b></td><td align=right><b>"<< (boost::format("%.01f") % ((tot-printed)*100.0/tot))<<"%</b></td>"<<endl;
+    ret<<"<tr><td><b>Rest:</b></td><td><b>"<<tot-printed<<"</b></td><td align=right><b>"<< StatWebServer::makePercentage((tot-printed)*100.0/tot)<<"</b></td>"<<endl;
 
   ret<<"<tr><td><b>Total:</b></td><td><b>"<<tot<<"</td><td align=right><b>100%</b></td>";
   ret<<"</table><p>"<<endl;
@@ -136,6 +136,11 @@ void StatWebServer::printargs(ostringstream &ret)
   }
 }
 
+string StatWebServer::makePercentage(const double& val)
+{
+  return (boost::format("%.01f%%") % val).str();
+}
+
 string StatWebServer::indexfunction(const map<string,string> &varmap, void *ptr, bool *custom)
 {
 
@@ -178,18 +183,18 @@ string StatWebServer::indexfunction(const map<string,string> &varmap, void *ptr,
     "<br>"<<endl;
   
   if(sws->d_cachemisses.get10()+sws->d_cachehits.get10()>0)
-    ret<<"Cache hitrate, 1, 5, 10 minute averages: "<<setprecision(2)<<
-      (sws->d_cachehits.get1()*100.0)/((sws->d_cachehits.get1())+(sws->d_cachemisses.get1()))<<"%, "<<
-      (sws->d_cachehits.get5()*100.0)/((sws->d_cachehits.get5())+(sws->d_cachemisses.get5()))<<"%, "<<
-      (sws->d_cachehits.get10()*100.0)/((sws->d_cachehits.get10())+(sws->d_cachemisses.get10()))<<
-      "%<br>"<<endl;
+    ret<<"Cache hitrate, 1, 5, 10 minute averages: "<<
+      makePercentage((sws->d_cachehits.get1()*100.0)/((sws->d_cachehits.get1())+(sws->d_cachemisses.get1())))<<", "<<
+      makePercentage((sws->d_cachehits.get5()*100.0)/((sws->d_cachehits.get5())+(sws->d_cachemisses.get5())))<<", "<<
+      makePercentage((sws->d_cachehits.get10()*100.0)/((sws->d_cachehits.get10())+(sws->d_cachemisses.get10())))<<
+      "<br>"<<endl;
 
   if(sws->d_qcachemisses.get10()+sws->d_qcachehits.get10()>0)
     ret<<"Backend query cache hitrate, 1, 5, 10 minute averages: "<<setprecision(2)<<
-      (sws->d_qcachehits.get1()*100.0)/((sws->d_qcachehits.get1())+(sws->d_qcachemisses.get1()))<<"%, "<<
-      (sws->d_qcachehits.get5()*100.0)/((sws->d_qcachehits.get5())+(sws->d_qcachemisses.get5()))<<"%, "<<
-      (sws->d_qcachehits.get10()*100.0)/((sws->d_qcachehits.get10())+(sws->d_qcachemisses.get10()))<<
-      "%<br>"<<endl;
+      makePercentage((sws->d_qcachehits.get1()*100.0)/((sws->d_qcachehits.get1())+(sws->d_qcachemisses.get1())))<<", "<<
+      makePercentage((sws->d_qcachehits.get5()*100.0)/((sws->d_qcachehits.get5())+(sws->d_qcachemisses.get5())))<<", "<<
+      makePercentage((sws->d_qcachehits.get10()*100.0)/((sws->d_qcachehits.get10())+(sws->d_qcachemisses.get10())))<<
+      "<br>"<<endl;
 
   ret<<"Backend query load, 1, 5, 10 minute averages: "<<setprecision(3)<<
     sws->d_qcachemisses.get1()<<", "<<
index a43c134551782469bcbffa5aac0b4cedcb8b8cf6..291bb3e281dbadcc7c07da706977a4cd32fac4bd 100644 (file)
@@ -1,6 +1,6 @@
 /*
     PowerDNS Versatile Database Driven Nameserver
-    Copyright (C) 2002  PowerDNS.COM BV
+    Copyright (C) 2002 - 2009  PowerDNS.COM BV
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License version 2
@@ -81,10 +81,12 @@ class StatWebServer
 public:
   StatWebServer();
   void go();
+  static string makePercentage(const double& val);
 private:
   static void *threadHelper(void *);
   static void *statThreadHelper(void *p);
   static string indexfunction(const map<string,string> &varmap, void *ptr, bool *custom);
+
   void printvars(ostringstream &ret);
   void printargs(ostringstream &ret);
   void launch();