client-reader.c (dovecot-2.3.16) | : | client-reader.c (dovecot-2.3.17) | ||
---|---|---|---|---|
skipping to change at line 12 | skipping to change at line 12 | |||
#include "stats-common.h" | #include "stats-common.h" | |||
#include "array.h" | #include "array.h" | |||
#include "str.h" | #include "str.h" | |||
#include "stats-dist.h" | #include "stats-dist.h" | |||
#include "strescape.h" | #include "strescape.h" | |||
#include "connection.h" | #include "connection.h" | |||
#include "ostream.h" | #include "ostream.h" | |||
#include "master-service.h" | #include "master-service.h" | |||
#include "stats-metrics.h" | #include "stats-metrics.h" | |||
#include "stats-settings.h" | ||||
#include "client-reader.h" | #include "client-reader.h" | |||
#include "client-writer.h" | ||||
struct reader_client { | struct reader_client { | |||
struct connection conn; | struct connection conn; | |||
}; | }; | |||
static struct connection_list *reader_clients = NULL; | static struct connection_list *reader_clients = NULL; | |||
void client_reader_create(int fd) | void client_reader_create(int fd) | |||
{ | { | |||
struct reader_client *client; | struct reader_client *client; | |||
skipping to change at line 153 | skipping to change at line 155 | |||
static int | static int | |||
reader_client_input_dump_reset(struct reader_client *client, | reader_client_input_dump_reset(struct reader_client *client, | |||
const char *const *args) | const char *const *args) | |||
{ | { | |||
(void)reader_client_input_dump(client, args); | (void)reader_client_input_dump(client, args); | |||
stats_metrics_reset(stats_metrics); | stats_metrics_reset(stats_metrics); | |||
return 1; | return 1; | |||
} | } | |||
static int | static int | |||
reader_client_input_metrics_add(struct reader_client *client, | ||||
const char *const *args) | ||||
{ | ||||
const char *error; | ||||
if (str_array_length(args) < 7) { | ||||
e_error(client->conn.event, "METRICS-ADD: Not enough parameters") | ||||
; | ||||
return -1; | ||||
} | ||||
struct stats_metric_settings set = { | ||||
.metric_name = args[0], | ||||
.description = args[1], | ||||
.fields = args[2], | ||||
.group_by = args[3], | ||||
.filter = args[4], | ||||
.exporter = args[5], | ||||
.exporter_include = args[6], | ||||
}; | ||||
o_stream_cork(client->conn.output); | ||||
if (stats_metrics_add_dynamic(stats_metrics, &set, &error)) { | ||||
client_writer_update_connections(); | ||||
o_stream_nsend(client->conn.output, "+", 1); | ||||
} else { | ||||
o_stream_nsend(client->conn.output, "-", 1); | ||||
o_stream_nsend_str(client->conn.output, "METRICS-ADD: "); | ||||
o_stream_nsend_str(client->conn.output, error); | ||||
} | ||||
o_stream_nsend(client->conn.output, "\n", 1); | ||||
o_stream_uncork(client->conn.output); | ||||
return 1; | ||||
} | ||||
static int | ||||
reader_client_input_metrics_remove(struct reader_client *client, | ||||
const char *const *args) | ||||
{ | ||||
if (str_array_length(args) < 1) { | ||||
e_error(client->conn.event, "METRICS-REMOVE: Not enough parameter | ||||
s"); | ||||
return -1; | ||||
} | ||||
if (stats_metrics_remove_dynamic(stats_metrics, args[0])) { | ||||
client_writer_update_connections(); | ||||
o_stream_nsend(client->conn.output, "+\n", 2); | ||||
} else { | ||||
o_stream_nsend_str(client->conn.output, | ||||
t_strdup_printf("-metrics '%s' not found\n", a | ||||
rgs[0])); | ||||
} | ||||
return 1; | ||||
} | ||||
static int | ||||
reader_client_input_args(struct connection *conn, const char *const *args) | reader_client_input_args(struct connection *conn, const char *const *args) | |||
{ | { | |||
struct reader_client *client = (struct reader_client *)conn; | struct reader_client *client = (struct reader_client *)conn; | |||
const char *cmd = args[0]; | const char *cmd = args[0]; | |||
if (cmd == NULL) { | if (cmd == NULL) { | |||
i_error("Client sent empty line"); | i_error("Client sent empty line"); | |||
return 1; | return 1; | |||
} | } | |||
args++; | args++; | |||
if (strcmp(cmd, "DUMP") == 0) | if (strcmp(cmd, "DUMP") == 0) | |||
return reader_client_input_dump(client, args); | return reader_client_input_dump(client, args); | |||
else if (strcmp(cmd, "METRICS-ADD") == 0) | ||||
return reader_client_input_metrics_add(client, args); | ||||
else if (strcmp(cmd, "METRICS-REMOVE") == 0) | ||||
return reader_client_input_metrics_remove(client, args); | ||||
else if (strcmp(cmd, "DUMP-RESET") == 0) | else if (strcmp(cmd, "DUMP-RESET") == 0) | |||
return reader_client_input_dump_reset(client, args); | return reader_client_input_dump_reset(client, args); | |||
return 1; | return 1; | |||
} | } | |||
static struct connection_settings client_set = { | static struct connection_settings client_set = { | |||
.service_name_in = "stats-reader-client", | .service_name_in = "stats-reader-client", | |||
.service_name_out = "stats-reader-server", | .service_name_out = "stats-reader-server", | |||
.major_version = 2, | .major_version = 2, | |||
.minor_version = 0, | .minor_version = 0, | |||
End of changes. 4 change blocks. | ||||
0 lines changed or deleted | 62 lines changed or added |