[MINOR] Allow listing of stick table by key

This commit is contained in:
Simon Horman 2011-06-15 15:18:47 +09:00 committed by Willy Tarreau
parent 121f305f3b
commit 17bce34a20
2 changed files with 45 additions and 13 deletions

View File

@ -9519,15 +9519,18 @@ show table
>>> # table: front_pub, type: 0, size:204800, used:171454 >>> # table: front_pub, type: 0, size:204800, used:171454
>>> # table: back_rdp, type: 0, size:204800, used:0 >>> # table: back_rdp, type: 0, size:204800, used:0
show table <name> [ data.<type> <operator> <value> ] show table <name> [ data.<type> <operator> <value> ] | [ key <key> ]
Dump contents of stick-table <name>. In this mode, a first line of generic Dump contents of stick-table <name>. In this mode, a first line of generic
information about the table is reported as with "show table", then all information about the table is reported as with "show table", then all
entries are dumped. Since this can be quite heavy, it is possible to specify entries are dumped. Since this can be quite heavy, it is possible to specify
a filter in order to specify what entries to display. The filter then applies a filter in order to specify what entries to display.
to the stored data (see "stick-table" in section 4.2). One stored data type
has to be specified in <type>, and this data type must be stored in the table When the "data." form is used the filter applies to the stored data (see
otherwise an error is reported. The data is compared according to <operator> "stick-table" in section 4.2). A stored data type must be specified
with the 64-bit integer <value>. Operators are the same as with the ACLs : in <type>, and this data type must be stored in the table otherwise an
error is reported. The data is compared according to <operator> with the
64-bit integer <value>. Operators are the same as with the ACLs :
- eq : match entries whose data is equal to this value - eq : match entries whose data is equal to this value
- ne : match entries whose data is not equal to this value - ne : match entries whose data is not equal to this value
- le : match entries whose data is less than or equal to this value - le : match entries whose data is less than or equal to this value
@ -9535,6 +9538,11 @@ show table <name> [ data.<type> <operator> <value> ]
- lt : match entries whose data is less than this value - lt : match entries whose data is less than this value
- gt : match entries whose data is greater than this value - gt : match entries whose data is greater than this value
When the key form is used the filter applies to the key of
the stick table entry (see "stick-table" in section 4.2).
The stick table must be of type ip otherwise an error will
be reported.
Example : Example :
$ echo "show table http_proxy" | socat stdio /tmp/sock1 $ echo "show table http_proxy" | socat stdio /tmp/sock1
>>> # table: http_proxy, type: 0, size:204800, used:2 >>> # table: http_proxy, type: 0, size:204800, used:2
@ -9551,6 +9559,12 @@ show table <name> [ data.<type> <operator> <value> ]
$ echo "show table http_proxy data.conn_rate gt 5" | \ $ echo "show table http_proxy data.conn_rate gt 5" | \
socat stdio /tmp/sock1 socat stdio /tmp/sock1
>>> # table: http_proxy, type: 0, size:204800, used:2 >>> # table: http_proxy, type: 0, size:204800, used:2
>>> 0x80e6a80: key=127.0.0.2 use=0 exp=3594740 gpc0=1 conn_rate(30000)=10 \
bytes_out_rate(60000)=191
$ echo "show table http_proxy key 127.0.0.2" | \
socat stdio /tmp/sock1
>>> # table: http_proxy, type: 0, size:204800, used:2
>>> 0x80e6a80: key=127.0.0.2 use=0 exp=3594740 gpc0=1 conn_rate(30000)=10 \ >>> 0x80e6a80: key=127.0.0.2 use=0 exp=3594740 gpc0=1 conn_rate(30000)=10 \
bytes_out_rate(60000)=191 bytes_out_rate(60000)=191

View File

@ -14,6 +14,7 @@
#include <ctype.h> #include <ctype.h>
#include <errno.h> #include <errno.h>
#include <fcntl.h> #include <fcntl.h>
#include <stdbool.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -504,7 +505,7 @@ static int stats_dump_table_entry_to_buffer(struct chunk *msg, struct stream_int
return 1; return 1;
} }
static void stats_sock_table_key_request(struct stream_interface *si, char **args) static void stats_sock_table_key_request(struct stream_interface *si, char **args, bool show)
{ {
struct session *s = si->applet.private; struct session *s = si->applet.private;
struct proxy *px; struct proxy *px;
@ -542,7 +543,10 @@ static void stats_sock_table_key_request(struct stream_interface *si, char **arg
static_table_key.key = (void *)&ip_key; static_table_key.key = (void *)&ip_key;
} }
else { else {
si->applet.ctx.cli.msg = "Removing keys from non-ip tables is not supported\n"; if (show)
si->applet.ctx.cli.msg = "Showing keys from non-ip tables is not supported\n";
else
si->applet.ctx.cli.msg = "Removing keys from non-ip tables is not supported\n";
si->applet.st0 = STAT_CLI_PRINT; si->applet.st0 = STAT_CLI_PRINT;
return; return;
} }
@ -555,11 +559,19 @@ static void stats_sock_table_key_request(struct stream_interface *si, char **arg
} }
ts = stktable_lookup_key(&px->table, &static_table_key); ts = stktable_lookup_key(&px->table, &static_table_key);
if (!ts) { if (!ts)
/* silent return, entry was already removed */ return;
if (show) {
struct chunk msg;
chunk_init(&msg, trash, sizeof(trash));
if (!stats_dump_table_head_to_buffer(&msg, si, px, px))
return;
stats_dump_table_entry_to_buffer(&msg, si, px, ts);
return; return;
} }
else if (ts->ref_cnt) {
if (ts->ref_cnt) {
/* don't delete an entry which is currently referenced */ /* don't delete an entry which is currently referenced */
si->applet.ctx.cli.msg = "Entry currently in use, cannot remove\n"; si->applet.ctx.cli.msg = "Entry currently in use, cannot remove\n";
si->applet.st0 = STAT_CLI_PRINT; si->applet.st0 = STAT_CLI_PRINT;
@ -655,6 +667,12 @@ static int stats_sock_parse_request(struct stream_interface *si, char *line)
si->applet.st0 = STAT_CLI_O_ERR; // stats_dump_errors_to_buffer si->applet.st0 = STAT_CLI_O_ERR; // stats_dump_errors_to_buffer
} }
else if (strcmp(args[1], "table") == 0) { else if (strcmp(args[1], "table") == 0) {
if (*args[2] && *args[3] && strcmp(args[3], "key") == 0) {
stats_sock_table_key_request(si, args, true);
/* end of processing */
return 1;
}
si->applet.state = STAT_ST_INIT; si->applet.state = STAT_ST_INIT;
if (*args[2]) { if (*args[2]) {
si->applet.ctx.table.target = find_stktable(args[2]); si->applet.ctx.table.target = find_stktable(args[2]);
@ -697,7 +715,7 @@ static int stats_sock_parse_request(struct stream_interface *si, char *line)
} }
} }
else if (*args[3]) { else if (*args[3]) {
si->applet.ctx.cli.msg = "Optional argument only supports \"data.<store_data_type>\" <operator> <value>\n"; si->applet.ctx.cli.msg = "Optional argument only supports \"data.<store_data_type>\" <operator> <value> and key <key>\n";
si->applet.st0 = STAT_CLI_PRINT; si->applet.st0 = STAT_CLI_PRINT;
return 1; return 1;
} }
@ -768,7 +786,7 @@ static int stats_sock_parse_request(struct stream_interface *si, char *line)
return 1; return 1;
} }
else if (strcmp(args[1], "table") == 0) { else if (strcmp(args[1], "table") == 0) {
stats_sock_table_key_request(si, args); stats_sock_table_key_request(si, args, false);
/* end of processing */ /* end of processing */
return 1; return 1;
} }