bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2017-2018 Dovecot authors, see the included COPYING file */
285f3c4cf828ebe9ff345080aa1df3755613af29Timo Sirainenstatic void dump_timing(const char *const **args, unsigned int fields_count)
285f3c4cf828ebe9ff345080aa1df3755613af29Timo Sirainen unsigned int i, args_count = str_array_length(*args);
285f3c4cf828ebe9ff345080aa1df3755613af29Timo Sirainen for (i = 0; i < args_count; i++)
f46a703b2916bdda27e701f2f8305c0ce3d1e893Timo Sirainenstatic void stats_dump(const char *path, const char *const *fields, bool reset)
285f3c4cf828ebe9ff345080aa1df3755613af29Timo Sirainen unsigned int i, fields_count = str_array_length(fields);
f46a703b2916bdda27e701f2f8305c0ce3d1e893Timo Sirainen str_append(cmd, "VERSION\tstats-reader-client\t2\t0\n");
f46a703b2916bdda27e701f2f8305c0ce3d1e893Timo Sirainen str_append(cmd, reset ? "DUMP-RESET" : "DUMP");
285f3c4cf828ebe9ff345080aa1df3755613af29Timo Sirainen for (i = 0; i < fields_count; i++) {
285f3c4cf828ebe9ff345080aa1df3755613af29Timo Sirainen if (write_full(fd, str_data(cmd), str_len(cmd)) < 0)
285f3c4cf828ebe9ff345080aa1df3755613af29Timo Sirainen input = i_stream_create_fd_autoclose(&fd, (size_t)-1);
285f3c4cf828ebe9ff345080aa1df3755613af29Timo Sirainen if ((line = i_stream_read_next_line(input)) == NULL)
285f3c4cf828ebe9ff345080aa1df3755613af29Timo Sirainen i_fatal("%s: Failed to read VERSION line", path);
285f3c4cf828ebe9ff345080aa1df3755613af29Timo Sirainen else if (!version_string_verify(line, "stats-reader-server", 2)) {
285f3c4cf828ebe9ff345080aa1df3755613af29Timo Sirainen "%s is not a compatible stats-reader socket", path);
285f3c4cf828ebe9ff345080aa1df3755613af29Timo Sirainen for (i = 0; i < fields_count; i++)
285f3c4cf828ebe9ff345080aa1df3755613af29Timo Sirainen while ((line = i_stream_read_next_line(input)) != NULL) {
285f3c4cf828ebe9ff345080aa1df3755613af29Timo Sirainen i_fatal("read(%s) failed: %s", path, i_stream_get_error(input));
285f3c4cf828ebe9ff345080aa1df3755613af29Timo Sirainendoveadm_cmd_stats_dump(struct doveadm_cmd_context *cctx)
285f3c4cf828ebe9ff345080aa1df3755613af29Timo Sirainen if (!doveadm_cmd_param_str(cctx, "socket-path", &path))
285f3c4cf828ebe9ff345080aa1df3755613af29Timo Sirainen path = t_strconcat(doveadm_settings->base_dir, "/stats-reader", NULL);
f46a703b2916bdda27e701f2f8305c0ce3d1e893Timo Sirainen if (!doveadm_cmd_param_bool(cctx, "reset", &reset))
285f3c4cf828ebe9ff345080aa1df3755613af29Timo Sirainen "count", "sum", "min", "max", "avg", "median", "%95", NULL
285f3c4cf828ebe9ff345080aa1df3755613af29Timo Sirainenstruct doveadm_cmd_ver2 doveadm_cmd_stats_dump_ver2 = {
285f3c4cf828ebe9ff345080aa1df3755613af29Timo SirainenDOVEADM_CMD_PARAM('s', "socket-path", CMD_PARAM_STR, 0)