zoom: init member cqlt of Backend
[metaproxy-moved-to-github.git] / src / filter_frontend_net.cpp
index 57fab7a..7f448a2 100644 (file)
@@ -61,6 +61,10 @@ namespace metaproxy_1 {
             ZAssocServer **az;
             int m_duration_freq[22];
             double m_duration_lim[22];
+            double m_duration_max;
+            double m_duration_min;
+            double m_duration_total;
+            bool m_stop;
         public:
             Rep();
             ~Rep();
@@ -183,7 +187,15 @@ void yf::FrontendNet::ThreadPoolPackage::result(const char *t_info)
         while (m_p->m_duration_lim[ent] != 0.0 && duration > m_p->m_duration_lim[ent])
             ent++;
         m_p->m_duration_freq[ent]++;
-        
+
+        m_p->m_duration_total += duration;
+
+        if (m_p->m_duration_max < duration)
+            m_p->m_duration_max = duration;
+          
+        if (m_p->m_duration_min == 0.0 || m_p->m_duration_min > duration)
+            m_p->m_duration_min = duration;
+            
         if (m_p->m_msg_config.length())
         {
             Z_GDU *z_gdu = gdu->get();
@@ -291,24 +303,46 @@ void yf::FrontendNet::ZAssocChild::report(Z_HTTP_Request *hreq)
         number_total += m_p->m_duration_freq[i];
     number_total += m_p->m_duration_freq[i];
     
-    wrbuf_puts(w, "<?xml version=\"1.0\">\n");
+    wrbuf_puts(w, "<?xml version=\"1.0\"?>\n");
     wrbuf_puts(w, "<frontend_net>\n");
     wrbuf_printf(w, "  <responses frequency=\"%d\">\n", number_total);
     for (i = 0; m_p->m_duration_lim[i] != 0.0; i++)
     {
         if (m_p->m_duration_freq[i] > 0)
             wrbuf_printf(
-                w, "    <response mintime=\"%f\" "
-                "maxtime=\"%f\" frequency=\"%d\"/>\n",
+                w, "    <response duration_start=\"%f\" "
+                "duration_end=\"%f\" frequency=\"%d\"/>\n",
                 i > 0 ? m_p->m_duration_lim[i - 1] : 0.0,
                 m_p->m_duration_lim[i], m_p->m_duration_freq[i]);
     }
     
     if (m_p->m_duration_freq[i] > 0)
         wrbuf_printf(
-            w, "    <response mintime=\"%f\" frequency=\"%d\"/>\n",
+            w, "    <response duration_start=\"%f\" frequency=\"%d\"/>\n",
             m_p->m_duration_lim[i - 1], m_p->m_duration_freq[i]);
+
+    if (m_p->m_duration_max != 0.0)
+        wrbuf_printf(
+            w, "    <response duration_max=\"%f\"/>\n",
+            m_p->m_duration_max);
+    if (m_p->m_duration_min != 0.0)
+        wrbuf_printf(
+            w, "    <response duration_min=\"%f\"/>\n",
+            m_p->m_duration_min);
+    if (m_p->m_duration_total != 0.0)
+        wrbuf_printf(
+            w, "    <response duration_average=\"%f\"/>\n",
+            m_p->m_duration_total / number_total);
+       
     wrbuf_puts(w, " </responses>\n");
+    int thread_busy;
+    int thread_total;
+    m_thread_pool_observer->get_thread_info(thread_busy, thread_total);
+    
+    wrbuf_printf(w, " <thread_info busy=\"%d\" total=\"%d\"/>\n",
+                 thread_busy, thread_total);
+    
     wrbuf_puts(w, "</frontend_net>\n");
     
     hres->content_len = w.len();
@@ -328,6 +362,10 @@ void yf::FrontendNet::ZAssocChild::recv_GDU(Z_GDU *z_pdu, int len)
     {
         Z_HTTP_Request *hreq = z_pdu->u.HTTP_Request;
 
+        const char *f = z_HTTP_header_lookup(hreq->headers, "X-Forwarded-For");
+        if (f)
+            p->origin().set_tcpip_address(std::string(f), m_session.id());
+
         if (m_p->m_stat_req.length()
             && !strcmp(hreq->path, m_p->m_stat_req.c_str()))
         {
@@ -482,7 +520,11 @@ yf::FrontendNet::Rep::Rep()
     m_duration_lim[18] = 15.0;
     m_duration_lim[19] = 20.0;
     m_duration_lim[20] = 30.0;
-    m_duration_lim[21] = 0;
+    m_duration_lim[21] = 0.0;
+    m_duration_max = 0.0;
+    m_duration_min = 0.0;
+    m_duration_total = 0.0;
+    m_stop = false;
 }
 
 yf::FrontendNet::Rep::~Rep()
@@ -503,12 +545,7 @@ yf::FrontendNet::~FrontendNet()
 
 void yf::FrontendNet::stop() const
 {
-    if (m_p->az)
-    {
-        size_t i;
-        for (i = 0; i < m_p->m_ports.size(); i++)
-            m_p->az[i]->server("");
-    }
+    m_p->m_stop = true;
 }
 
 bool yf::FrontendNet::My_Timer_Thread::timeout()
@@ -552,6 +589,16 @@ void yf::FrontendNet::process(Package &package) const
     }
     while (m_p->mySocketManager.processEvent() > 0)
     {
+        if (m_p->m_stop)
+        {
+            m_p->m_stop = false;
+            if (m_p->az)
+            {
+                size_t i;
+                for (i = 0; i < m_p->m_ports.size(); i++)
+                    m_p->az[i]->server("");
+            }
+        }
         int no = m_p->mySocketManager.getNumberOfObservers();
         if (no <= 1)
             break;