From d1c87720d3ce527cde3486b3b8154fb6316e279e Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Thu, 6 Apr 2006 16:25:20 +0000 Subject: [PATCH] period-connect which specifies the period we do connect statistics --- etc/config.xml | 3 ++- include/yazproxy/limit-connect.h | 3 ++- include/yazproxy/proxy.h | 6 ++++-- src/limit-connect.cpp | 8 +++++++- src/proxyp.h | 5 +++-- src/yaz-proxy-config.cpp | 29 +++++++++++++++++++++++++++-- src/yaz-proxy.cpp | 19 ++++++++++++++----- 7 files changed, 59 insertions(+), 14 deletions(-) diff --git a/etc/config.xml b/etc/config.xml index 7b3cf3c..c48eab2 100644 --- a/etc/config.xml +++ b/etc/config.xml @@ -1,5 +1,5 @@ - + 30 10 + 10 5 client-requests server-requests client-ip doc diff --git a/include/yazproxy/limit-connect.h b/include/yazproxy/limit-connect.h index 7efaf58..a557502 100644 --- a/include/yazproxy/limit-connect.h +++ b/include/yazproxy/limit-connect.h @@ -1,4 +1,4 @@ -/* $Id: limit-connect.h,v 1.2 2006-03-30 14:16:34 adam Exp $ +/* $Id: limit-connect.h,v 1.3 2006-04-06 16:25:21 adam Exp $ Copyright (c) 1998-2006, Index Data. This file is part of the yazproxy. @@ -32,6 +32,7 @@ public: void add_connect(const char *peername); int get_total(const char *peername); void cleanup(bool all); + void set_period(int sec); private: struct Peer; diff --git a/include/yazproxy/proxy.h b/include/yazproxy/proxy.h index 07d6b08..e80924f 100644 --- a/include/yazproxy/proxy.h +++ b/include/yazproxy/proxy.h @@ -1,4 +1,4 @@ -/* $Id: proxy.h,v 1.31 2006-04-06 12:04:19 adam Exp $ +/* $Id: proxy.h,v 1.32 2006-04-06 16:25:21 adam Exp $ Copyright (c) 1998-2006, Index Data. This file is part of the yazproxy. @@ -108,8 +108,10 @@ class YAZ_EXPORT Yaz_Proxy : public yazpp_1::Z_Assoc { } m_timeout_mode; int m_initial_reduce; - int m_connect_max; + int m_max_connect; + int m_max_connect_period; int m_limit_connect; + int m_limit_connect_period; int m_search_max; Yaz_bw m_bw_stat; int m_pdu_max; diff --git a/src/limit-connect.cpp b/src/limit-connect.cpp index 9197ea3..270d567 100644 --- a/src/limit-connect.cpp +++ b/src/limit-connect.cpp @@ -1,4 +1,4 @@ -/* $Id: limit-connect.cpp,v 1.1 2006-03-30 10:35:15 adam Exp $ +/* $Id: limit-connect.cpp,v 1.2 2006-04-06 16:25:21 adam Exp $ Copyright (c) 1998-2006, Index Data. This file is part of the yazproxy. @@ -43,11 +43,17 @@ LimitConnect::LimitConnect() m_peers = 0; } + LimitConnect::~LimitConnect() { cleanup(true); } +void LimitConnect::set_period(int sec) +{ + m_period = sec; +} + LimitConnect::Peer::Peer(int sz, const char *peername) : m_bw(sz) { m_peername = xstrdup(peername); diff --git a/src/proxyp.h b/src/proxyp.h index c412566..8a94f9a 100644 --- a/src/proxyp.h +++ b/src/proxyp.h @@ -1,4 +1,4 @@ -/* $Id: proxyp.h,v 1.15 2006-04-06 01:16:55 adam Exp $ +/* $Id: proxyp.h,v 1.16 2006-04-06 16:25:21 adam Exp $ Copyright (c) 1998-2006, Index Data. This file is part of the yazproxy. @@ -105,7 +105,8 @@ public: const char **default_client_query_charset); void get_generic_info(int *log_mask, int *max_clients, - int *max_connect, int *limit_connect); + int *max_connect, int *limit_connect, + int *period_connect); int get_file_access_info(const char *path); diff --git a/src/yaz-proxy-config.cpp b/src/yaz-proxy-config.cpp index ec7e396..dbf03a5 100644 --- a/src/yaz-proxy-config.cpp +++ b/src/yaz-proxy-config.cpp @@ -1,4 +1,4 @@ -/* $Id: yaz-proxy-config.cpp,v 1.29 2006-04-06 12:04:19 adam Exp $ +/* $Id: yaz-proxy-config.cpp,v 1.30 2006-04-06 16:25:21 adam Exp $ Copyright (c) 1998-2006, Index Data. This file is part of the yazproxy. @@ -55,6 +55,7 @@ class Yaz_ProxyConfigP { xmlNodePtr find_target_node(const char *name, const char *db); xmlNodePtr find_target_db(xmlNodePtr ptr, const char *db); const char *get_text(xmlNodePtr ptr); + void get_period(xmlNodePtr ptr, int *period); int check_type_1_attributes(ODR odr, xmlNodePtr ptr, Z_AttributeList *attrs, char **addinfo); @@ -165,6 +166,18 @@ const char *Yaz_ProxyConfigP::get_text(xmlNodePtr ptr) } return 0; } + +void Yaz_ProxyConfigP::get_period(xmlNodePtr ptr, int *period) +{ + struct _xmlAttr *attr; + *period = 60; + for (attr = ptr->properties; attr; attr = attr->next) + { + if (!strcmp((const char *) attr->name, "period") && + attr->children && attr->children->type == XML_TEXT_NODE) + *period = atoi((const char *) attr->children->content); + } +} #endif #if HAVE_XSLT @@ -1008,7 +1021,8 @@ int Yaz_ProxyConfig::get_file_access_info(const char *path) void Yaz_ProxyConfig::get_generic_info(int *log_mask, int *max_clients, int *max_connect, - int *limit_connect) + int *limit_connect, + int *period_connect) { *max_connect = 0; *limit_connect = 0; @@ -1060,18 +1074,29 @@ void Yaz_ProxyConfig::get_generic_info(int *log_mask, } } else if (ptr->type == XML_ELEMENT_NODE && + !strcmp((const char *) ptr->name, "period-connect")) + { + const char *t = m_cp->get_text(ptr); + if (t) + *period_connect = atoi(t); + } + else if (ptr->type == XML_ELEMENT_NODE && !strcmp((const char *) ptr->name, "max-connect")) { const char *t = m_cp->get_text(ptr); if (t) + { *max_connect = atoi(t); + } } else if (ptr->type == XML_ELEMENT_NODE && !strcmp((const char *) ptr->name, "limit-connect")) { const char *t = m_cp->get_text(ptr); if (t) + { *limit_connect = atoi(t); + } } else if (ptr->type == XML_ELEMENT_NODE && !strcmp((const char *) ptr->name, "target")) diff --git a/src/yaz-proxy.cpp b/src/yaz-proxy.cpp index a6930ea..5de2824 100644 --- a/src/yaz-proxy.cpp +++ b/src/yaz-proxy.cpp @@ -1,4 +1,4 @@ -/* $Id: yaz-proxy.cpp,v 1.50 2006-04-06 12:04:20 adam Exp $ +/* $Id: yaz-proxy.cpp,v 1.51 2006-04-06 16:25:21 adam Exp $ Copyright (c) 1998-2006, Index Data. This file is part of the yazproxy. @@ -232,8 +232,10 @@ Yaz_Proxy::Yaz_Proxy(IPDU_Observable *the_PDU_Observable, m_bw_max = 0; m_pdu_max = 0; m_search_max = 0; - m_connect_max = 0; + m_max_connect = 0; + m_max_connect_period = 0; m_limit_connect = 0; + m_limit_connect_period = 0; m_timeout_mode = timeout_normal; m_timeout_gdu = 0; m_max_record_retrieve = 0; @@ -354,8 +356,12 @@ int Yaz_Proxy::set_config(const char *config) m_config_fname = xstrdup(config); int r = m_config->read_xml(config); if (!r) + { + int period = 60; m_config->get_generic_info(&m_log_mask, &m_max_clients, - &m_connect_max, &m_limit_connect); + &m_max_connect, &m_limit_connect, &period); + m_connect.set_period(period); + } return r; } @@ -406,8 +412,11 @@ Yaz_ProxyConfig *Yaz_Proxy::check_reconfigure() else { m_log_mask = 0; + int period = 60; cfg->get_generic_info(&m_log_mask, &m_max_clients, - &m_connect_max, &m_limit_connect); + &m_max_connect, &m_limit_connect, + &period); + m_connect.set_period(period); } } else @@ -438,7 +447,7 @@ IPDU_Observer *Yaz_Proxy::sessionNotify(IPDU_Observable m_connect.add_connect(peername); int connect_total = m_connect.get_total(peername); - int connect_max = m_connect_max; + int connect_max = m_max_connect; if (connect_max && connect_total > connect_max) { yaz_log(YLOG_LOG, "%sconnect not accepted total=%d max=%d", -- 1.7.10.4