]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: counters: factor out smp_fetch_sc*_kbytes_in
authorWilly Tarreau <w@1wt.eu>
Tue, 23 Jul 2013 15:17:10 +0000 (17:17 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 1 Aug 2013 19:17:14 +0000 (21:17 +0200)
smp_fetch_sc0_kbytes_in, smp_fetch_sc1_kbytes_in, smp_fetch_sc2_kbytes_in,
smp_fetch_src_kbytes_in and smp_fetch_kbytes_in were merged into a single
function which relies on the fetch name to decide what to return.

src/session.c

index 4413e40ebfe9f23592105cd413c5afacd7026be5..76dc676e30495db975e64ab6f6e6472a33d1ebff 100644 (file)
@@ -2996,16 +2996,24 @@ smp_fetch_sc_http_err_rate(struct proxy *px, struct session *l4, void *l7, unsig
        return 1;
 }
 
-/* set temp integer to the number of kbytes received from clients matching the stksess entry <ts> */
+/* set <smp> to the number of kbytes received from clients, as found in the
+ * session's tracked frontend counters. Supports being called as
+ * "sc[0-9]_kbytes_in" or "src_kbytes_in" only.
+ */
 static int
-smp_fetch_kbytes_in(struct stktable *table, struct sample *smp, struct stksess *ts)
+smp_fetch_sc_kbytes_in(struct proxy *px, struct session *l4, void *l7, unsigned int opt,
+                       const struct arg *args, struct sample *smp, const char *kw)
 {
+       struct stkctr *stkctr = smp_fetch_sc_stkctr(l4, args, kw);
+
+       if (!stkctr)
+               return 0;
+
        smp->flags = SMP_F_VOL_TEST;
        smp->type = SMP_T_UINT;
        smp->data.uint = 0;
-
-       if (ts != NULL) {
-               void *ptr = stktable_data_ptr(table, ts, STKTABLE_DT_BYTES_IN_CNT);
+       if (stkctr->entry != NULL) {
+               void *ptr = stktable_data_ptr(stkctr->table, stkctr->entry, STKTABLE_DT_BYTES_IN_CNT);
                if (!ptr)
                        return 0; /* parameter not stored */
                smp->data.uint = stktable_data_cast(ptr, bytes_in_cnt) >> 10;
@@ -3013,63 +3021,6 @@ smp_fetch_kbytes_in(struct stktable *table, struct sample *smp, struct stksess *
        return 1;
 }
 
-/* set temp integer to the number of kbytes received from clients according to the
- * session's tracked FE counters.
- */
-static int
-smp_fetch_sc0_kbytes_in(struct proxy *px, struct session *l4, void *l7, unsigned int opt,
-                        const struct arg *args, struct sample *smp, const char *kw)
-{
-       if (!l4->stkctr[0].entry)
-               return 0;
-
-       return smp_fetch_kbytes_in(l4->stkctr[0].table, smp, l4->stkctr[0].entry);
-}
-
-/* set temp integer to the number of kbytes received from clients according to the
- * session's tracked BE counters.
- */
-static int
-smp_fetch_sc1_kbytes_in(struct proxy *px, struct session *l4, void *l7, unsigned int opt,
-                        const struct arg *args, struct sample *smp, const char *kw)
-{
-       if (!l4->stkctr[1].entry)
-               return 0;
-
-       return smp_fetch_kbytes_in(l4->stkctr[1].table, smp, l4->stkctr[1].entry);
-}
-
-/* set temp integer to the number of kbytes received from clients according to the
- * session's tracked BE counters.
- */
-static int
-smp_fetch_sc2_kbytes_in(struct proxy *px, struct session *l4, void *l7, unsigned int opt,
-                        const struct arg *args, struct sample *smp, const char *kw)
-{
-       if (!l4->stkctr[2].entry)
-               return 0;
-
-       return smp_fetch_kbytes_in(l4->stkctr[2].table, smp, l4->stkctr[2].entry);
-}
-
-/* set temp integer to the number of kbytes received from the session's source
- * address in the table pointed to by expr.
- * Accepts exactly 1 argument of type table.
- */
-static int
-smp_fetch_src_kbytes_in(struct proxy *px, struct session *l4, void *l7, unsigned int opt,
-                       const struct arg *args, struct sample *smp, const char *kw)
-{
-       struct stktable_key *key;
-
-       key = addr_to_stktable_key(&l4->si[0].conn->addr.from);
-       if (!key)
-               return 0;
-
-       px = args->data.prx;
-       return smp_fetch_kbytes_in(&px->table, smp, stktable_lookup_key(&px->table, key));
-}
-
 /* set temp integer to the bytes rate from clients in the stksess entry <ts> over the
  * configured period.
  */
@@ -3380,7 +3331,7 @@ static struct sample_fetch_kw_list smp_fetch_keywords = {ILH, {
        { "sc0_http_req_cnt",   smp_fetch_sc_http_req_cnt,    0,           NULL, SMP_T_UINT, SMP_USE_INTRN, },
        { "sc0_http_req_rate",  smp_fetch_sc_http_req_rate,   0,           NULL, SMP_T_UINT, SMP_USE_INTRN, },
        { "sc0_inc_gpc0",       smp_fetch_sc_inc_gpc0,        0,           NULL, SMP_T_UINT, SMP_USE_INTRN, },
-       { "sc0_kbytes_in",      smp_fetch_sc0_kbytes_in,      0,           NULL, SMP_T_UINT, SMP_USE_L4CLI, },
+       { "sc0_kbytes_in",      smp_fetch_sc_kbytes_in,       0,           NULL, SMP_T_UINT, SMP_USE_L4CLI, },
        { "sc0_kbytes_out",     smp_fetch_sc0_kbytes_out,     0,           NULL, SMP_T_UINT, SMP_USE_L4CLI, },
        { "sc0_sess_cnt",       smp_fetch_sc_sess_cnt,        0,           NULL, SMP_T_UINT, SMP_USE_INTRN, },
        { "sc0_sess_rate",      smp_fetch_sc_sess_rate,       0,           NULL, SMP_T_UINT, SMP_USE_INTRN, },
@@ -3399,7 +3350,7 @@ static struct sample_fetch_kw_list smp_fetch_keywords = {ILH, {
        { "sc1_http_req_cnt",   smp_fetch_sc_http_req_cnt,    0,           NULL, SMP_T_UINT, SMP_USE_INTRN, },
        { "sc1_http_req_rate",  smp_fetch_sc_http_req_rate,   0,           NULL, SMP_T_UINT, SMP_USE_INTRN, },
        { "sc1_inc_gpc0",       smp_fetch_sc_inc_gpc0,        0,           NULL, SMP_T_UINT, SMP_USE_INTRN, },
-       { "sc1_kbytes_in",      smp_fetch_sc1_kbytes_in,      0,           NULL, SMP_T_UINT, SMP_USE_L4CLI, },
+       { "sc1_kbytes_in",      smp_fetch_sc_kbytes_in,       0,           NULL, SMP_T_UINT, SMP_USE_L4CLI, },
        { "sc1_kbytes_out",     smp_fetch_sc1_kbytes_out,     0,           NULL, SMP_T_UINT, SMP_USE_L4CLI, },
        { "sc1_sess_cnt",       smp_fetch_sc_sess_cnt,        0,           NULL, SMP_T_UINT, SMP_USE_INTRN, },
        { "sc1_sess_rate",      smp_fetch_sc_sess_rate,       0,           NULL, SMP_T_UINT, SMP_USE_INTRN, },
@@ -3418,7 +3369,7 @@ static struct sample_fetch_kw_list smp_fetch_keywords = {ILH, {
        { "sc2_http_req_cnt",   smp_fetch_sc_http_req_cnt,    0,           NULL, SMP_T_UINT, SMP_USE_INTRN, },
        { "sc2_http_req_rate",  smp_fetch_sc_http_req_rate,   0,           NULL, SMP_T_UINT, SMP_USE_INTRN, },
        { "sc2_inc_gpc0",       smp_fetch_sc_inc_gpc0,        0,           NULL, SMP_T_UINT, SMP_USE_INTRN, },
-       { "sc2_kbytes_in",      smp_fetch_sc2_kbytes_in,      0,           NULL, SMP_T_UINT, SMP_USE_L4CLI, },
+       { "sc2_kbytes_in",      smp_fetch_sc_kbytes_in,       0,           NULL, SMP_T_UINT, SMP_USE_L4CLI, },
        { "sc2_kbytes_out",     smp_fetch_sc2_kbytes_out,     0,           NULL, SMP_T_UINT, SMP_USE_L4CLI, },
        { "sc2_sess_cnt",       smp_fetch_sc_sess_cnt,        0,           NULL, SMP_T_UINT, SMP_USE_INTRN, },
        { "sc2_sess_rate",      smp_fetch_sc_sess_rate,       0,           NULL, SMP_T_UINT, SMP_USE_INTRN, },
@@ -3437,7 +3388,7 @@ static struct sample_fetch_kw_list smp_fetch_keywords = {ILH, {
        { "src_http_req_cnt",   smp_fetch_sc_http_req_cnt,    ARG1(1,TAB), NULL, SMP_T_UINT, SMP_USE_L4CLI, },
        { "src_http_req_rate",  smp_fetch_sc_http_req_rate,   ARG1(1,TAB), NULL, SMP_T_UINT, SMP_USE_L4CLI, },
        { "src_inc_gpc0",       smp_fetch_sc_inc_gpc0,        ARG1(1,TAB), NULL, SMP_T_UINT, SMP_USE_L4CLI, },
-       { "src_kbytes_in",      smp_fetch_src_kbytes_in,      ARG1(1,TAB), NULL, SMP_T_UINT, SMP_USE_L4CLI, },
+       { "src_kbytes_in",      smp_fetch_sc_kbytes_in,       ARG1(1,TAB), NULL, SMP_T_UINT, SMP_USE_L4CLI, },
        { "src_kbytes_out",     smp_fetch_src_kbytes_out,     ARG1(1,TAB), NULL, SMP_T_UINT, SMP_USE_L4CLI, },
        { "src_sess_cnt",       smp_fetch_sc_sess_cnt,        ARG1(1,TAB), NULL, SMP_T_UINT, SMP_USE_L4CLI, },
        { "src_sess_rate",      smp_fetch_sc_sess_rate,       ARG1(1,TAB), NULL, SMP_T_UINT, SMP_USE_L4CLI, },