bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2017-2018 Dovecot authors, see the included COPYING file */
e9068f1c3326de0265d0ef542a0d7723f5f01bc8Timo Sirainenstatic struct connection_list *reader_clients = NULL;
e9068f1c3326de0265d0ef542a0d7723f5f01bc8Timo Sirainenvoid client_reader_create(int fd, struct stats_metrics *metrics)
e9068f1c3326de0265d0ef542a0d7723f5f01bc8Timo Sirainen connection_init_server(reader_clients, &client->conn,
e9068f1c3326de0265d0ef542a0d7723f5f01bc8Timo Sirainenstatic void reader_client_destroy(struct connection *conn)
e9068f1c3326de0265d0ef542a0d7723f5f01bc8Timo Sirainen master_service_client_connection_destroyed(master_service);
5f08b0309190ec818d46bfe0e497468b30714a93Timo Sirainenstatic void reader_client_dump_stats(string_t *str, struct stats_dist *stats,
5f08b0309190ec818d46bfe0e497468b30714a93Timo Sirainen const char *const *fields)
e9068f1c3326de0265d0ef542a0d7723f5f01bc8Timo Sirainen for (unsigned int i = 0; fields[i] != NULL; i++) {
5f08b0309190ec818d46bfe0e497468b30714a93Timo Sirainen str_printfa(str, "%u", stats_dist_get_count(stats));
5f08b0309190ec818d46bfe0e497468b30714a93Timo Sirainen str_printfa(str, "%"PRIu64, stats_dist_get_sum(stats));
5f08b0309190ec818d46bfe0e497468b30714a93Timo Sirainen str_printfa(str, "%"PRIu64, stats_dist_get_min(stats));
5f08b0309190ec818d46bfe0e497468b30714a93Timo Sirainen str_printfa(str, "%"PRIu64, stats_dist_get_max(stats));
5f08b0309190ec818d46bfe0e497468b30714a93Timo Sirainen str_printfa(str, "%"PRIu64, stats_dist_get_avg(stats));
5f08b0309190ec818d46bfe0e497468b30714a93Timo Sirainen str_printfa(str, "%"PRIu64, stats_dist_get_median(stats));
5f08b0309190ec818d46bfe0e497468b30714a93Timo Sirainen str_printfa(str, "%"PRIu64, stats_dist_get_95th(stats));
e9068f1c3326de0265d0ef542a0d7723f5f01bc8Timo Sirainen /* return unknown fields as empty */
e9068f1c3326de0265d0ef542a0d7723f5f01bc8Timo Sirainenreader_client_input_dump(struct reader_client *client, const char *const *args)
e9068f1c3326de0265d0ef542a0d7723f5f01bc8Timo Sirainen iter = stats_metrics_iterate_init(client->metrics);
e9068f1c3326de0265d0ef542a0d7723f5f01bc8Timo Sirainen while ((metric = stats_metrics_iterate(iter)) != NULL) {
5f08b0309190ec818d46bfe0e497468b30714a93Timo Sirainen reader_client_dump_stats(str, metric->duration_stats, args);
e9068f1c3326de0265d0ef542a0d7723f5f01bc8Timo Sirainen for (unsigned int i = 0; i < metric->fields_count; i++) {
e9068f1c3326de0265d0ef542a0d7723f5f01bc8Timo Sirainen str_append_tabescaped(str, metric->fields[i].field_key);
5f08b0309190ec818d46bfe0e497468b30714a93Timo Sirainen reader_client_dump_stats(str, metric->fields[i].stats, args);
e9068f1c3326de0265d0ef542a0d7723f5f01bc8Timo Sirainen o_stream_nsend(client->conn.output, str_data(str), str_len(str));
9c675f5e259c19f9fdc40808439479131b32421eTimo Sirainenreader_client_input_dump_reset(struct reader_client *client,
9c675f5e259c19f9fdc40808439479131b32421eTimo Sirainen const char *const *args)
e9068f1c3326de0265d0ef542a0d7723f5f01bc8Timo Sirainenreader_client_input_args(struct connection *conn, const char *const *args)
e9068f1c3326de0265d0ef542a0d7723f5f01bc8Timo Sirainen struct reader_client *client = (struct reader_client *)conn;
e9068f1c3326de0265d0ef542a0d7723f5f01bc8Timo Sirainen return reader_client_input_dump(client, args);
9c675f5e259c19f9fdc40808439479131b32421eTimo Sirainen return reader_client_input_dump_reset(client, args);
e9068f1c3326de0265d0ef542a0d7723f5f01bc8Timo Sirainenstatic struct connection_settings client_set = {
e9068f1c3326de0265d0ef542a0d7723f5f01bc8Timo Sirainenstatic const struct connection_vfuncs client_vfuncs = {