mirror of
http://git.haproxy.org/git/haproxy.git/
synced 2025-04-27 05:18:00 +00:00
MEDIUM: stick-table: add new converters to fetch table data
These new converters make it possible to look up any sample expression in a table, and check whether an equivalent key exists or not, and if it exists, to retrieve the associated data (eg: gpc0, request rate, etc...). Till now it was only possible using tracking, but sometimes tracking is not suited to only retrieving such counters, either because it's done too early or because too many items need to be checked without necessarily being tracked. These converters all take a string on input, and then convert it again to the table's type. This means that if an input sample is of type IPv4 and the table is of type IP, it will first be converted to a string, then back to an IP address. This is a limitation of the current design which does not allow converters to declare that "any" type is supported on input. Since strings are the only types which can be cast to any other one, this method always works. The following converters were added : in_table, table_bytes_in_rate, table_bytes_out_rate, table_conn_cnt, table_conn_cur, table_conn_rate, table_gpc0, table_gpc0_rate, table_http_err_cnt, table_http_err_rate, table_http_req_cnt, table_http_req_rate, table_kbytes_in, table_kbytes_out, table_server_id, table_sess_cnt, table_sess_rate, table_trackers.
This commit is contained in:
parent
8fed9037cd
commit
d9f316ab83
@ -9972,6 +9972,13 @@ http_date([<offset>])
|
||||
emit Date header fields, Expires values in responses when combined with a
|
||||
positive offset, or Last-Modified values when the offset is negative.
|
||||
|
||||
in_table(<table>)
|
||||
Uses the string representation of the input sample to perform a look up in
|
||||
the specified table. If the key is not found in the table, a boolean false
|
||||
is returned. Otherwise a boolean true is returned. This can be used to verify
|
||||
the presence of a certain key in a table tracking some elements (eg: whether
|
||||
or not a source IP address or an Authorization header was already seen).
|
||||
|
||||
ipmask(<mask>)
|
||||
Apply a mask to an IPv4 address, and use the result for lookups and storage.
|
||||
This can be used to make all hosts within a certain mask to share the same
|
||||
@ -10067,6 +10074,145 @@ map_<match_type>_<output_type>(<map_file>[,<default_value>])
|
||||
| `---------------------------- key
|
||||
`------------------------------------ leading spaces ignored
|
||||
|
||||
table_bytes_in_rate(<table>)
|
||||
Uses the string representation of the input sample to perform a look up in
|
||||
the specified table. If the key is not found in the table, integer value zero
|
||||
is returned. Otherwise the converter returns the average client-to-server
|
||||
bytes rate associated with the input sample in the designated table, measured
|
||||
in amount of bytes over the period configured in the table. See also the
|
||||
sc_bytes_in_rate sample fetch keyword.
|
||||
|
||||
|
||||
table_bytes_out_rate(<table>)
|
||||
Uses the string representation of the input sample to perform a look up in
|
||||
the specified table. If the key is not found in the table, integer value zero
|
||||
is returned. Otherwise the converter returns the average server-to-client
|
||||
bytes rate associated with the input sample in the designated table, measured
|
||||
in amount of bytes over the period configured in the table. See also the
|
||||
sc_bytes_out_rate sample fetch keyword.
|
||||
|
||||
table_conn_cnt(<table>)
|
||||
Uses the string representation of the input sample to perform a look up in
|
||||
the specified table. If the key is not found in the table, integer value zero
|
||||
is returned. Otherwise the converter returns the cumulated amount of incoming
|
||||
connections associated with the input sample in the designated table. See
|
||||
also the sc_conn_cnt sample fetch keyword.
|
||||
|
||||
table_conn_cur(<table>)
|
||||
Uses the string representation of the input sample to perform a look up in
|
||||
the specified table. If the key is not found in the table, integer value zero
|
||||
is returned. Otherwise the converter returns the current amount of concurrent
|
||||
tracked connections associated with the input sample in the designated table.
|
||||
See also the sc_conn_cur sample fetch keyword.
|
||||
|
||||
table_conn_rate(<table>)
|
||||
Uses the string representation of the input sample to perform a look up in
|
||||
the specified table. If the key is not found in the table, integer value zero
|
||||
is returned. Otherwise the converter returns the average incoming connection
|
||||
rate associated with the input sample in the designated table. See also the
|
||||
sc_conn_rate sample fetch keyword.
|
||||
|
||||
table_gpc0(<table>)
|
||||
Uses the string representation of the input sample to perform a look up in
|
||||
the specified table. If the key is not found in the table, integer value zero
|
||||
is returned. Otherwise the converter returns the current value of the first
|
||||
general purpose counter associated with the input sample in the designated
|
||||
table. See also the sc_get_gpc0 sample fetch keyword.
|
||||
|
||||
table_gpc0_rate(<table>)
|
||||
Uses the string representation of the input sample to perform a look up in
|
||||
the specified table. If the key is not found in the table, integer value zero
|
||||
is returned. Otherwise the converter returns the frequency which the gpc0
|
||||
counter was incremented over the configured period in the table, associated
|
||||
with the input sample in the designated table. See also the sc_get_gpc0_rate
|
||||
sample fetch keyword.
|
||||
|
||||
table_http_err_cnt(<table>)
|
||||
Uses the string representation of the input sample to perform a look up in
|
||||
the specified table. If the key is not found in the table, integer value zero
|
||||
is returned. Otherwise the converter returns the cumulated amount of HTTP
|
||||
errors associated with the input sample in the designated table. See also the
|
||||
sc_http_err_cnt sample fetch keyword.
|
||||
|
||||
table_http_err_rate(<table>)
|
||||
Uses the string representation of the input sample to perform a look up in
|
||||
the specified table. If the key is not found in the table, integer value zero
|
||||
is returned. Otherwise the average rate of HTTP errors associated with the
|
||||
input sample in the designated table, measured in amount of errors over the
|
||||
period configured in the table. See also the sc_http_err_rate sample fetch
|
||||
keyword.
|
||||
|
||||
table_http_req_cnt(<table>)
|
||||
Uses the string representation of the input sample to perform a look up in
|
||||
the specified table. If the key is not found in the table, integer value zero
|
||||
is returned. Otherwise the converter returns the cumulated amount of HTTP
|
||||
requests associated with the input sample in the designated table. See also
|
||||
the sc_http_req_cnt sample fetch keyword.
|
||||
|
||||
table_http_req_rate(<table>)
|
||||
Uses the string representation of the input sample to perform a look up in
|
||||
the specified table. If the key is not found in the table, integer value zero
|
||||
is returned. Otherwise the average rate of HTTP requests associated with the
|
||||
input sample in the designated table, measured in amount of requests over the
|
||||
period configured in the table. See also the sc_http_req_rate sample fetch
|
||||
keyword.
|
||||
|
||||
table_kbytes_in(<table>)
|
||||
Uses the string representation of the input sample to perform a look up in
|
||||
the specified table. If the key is not found in the table, integer value zero
|
||||
is returned. Otherwise the converter returns the cumulated amount of client-
|
||||
to-server data associated with the input sample in the designated table,
|
||||
measured in kilobytes. The test is currently performed on 32-bit integers,
|
||||
which limits values to 4 terabytes. See also the sc_kbytes_in sample fetch
|
||||
keyword.
|
||||
|
||||
table_kbytes_out(<table>)
|
||||
Uses the string representation of the input sample to perform a look up in
|
||||
the specified table. If the key is not found in the table, integer value zero
|
||||
is returned. Otherwise the converter returns the cumulated amount of server-
|
||||
to-client data associated with the input sample in the designated table,
|
||||
measured in kilobytes. The test is currently performed on 32-bit integers,
|
||||
which limits values to 4 terabytes. See also the sc_kbytes_out sample fetch
|
||||
keyword.
|
||||
|
||||
table_server_id(<table>)
|
||||
Uses the string representation of the input sample to perform a look up in
|
||||
the specified table. If the key is not found in the table, integer value zero
|
||||
is returned. Otherwise the converter returns the server ID associated with
|
||||
the input sample in the designated table. A server ID is associated to a
|
||||
sample by a "stick" rule when a connection to a server succeeds. A server ID
|
||||
zero means that no server is associated with this key.
|
||||
|
||||
table_sess_cnt(<table>)
|
||||
Uses the string representation of the input sample to perform a look up in
|
||||
the specified table. If the key is not found in the table, integer value zero
|
||||
is returned. Otherwise the converter returns the cumulated amount of incoming
|
||||
sessions associated with the input sample in the designated table. Note that
|
||||
a session here refers to an incoming connection being accepted by the
|
||||
"tcp-request connection" rulesets. See also the sc_sess_cnt sample fetch
|
||||
keyword.
|
||||
|
||||
table_sess_rate(<table>)
|
||||
Uses the string representation of the input sample to perform a look up in
|
||||
the specified table. If the key is not found in the table, integer value zero
|
||||
is returned. Otherwise the converter returns the average incoming session
|
||||
rate associated with the input sample in the designated table. Note that a
|
||||
session here refers to an incoming connection being accepted by the
|
||||
"tcp-request connection" rulesets. See also the sc_sess_rate sample fetch
|
||||
keyword.
|
||||
|
||||
table_trackers(<table>)
|
||||
Uses the string representation of the input sample to perform a look up in
|
||||
the specified table. If the key is not found in the table, integer value zero
|
||||
is returned. Otherwise the converter returns the current amount of concurrent
|
||||
connections tracking the same key as the input sample in the designated
|
||||
table. It differs from table_conn_cur in that it does not rely on any stored
|
||||
information but on the table's reference count (the "use" value which is
|
||||
returned by "show table" on the CLI). This may sometimes be more suited for
|
||||
layer7 tracking. It can be used to tell a server how many concurrent
|
||||
connections there are from a given address for example. See also the
|
||||
sc_trackers sample fetch keyword.
|
||||
|
||||
upper
|
||||
Convert a string sample to upper case. This can only be placed after a string
|
||||
sample fetch function or after a transformation keyword returning a string
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include <ebmbtree.h>
|
||||
#include <ebsttree.h>
|
||||
|
||||
#include <proto/arg.h>
|
||||
#include <proto/proxy.h>
|
||||
#include <proto/sample.h>
|
||||
#include <proto/session.h>
|
||||
@ -739,3 +740,657 @@ struct proxy *find_stktable(const char *name)
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Casts sample <smp> to the type of the table specified in arg(0), and looks
|
||||
* it up into this table. Returns true if found, false otherwise. The input
|
||||
* type is STR so that input samples are converted to string (since all types
|
||||
* can be converted to strings), then the function casts the string again into
|
||||
* the table's type. This is a double conversion, but in the future we might
|
||||
* support automatic input types to perform the cast on the fly.
|
||||
*/
|
||||
static int sample_conv_in_table(const struct arg *arg_p, struct sample *smp)
|
||||
{
|
||||
struct stktable *t;
|
||||
struct stktable_key *key;
|
||||
struct stksess *ts;
|
||||
|
||||
t = &arg_p[0].data.prx->table;
|
||||
|
||||
key = smp_to_stkey(smp, t);
|
||||
if (!key)
|
||||
return 0;
|
||||
|
||||
ts = stktable_lookup_key(t, key);
|
||||
|
||||
smp->type = SMP_T_BOOL;
|
||||
smp->data.uint = !!ts;
|
||||
smp->flags = SMP_F_VOL_TEST;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Casts sample <smp> to the type of the table specified in arg(0), and looks
|
||||
* it up into this table. Returns the data rate received from clients in bytes/s
|
||||
* if the key is present in the table, otherwise zero, so that comparisons can
|
||||
* be easily performed. If the inspected parameter is not stored in the table,
|
||||
* <not found> is returned.
|
||||
*/
|
||||
static int sample_conv_table_bytes_in_rate(const struct arg *arg_p, struct sample *smp)
|
||||
{
|
||||
struct stktable *t;
|
||||
struct stktable_key *key;
|
||||
struct stksess *ts;
|
||||
void *ptr;
|
||||
|
||||
t = &arg_p[0].data.prx->table;
|
||||
|
||||
key = smp_to_stkey(smp, t);
|
||||
if (!key)
|
||||
return 0;
|
||||
|
||||
smp->flags = SMP_F_VOL_TEST;
|
||||
smp->type = SMP_T_UINT;
|
||||
smp->data.uint = 0;
|
||||
|
||||
ts = stktable_lookup_key(t, key);
|
||||
if (!ts) /* key not present */
|
||||
return 1;
|
||||
|
||||
ptr = stktable_data_ptr(t, ts, STKTABLE_DT_BYTES_IN_RATE);
|
||||
if (!ptr)
|
||||
return 0; /* parameter not stored */
|
||||
|
||||
smp->data.uint = read_freq_ctr_period(&stktable_data_cast(ptr, bytes_in_rate),
|
||||
t->data_arg[STKTABLE_DT_BYTES_IN_RATE].u);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Casts sample <smp> to the type of the table specified in arg(0), and looks
|
||||
* it up into this table. Returns the cumulated number of connections for the key
|
||||
* if the key is present in the table, otherwise zero, so that comparisons can
|
||||
* be easily performed. If the inspected parameter is not stored in the table,
|
||||
* <not found> is returned.
|
||||
*/
|
||||
static int sample_conv_table_conn_cnt(const struct arg *arg_p, struct sample *smp)
|
||||
{
|
||||
struct stktable *t;
|
||||
struct stktable_key *key;
|
||||
struct stksess *ts;
|
||||
void *ptr;
|
||||
|
||||
t = &arg_p[0].data.prx->table;
|
||||
|
||||
key = smp_to_stkey(smp, t);
|
||||
if (!key)
|
||||
return 0;
|
||||
|
||||
smp->flags = SMP_F_VOL_TEST;
|
||||
smp->type = SMP_T_UINT;
|
||||
smp->data.uint = 0;
|
||||
|
||||
ts = stktable_lookup_key(t, key);
|
||||
if (!ts) /* key not present */
|
||||
return 1;
|
||||
|
||||
ptr = stktable_data_ptr(t, ts, STKTABLE_DT_CONN_CNT);
|
||||
if (!ptr)
|
||||
return 0; /* parameter not stored */
|
||||
|
||||
smp->data.uint = stktable_data_cast(ptr, conn_cnt);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Casts sample <smp> to the type of the table specified in arg(0), and looks
|
||||
* it up into this table. Returns the number of concurrent connections for the
|
||||
* key if the key is present in the table, otherwise zero, so that comparisons
|
||||
* can be easily performed. If the inspected parameter is not stored in the
|
||||
* table, <not found> is returned.
|
||||
*/
|
||||
static int sample_conv_table_conn_cur(const struct arg *arg_p, struct sample *smp)
|
||||
{
|
||||
struct stktable *t;
|
||||
struct stktable_key *key;
|
||||
struct stksess *ts;
|
||||
void *ptr;
|
||||
|
||||
t = &arg_p[0].data.prx->table;
|
||||
|
||||
key = smp_to_stkey(smp, t);
|
||||
if (!key)
|
||||
return 0;
|
||||
|
||||
smp->flags = SMP_F_VOL_TEST;
|
||||
smp->type = SMP_T_UINT;
|
||||
smp->data.uint = 0;
|
||||
|
||||
ts = stktable_lookup_key(t, key);
|
||||
if (!ts) /* key not present */
|
||||
return 1;
|
||||
|
||||
ptr = stktable_data_ptr(t, ts, STKTABLE_DT_CONN_CUR);
|
||||
if (!ptr)
|
||||
return 0; /* parameter not stored */
|
||||
|
||||
smp->data.uint = stktable_data_cast(ptr, conn_cur);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Casts sample <smp> to the type of the table specified in arg(0), and looks
|
||||
* it up into this table. Returns the rate of incoming connections from the key
|
||||
* if the key is present in the table, otherwise zero, so that comparisons can
|
||||
* be easily performed. If the inspected parameter is not stored in the table,
|
||||
* <not found> is returned.
|
||||
*/
|
||||
static int sample_conv_table_conn_rate(const struct arg *arg_p, struct sample *smp)
|
||||
{
|
||||
struct stktable *t;
|
||||
struct stktable_key *key;
|
||||
struct stksess *ts;
|
||||
void *ptr;
|
||||
|
||||
t = &arg_p[0].data.prx->table;
|
||||
|
||||
key = smp_to_stkey(smp, t);
|
||||
if (!key)
|
||||
return 0;
|
||||
|
||||
smp->flags = SMP_F_VOL_TEST;
|
||||
smp->type = SMP_T_UINT;
|
||||
smp->data.uint = 0;
|
||||
|
||||
ts = stktable_lookup_key(t, key);
|
||||
if (!ts) /* key not present */
|
||||
return 1;
|
||||
|
||||
ptr = stktable_data_ptr(t, ts, STKTABLE_DT_CONN_RATE);
|
||||
if (!ptr)
|
||||
return 0; /* parameter not stored */
|
||||
|
||||
smp->data.uint = read_freq_ctr_period(&stktable_data_cast(ptr, conn_rate),
|
||||
t->data_arg[STKTABLE_DT_CONN_RATE].u);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Casts sample <smp> to the type of the table specified in arg(0), and looks
|
||||
* it up into this table. Returns the data rate sent to clients in bytes/s
|
||||
* if the key is present in the table, otherwise zero, so that comparisons can
|
||||
* be easily performed. If the inspected parameter is not stored in the table,
|
||||
* <not found> is returned.
|
||||
*/
|
||||
static int sample_conv_table_bytes_out_rate(const struct arg *arg_p, struct sample *smp)
|
||||
{
|
||||
struct stktable *t;
|
||||
struct stktable_key *key;
|
||||
struct stksess *ts;
|
||||
void *ptr;
|
||||
|
||||
t = &arg_p[0].data.prx->table;
|
||||
|
||||
key = smp_to_stkey(smp, t);
|
||||
if (!key)
|
||||
return 0;
|
||||
|
||||
smp->flags = SMP_F_VOL_TEST;
|
||||
smp->type = SMP_T_UINT;
|
||||
smp->data.uint = 0;
|
||||
|
||||
ts = stktable_lookup_key(t, key);
|
||||
if (!ts) /* key not present */
|
||||
return 1;
|
||||
|
||||
ptr = stktable_data_ptr(t, ts, STKTABLE_DT_BYTES_OUT_RATE);
|
||||
if (!ptr)
|
||||
return 0; /* parameter not stored */
|
||||
|
||||
smp->data.uint = read_freq_ctr_period(&stktable_data_cast(ptr, bytes_out_rate),
|
||||
t->data_arg[STKTABLE_DT_BYTES_OUT_RATE].u);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Casts sample <smp> to the type of the table specified in arg(0), and looks
|
||||
* it up into this table. Returns the value of the GPC0 counter for the key
|
||||
* if the key is present in the table, otherwise zero, so that comparisons can
|
||||
* be easily performed. If the inspected parameter is not stored in the table,
|
||||
* <not found> is returned.
|
||||
*/
|
||||
static int sample_conv_table_gpc0(const struct arg *arg_p, struct sample *smp)
|
||||
{
|
||||
struct stktable *t;
|
||||
struct stktable_key *key;
|
||||
struct stksess *ts;
|
||||
void *ptr;
|
||||
|
||||
t = &arg_p[0].data.prx->table;
|
||||
|
||||
key = smp_to_stkey(smp, t);
|
||||
if (!key)
|
||||
return 0;
|
||||
|
||||
smp->flags = SMP_F_VOL_TEST;
|
||||
smp->type = SMP_T_UINT;
|
||||
smp->data.uint = 0;
|
||||
|
||||
ts = stktable_lookup_key(t, key);
|
||||
if (!ts) /* key not present */
|
||||
return 1;
|
||||
|
||||
ptr = stktable_data_ptr(t, ts, STKTABLE_DT_GPC0);
|
||||
if (!ptr)
|
||||
return 0; /* parameter not stored */
|
||||
|
||||
smp->data.uint = stktable_data_cast(ptr, gpc0);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Casts sample <smp> to the type of the table specified in arg(0), and looks
|
||||
* it up into this table. Returns the event rate of the GPC0 counter for the key
|
||||
* if the key is present in the table, otherwise zero, so that comparisons can
|
||||
* be easily performed. If the inspected parameter is not stored in the table,
|
||||
* <not found> is returned.
|
||||
*/
|
||||
static int sample_conv_table_gpc0_rate(const struct arg *arg_p, struct sample *smp)
|
||||
{
|
||||
struct stktable *t;
|
||||
struct stktable_key *key;
|
||||
struct stksess *ts;
|
||||
void *ptr;
|
||||
|
||||
t = &arg_p[0].data.prx->table;
|
||||
|
||||
key = smp_to_stkey(smp, t);
|
||||
if (!key)
|
||||
return 0;
|
||||
|
||||
smp->flags = SMP_F_VOL_TEST;
|
||||
smp->type = SMP_T_UINT;
|
||||
smp->data.uint = 0;
|
||||
|
||||
ts = stktable_lookup_key(t, key);
|
||||
if (!ts) /* key not present */
|
||||
return 1;
|
||||
|
||||
ptr = stktable_data_ptr(t, ts, STKTABLE_DT_GPC0_RATE);
|
||||
if (!ptr)
|
||||
return 0; /* parameter not stored */
|
||||
|
||||
smp->data.uint = read_freq_ctr_period(&stktable_data_cast(ptr, gpc0_rate),
|
||||
t->data_arg[STKTABLE_DT_GPC0_RATE].u);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Casts sample <smp> to the type of the table specified in arg(0), and looks
|
||||
* it up into this table. Returns the cumulated number of HTTP request errors
|
||||
* for the key if the key is present in the table, otherwise zero, so that
|
||||
* comparisons can be easily performed. If the inspected parameter is not stored
|
||||
* in the table, <not found> is returned.
|
||||
*/
|
||||
static int sample_conv_table_http_err_cnt(const struct arg *arg_p, struct sample *smp)
|
||||
{
|
||||
struct stktable *t;
|
||||
struct stktable_key *key;
|
||||
struct stksess *ts;
|
||||
void *ptr;
|
||||
|
||||
t = &arg_p[0].data.prx->table;
|
||||
|
||||
key = smp_to_stkey(smp, t);
|
||||
if (!key)
|
||||
return 0;
|
||||
|
||||
smp->flags = SMP_F_VOL_TEST;
|
||||
smp->type = SMP_T_UINT;
|
||||
smp->data.uint = 0;
|
||||
|
||||
ts = stktable_lookup_key(t, key);
|
||||
if (!ts) /* key not present */
|
||||
return 1;
|
||||
|
||||
ptr = stktable_data_ptr(t, ts, STKTABLE_DT_HTTP_ERR_CNT);
|
||||
if (!ptr)
|
||||
return 0; /* parameter not stored */
|
||||
|
||||
smp->data.uint = stktable_data_cast(ptr, http_err_cnt);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Casts sample <smp> to the type of the table specified in arg(0), and looks
|
||||
* it up into this table. Returns the HTTP request error rate the key
|
||||
* if the key is present in the table, otherwise zero, so that comparisons can
|
||||
* be easily performed. If the inspected parameter is not stored in the table,
|
||||
* <not found> is returned.
|
||||
*/
|
||||
static int sample_conv_table_http_err_rate(const struct arg *arg_p, struct sample *smp)
|
||||
{
|
||||
struct stktable *t;
|
||||
struct stktable_key *key;
|
||||
struct stksess *ts;
|
||||
void *ptr;
|
||||
|
||||
t = &arg_p[0].data.prx->table;
|
||||
|
||||
key = smp_to_stkey(smp, t);
|
||||
if (!key)
|
||||
return 0;
|
||||
|
||||
smp->flags = SMP_F_VOL_TEST;
|
||||
smp->type = SMP_T_UINT;
|
||||
smp->data.uint = 0;
|
||||
|
||||
ts = stktable_lookup_key(t, key);
|
||||
if (!ts) /* key not present */
|
||||
return 1;
|
||||
|
||||
ptr = stktable_data_ptr(t, ts, STKTABLE_DT_HTTP_ERR_RATE);
|
||||
if (!ptr)
|
||||
return 0; /* parameter not stored */
|
||||
|
||||
smp->data.uint = read_freq_ctr_period(&stktable_data_cast(ptr, http_err_rate),
|
||||
t->data_arg[STKTABLE_DT_HTTP_ERR_RATE].u);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Casts sample <smp> to the type of the table specified in arg(0), and looks
|
||||
* it up into this table. Returns the cumulated number of HTTP request for the
|
||||
* key if the key is present in the table, otherwise zero, so that comparisons
|
||||
* can be easily performed. If the inspected parameter is not stored in the
|
||||
* table, <not found> is returned.
|
||||
*/
|
||||
static int sample_conv_table_http_req_cnt(const struct arg *arg_p, struct sample *smp)
|
||||
{
|
||||
struct stktable *t;
|
||||
struct stktable_key *key;
|
||||
struct stksess *ts;
|
||||
void *ptr;
|
||||
|
||||
t = &arg_p[0].data.prx->table;
|
||||
|
||||
key = smp_to_stkey(smp, t);
|
||||
if (!key)
|
||||
return 0;
|
||||
|
||||
smp->flags = SMP_F_VOL_TEST;
|
||||
smp->type = SMP_T_UINT;
|
||||
smp->data.uint = 0;
|
||||
|
||||
ts = stktable_lookup_key(t, key);
|
||||
if (!ts) /* key not present */
|
||||
return 1;
|
||||
|
||||
ptr = stktable_data_ptr(t, ts, STKTABLE_DT_HTTP_REQ_CNT);
|
||||
if (!ptr)
|
||||
return 0; /* parameter not stored */
|
||||
|
||||
smp->data.uint = stktable_data_cast(ptr, http_req_cnt);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Casts sample <smp> to the type of the table specified in arg(0), and looks
|
||||
* it up into this table. Returns the HTTP request rate the key if the key is
|
||||
* present in the table, otherwise zero, so that comparisons can be easily
|
||||
* performed. If the inspected parameter is not stored in the table, <not found>
|
||||
* is returned.
|
||||
*/
|
||||
static int sample_conv_table_http_req_rate(const struct arg *arg_p, struct sample *smp)
|
||||
{
|
||||
struct stktable *t;
|
||||
struct stktable_key *key;
|
||||
struct stksess *ts;
|
||||
void *ptr;
|
||||
|
||||
t = &arg_p[0].data.prx->table;
|
||||
|
||||
key = smp_to_stkey(smp, t);
|
||||
if (!key)
|
||||
return 0;
|
||||
|
||||
smp->flags = SMP_F_VOL_TEST;
|
||||
smp->type = SMP_T_UINT;
|
||||
smp->data.uint = 0;
|
||||
|
||||
ts = stktable_lookup_key(t, key);
|
||||
if (!ts) /* key not present */
|
||||
return 1;
|
||||
|
||||
ptr = stktable_data_ptr(t, ts, STKTABLE_DT_HTTP_REQ_RATE);
|
||||
if (!ptr)
|
||||
return 0; /* parameter not stored */
|
||||
|
||||
smp->data.uint = read_freq_ctr_period(&stktable_data_cast(ptr, http_req_rate),
|
||||
t->data_arg[STKTABLE_DT_HTTP_REQ_RATE].u);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Casts sample <smp> to the type of the table specified in arg(0), and looks
|
||||
* it up into this table. Returns the volume of datareceived from clients in kbytes
|
||||
* if the key is present in the table, otherwise zero, so that comparisons can
|
||||
* be easily performed. If the inspected parameter is not stored in the table,
|
||||
* <not found> is returned.
|
||||
*/
|
||||
static int sample_conv_table_kbytes_in(const struct arg *arg_p, struct sample *smp)
|
||||
{
|
||||
struct stktable *t;
|
||||
struct stktable_key *key;
|
||||
struct stksess *ts;
|
||||
void *ptr;
|
||||
|
||||
t = &arg_p[0].data.prx->table;
|
||||
|
||||
key = smp_to_stkey(smp, t);
|
||||
if (!key)
|
||||
return 0;
|
||||
|
||||
smp->flags = SMP_F_VOL_TEST;
|
||||
smp->type = SMP_T_UINT;
|
||||
smp->data.uint = 0;
|
||||
|
||||
ts = stktable_lookup_key(t, key);
|
||||
if (!ts) /* key not present */
|
||||
return 1;
|
||||
|
||||
ptr = stktable_data_ptr(t, ts, STKTABLE_DT_BYTES_IN_CNT);
|
||||
if (!ptr)
|
||||
return 0; /* parameter not stored */
|
||||
|
||||
smp->data.uint = stktable_data_cast(ptr, bytes_in_cnt) >> 10;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Casts sample <smp> to the type of the table specified in arg(0), and looks
|
||||
* it up into this table. Returns the volume of data sent to clients in kbytes
|
||||
* if the key is present in the table, otherwise zero, so that comparisons can
|
||||
* be easily performed. If the inspected parameter is not stored in the table,
|
||||
* <not found> is returned.
|
||||
*/
|
||||
static int sample_conv_table_kbytes_out(const struct arg *arg_p, struct sample *smp)
|
||||
{
|
||||
struct stktable *t;
|
||||
struct stktable_key *key;
|
||||
struct stksess *ts;
|
||||
void *ptr;
|
||||
|
||||
t = &arg_p[0].data.prx->table;
|
||||
|
||||
key = smp_to_stkey(smp, t);
|
||||
if (!key)
|
||||
return 0;
|
||||
|
||||
smp->flags = SMP_F_VOL_TEST;
|
||||
smp->type = SMP_T_UINT;
|
||||
smp->data.uint = 0;
|
||||
|
||||
ts = stktable_lookup_key(t, key);
|
||||
if (!ts) /* key not present */
|
||||
return 1;
|
||||
|
||||
ptr = stktable_data_ptr(t, ts, STKTABLE_DT_BYTES_OUT_CNT);
|
||||
if (!ptr)
|
||||
return 0; /* parameter not stored */
|
||||
|
||||
smp->data.uint = stktable_data_cast(ptr, bytes_out_cnt) >> 10;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Casts sample <smp> to the type of the table specified in arg(0), and looks
|
||||
* it up into this table. Returns the server ID associated with the key if the
|
||||
* key is present in the table, otherwise zero, so that comparisons can be
|
||||
* easily performed. If the inspected parameter is not stored in the table,
|
||||
* <not found> is returned.
|
||||
*/
|
||||
static int sample_conv_table_server_id(const struct arg *arg_p, struct sample *smp)
|
||||
{
|
||||
struct stktable *t;
|
||||
struct stktable_key *key;
|
||||
struct stksess *ts;
|
||||
void *ptr;
|
||||
|
||||
t = &arg_p[0].data.prx->table;
|
||||
|
||||
key = smp_to_stkey(smp, t);
|
||||
if (!key)
|
||||
return 0;
|
||||
|
||||
smp->flags = SMP_F_VOL_TEST;
|
||||
smp->type = SMP_T_UINT;
|
||||
smp->data.uint = 0;
|
||||
|
||||
ts = stktable_lookup_key(t, key);
|
||||
if (!ts) /* key not present */
|
||||
return 1;
|
||||
|
||||
ptr = stktable_data_ptr(t, ts, STKTABLE_DT_SERVER_ID);
|
||||
if (!ptr)
|
||||
return 0; /* parameter not stored */
|
||||
|
||||
smp->data.uint = stktable_data_cast(ptr, server_id);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Casts sample <smp> to the type of the table specified in arg(0), and looks
|
||||
* it up into this table. Returns the cumulated number of sessions for the
|
||||
* key if the key is present in the table, otherwise zero, so that comparisons
|
||||
* can be easily performed. If the inspected parameter is not stored in the
|
||||
* table, <not found> is returned.
|
||||
*/
|
||||
static int sample_conv_table_sess_cnt(const struct arg *arg_p, struct sample *smp)
|
||||
{
|
||||
struct stktable *t;
|
||||
struct stktable_key *key;
|
||||
struct stksess *ts;
|
||||
void *ptr;
|
||||
|
||||
t = &arg_p[0].data.prx->table;
|
||||
|
||||
key = smp_to_stkey(smp, t);
|
||||
if (!key)
|
||||
return 0;
|
||||
|
||||
smp->flags = SMP_F_VOL_TEST;
|
||||
smp->type = SMP_T_UINT;
|
||||
smp->data.uint = 0;
|
||||
|
||||
ts = stktable_lookup_key(t, key);
|
||||
if (!ts) /* key not present */
|
||||
return 1;
|
||||
|
||||
ptr = stktable_data_ptr(t, ts, STKTABLE_DT_SESS_CNT);
|
||||
if (!ptr)
|
||||
return 0; /* parameter not stored */
|
||||
|
||||
smp->data.uint = stktable_data_cast(ptr, sess_cnt);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Casts sample <smp> to the type of the table specified in arg(0), and looks
|
||||
* it up into this table. Returns the session rate the key if the key is
|
||||
* present in the table, otherwise zero, so that comparisons can be easily
|
||||
* performed. If the inspected parameter is not stored in the table, <not found>
|
||||
* is returned.
|
||||
*/
|
||||
static int sample_conv_table_sess_rate(const struct arg *arg_p, struct sample *smp)
|
||||
{
|
||||
struct stktable *t;
|
||||
struct stktable_key *key;
|
||||
struct stksess *ts;
|
||||
void *ptr;
|
||||
|
||||
t = &arg_p[0].data.prx->table;
|
||||
|
||||
key = smp_to_stkey(smp, t);
|
||||
if (!key)
|
||||
return 0;
|
||||
|
||||
smp->flags = SMP_F_VOL_TEST;
|
||||
smp->type = SMP_T_UINT;
|
||||
smp->data.uint = 0;
|
||||
|
||||
ts = stktable_lookup_key(t, key);
|
||||
if (!ts) /* key not present */
|
||||
return 1;
|
||||
|
||||
ptr = stktable_data_ptr(t, ts, STKTABLE_DT_SESS_RATE);
|
||||
if (!ptr)
|
||||
return 0; /* parameter not stored */
|
||||
|
||||
smp->data.uint = read_freq_ctr_period(&stktable_data_cast(ptr, sess_rate),
|
||||
t->data_arg[STKTABLE_DT_SESS_RATE].u);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Casts sample <smp> to the type of the table specified in arg(0), and looks
|
||||
* it up into this table. Returns the amount of concurrent connections tracking
|
||||
* the same key if the key is present in the table, otherwise zero, so that
|
||||
* comparisons can be easily performed. If the inspected parameter is not
|
||||
* stored in the table, <not found> is returned.
|
||||
*/
|
||||
static int sample_conv_table_trackers(const struct arg *arg_p, struct sample *smp)
|
||||
{
|
||||
struct stktable *t;
|
||||
struct stktable_key *key;
|
||||
struct stksess *ts;
|
||||
|
||||
t = &arg_p[0].data.prx->table;
|
||||
|
||||
key = smp_to_stkey(smp, t);
|
||||
if (!key)
|
||||
return 0;
|
||||
|
||||
smp->flags = SMP_F_VOL_TEST;
|
||||
smp->type = SMP_T_UINT;
|
||||
smp->data.uint = 0;
|
||||
|
||||
ts = stktable_lookup_key(t, key);
|
||||
if (ts)
|
||||
smp->data.uint = ts->ref_cnt;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/* Note: must not be declared <const> as its list will be overwritten */
|
||||
static struct sample_conv_kw_list sample_conv_kws = {ILH, {
|
||||
{ "in_table", sample_conv_in_table, ARG1(1,TAB), NULL, SMP_T_STR, SMP_T_BOOL },
|
||||
{ "table_bytes_in_rate", sample_conv_table_bytes_in_rate, ARG1(1,TAB), NULL, SMP_T_STR, SMP_T_UINT },
|
||||
{ "table_bytes_out_rate", sample_conv_table_bytes_out_rate, ARG1(1,TAB), NULL, SMP_T_STR, SMP_T_UINT },
|
||||
{ "table_conn_cnt", sample_conv_table_conn_cnt, ARG1(1,TAB), NULL, SMP_T_STR, SMP_T_UINT },
|
||||
{ "table_conn_cur", sample_conv_table_conn_cur, ARG1(1,TAB), NULL, SMP_T_STR, SMP_T_UINT },
|
||||
{ "table_conn_rate", sample_conv_table_conn_rate, ARG1(1,TAB), NULL, SMP_T_STR, SMP_T_UINT },
|
||||
{ "table_gpc0", sample_conv_table_gpc0, ARG1(1,TAB), NULL, SMP_T_STR, SMP_T_UINT },
|
||||
{ "table_gpc0_rate", sample_conv_table_gpc0_rate, ARG1(1,TAB), NULL, SMP_T_STR, SMP_T_UINT },
|
||||
{ "table_http_err_cnt", sample_conv_table_http_err_cnt, ARG1(1,TAB), NULL, SMP_T_STR, SMP_T_UINT },
|
||||
{ "table_http_err_rate", sample_conv_table_http_err_rate, ARG1(1,TAB), NULL, SMP_T_STR, SMP_T_UINT },
|
||||
{ "table_http_req_cnt", sample_conv_table_http_req_cnt, ARG1(1,TAB), NULL, SMP_T_STR, SMP_T_UINT },
|
||||
{ "table_http_req_rate", sample_conv_table_http_req_rate, ARG1(1,TAB), NULL, SMP_T_STR, SMP_T_UINT },
|
||||
{ "table_kbytes_in", sample_conv_table_kbytes_in, ARG1(1,TAB), NULL, SMP_T_STR, SMP_T_UINT },
|
||||
{ "table_kbytes_out", sample_conv_table_kbytes_out, ARG1(1,TAB), NULL, SMP_T_STR, SMP_T_UINT },
|
||||
{ "table_server_id", sample_conv_table_server_id, ARG1(1,TAB), NULL, SMP_T_STR, SMP_T_UINT },
|
||||
{ "table_sess_cnt", sample_conv_table_sess_cnt, ARG1(1,TAB), NULL, SMP_T_STR, SMP_T_UINT },
|
||||
{ "table_sess_rate", sample_conv_table_sess_rate, ARG1(1,TAB), NULL, SMP_T_STR, SMP_T_UINT },
|
||||
{ "table_trackers", sample_conv_table_trackers, ARG1(1,TAB), NULL, SMP_T_STR, SMP_T_UINT },
|
||||
{ /* END */ },
|
||||
}};
|
||||
|
||||
__attribute__((constructor))
|
||||
static void __stick_table_init(void)
|
||||
{
|
||||
/* register sample fetch and format conversion keywords */
|
||||
sample_register_convs(&sample_conv_kws);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user