client-reader.c revision 9c675f5e259c19f9fdc40808439479131b32421e
b355dcb54194f498921743ca33304eac35d89718Stephen Gallagher/* Copyright (c) 2017 Dovecot authors, see the included COPYING file */
c938f4ba417328fe62eded0806b2d9ca053f34a5Stephen Gallagherstatic struct connection_list *reader_clients = NULL;
bde69429374859acff41273c0771d2b5f5c199b1Yuri Chornoivanvoid client_reader_create(int fd, struct stats_metrics *metrics)
cbe7c54c2caf718bdea7ca6660ba8193d759d2d5Stephen Gallagher connection_init_server(reader_clients, &client->conn,
65a9065538fd85e6ead925d344e6b421900eb8c2Jakub Hrozekstatic void reader_client_destroy(struct connection *conn)
bde69429374859acff41273c0771d2b5f5c199b1Yuri Chornoivan master_service_client_connection_destroyed(master_service);
bde69429374859acff41273c0771d2b5f5c199b1Yuri Chornoivanstatic void reader_client_dump_timing(string_t *str, struct timing *timing,
bde69429374859acff41273c0771d2b5f5c199b1Yuri Chornoivan const char *const *fields)
bde69429374859acff41273c0771d2b5f5c199b1Yuri Chornoivan for (unsigned int i = 0; fields[i] != NULL; i++) {
2ea6196484055397cc4bc011c5960f790431fa9dStephen Gallagher str_printfa(str, "%u", timing_get_count(timing));
bde69429374859acff41273c0771d2b5f5c199b1Yuri Chornoivan str_printfa(str, "%"PRIu64, timing_get_sum(timing));
bde69429374859acff41273c0771d2b5f5c199b1Yuri Chornoivan str_printfa(str, "%"PRIu64, timing_get_min(timing));
bde69429374859acff41273c0771d2b5f5c199b1Yuri Chornoivan str_printfa(str, "%"PRIu64, timing_get_max(timing));
bde69429374859acff41273c0771d2b5f5c199b1Yuri Chornoivan str_printfa(str, "%"PRIu64, timing_get_avg(timing));
cbe7c54c2caf718bdea7ca6660ba8193d759d2d5Stephen Gallagher str_printfa(str, "%"PRIu64, timing_get_median(timing));
bde69429374859acff41273c0771d2b5f5c199b1Yuri Chornoivan str_printfa(str, "%"PRIu64, timing_get_95th(timing));
cbe7c54c2caf718bdea7ca6660ba8193d759d2d5Stephen Gallagher /* return unknown fields as empty */
bde69429374859acff41273c0771d2b5f5c199b1Yuri Chornoivanreader_client_input_dump(struct reader_client *client, const char *const *args)
65a9065538fd85e6ead925d344e6b421900eb8c2Jakub Hrozek iter = stats_metrics_iterate_init(client->metrics);
a23014d69b56cbdf48ad05229c334648b5309d8fJakub Hrozek while ((metric = stats_metrics_iterate(iter)) != NULL) {
bde69429374859acff41273c0771d2b5f5c199b1Yuri Chornoivan reader_client_dump_timing(str, metric->duration_timing, args);
bde69429374859acff41273c0771d2b5f5c199b1Yuri Chornoivan for (unsigned int i = 0; i < metric->fields_count; i++) {
bde69429374859acff41273c0771d2b5f5c199b1Yuri Chornoivan str_append_tabescaped(str, metric->fields[i].field_key);
bde69429374859acff41273c0771d2b5f5c199b1Yuri Chornoivan reader_client_dump_timing(str, metric->fields[i].timing, args);
bde69429374859acff41273c0771d2b5f5c199b1Yuri Chornoivan o_stream_nsend(client->conn.output, str_data(str), str_len(str));
f9fdc87c80f2744780c6a0f2bf5b1b57bcbb095aYuri Chornoivan o_stream_nsend(client->conn.output, "\n", 1);
ea929f1b022fc2cb77dec89b0e12accef983ec85Jakub Hrozekreader_client_input_dump_reset(struct reader_client *client,
bde69429374859acff41273c0771d2b5f5c199b1Yuri Chornoivan const char *const *args)
bde69429374859acff41273c0771d2b5f5c199b1Yuri Chornoivan (void)reader_client_input_dump(client, args);
bde69429374859acff41273c0771d2b5f5c199b1Yuri Chornoivanreader_client_input_args(struct connection *conn, const char *const *args)
c938f4ba417328fe62eded0806b2d9ca053f34a5Stephen Gallagher struct reader_client *client = (struct reader_client *)conn;
c938f4ba417328fe62eded0806b2d9ca053f34a5Stephen Gallagher return reader_client_input_dump(client, args);
f9fdc87c80f2744780c6a0f2bf5b1b57bcbb095aYuri Chornoivan return reader_client_input_dump_reset(client, args);
bde69429374859acff41273c0771d2b5f5c199b1Yuri Chornoivanstatic struct connection_settings client_set = {
cbe7c54c2caf718bdea7ca6660ba8193d759d2d5Stephen Gallagher .service_name_out = "stats-reader-server",
cbe7c54c2caf718bdea7ca6660ba8193d759d2d5Stephen Gallagherstatic const struct connection_vfuncs client_vfuncs = {