Skip to content

Commit

Permalink
new feature: "info" command now prints statistics (--statistics optio…
Browse files Browse the repository at this point in the history
…n) also for exchanges
  • Loading branch information
jandelgado committed Apr 7, 2018
1 parent 500d8b4 commit 1290dec
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 22 deletions.
9 changes: 6 additions & 3 deletions cmd/main/broker_info_printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func (s BrokerInfoPrinter) renderQueueElementAsString(queue rabtap.RabbitQueue,
{{- .Queue.MessagesReady }}, {{printf "%.1f" .Queue.MessagesReadyDetails.Rate}}/s) msg ready,
{{- end }}
{{- if .Queue.IdleSince}}{{- " idle since "}}{{ .Queue.IdleSince}}{{else}}{{ " running" }}{{end}}
{{- " "}}{{ .QueueFlags}})`
{{- ""}}, {{ .QueueFlags}})`

return s.resolveTemplate("queue-tpl", tpl, args)
}
Expand Down Expand Up @@ -171,8 +171,11 @@ func (s BrokerInfoPrinter) renderExchangeElementAsString(exchange rabtap.RabbitE
exchangeFlags := s.renderExchangeFlagsAsString(exchange)
args := ExchangeInfo{s.config, exchange, exchangeFlags, printName}

const tpl = `{{ ExchangeColor .PrintName }} (exchange, type '
{{- .Exchange.Type }}' {{ .ExchangeFlags }})`
const tpl = `{{ ExchangeColor .PrintName }} (exchange, type '{{ .Exchange.Type }}'
{{- if and .Config.ShowStats .Exchange.MessageStats }}, in=(
{{- .Exchange.MessageStats.PublishIn }}, {{printf "%.1f" .Exchange.MessageStats.PublishInDetails.Rate}}/s) msg, out=(
{{- .Exchange.MessageStats.PublishOut }}, {{printf "%.1f" .Exchange.MessageStats.PublishOutDetails.Rate}}/s) msg
{{- end }}, {{ .ExchangeFlags }})`

return s.resolveTemplate("exchange-tpl", tpl, args)
}
Expand Down
38 changes: 19 additions & 19 deletions cmd/main/broker_info_printer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,26 +100,26 @@ func ExampleBrokerInfoPrinter_Print() {
// Output:
// http://rabbitmq/api (broker ver=3.6.9, mgmt ver=3.6.9, cluster=rabbit@08f57d1fe8ab)
// └── Vhost /
// ├── amq.direct (exchange, type 'direct' [D])
// ├── amq.fanout (exchange, type 'fanout' [D])
// ├── amq.headers (exchange, type 'headers' [D])
// ├── amq.match (exchange, type 'headers' [D])
// ├── amq.rabbitmq.log (exchange, type 'topic' [D|I])
// ├── amq.rabbitmq.trace (exchange, type 'topic' [D|I])
// ├── amq.topic (exchange, type 'topic' [D])
// ├── test-direct (exchange, type 'direct' [D|AD|I])
// │ ├── direct-q1 (queue, key=direct-q1, running [D])
// ├── amq.direct (exchange, type 'direct', [D])
// ├── amq.fanout (exchange, type 'fanout', [D])
// ├── amq.headers (exchange, type 'headers', [D])
// ├── amq.match (exchange, type 'headers', [D])
// ├── amq.rabbitmq.log (exchange, type 'topic', [D|I])
// ├── amq.rabbitmq.trace (exchange, type 'topic', [D|I])
// ├── amq.topic (exchange, type 'topic', [D])
// ├── test-direct (exchange, type 'direct', [D|AD|I])
// │ ├── direct-q1 (queue, key=direct-q1, running, [D])
// │ │ ├── some_consumer (consumer, 172.17.0.1:58938 -> 172.17.0.2:5672 (2))
// │ │ └── another_consumer w/ faulty channel (consumer, )
// │ └── direct-q2 (queue, key=direct-q2, running [D])
// ├── test-fanout (exchange, type 'fanout' [D])
// │ ├── fanout-q1 (queue, idle since 2017-05-25 19:14:32 [D])
// │ └── fanout-q2 (queue, idle since 2017-05-25 19:14:32 [D])
// ├── test-headers (exchange, type 'headers' [D|AD])
// │ ├── header-q1 (queue, key=headers-q1, idle since 2017-05-25 19:14:53 [D])
// │ └── header-q2 (queue, key=headers-q2, idle since 2017-05-25 19:14:47 [D])
// └── test-topic (exchange, type 'topic' [D])
// ├── topic-q1 (queue, key=topic-q1, idle since 2017-05-25 19:14:17 [D|AD|EX])
// └── topic-q2 (queue, key=topic-q2, idle since 2017-05-25 19:14:21 [D])
// │ └── direct-q2 (queue, key=direct-q2, running, [D])
// ├── test-fanout (exchange, type 'fanout', [D])
// │ ├── fanout-q1 (queue, idle since 2017-05-25 19:14:32, [D])
// │ └── fanout-q2 (queue, idle since 2017-05-25 19:14:32, [D])
// ├── test-headers (exchange, type 'headers', [D|AD])
// │ ├── header-q1 (queue, key=headers-q1, idle since 2017-05-25 19:14:53, [D])
// │ └── header-q2 (queue, key=headers-q2, idle since 2017-05-25 19:14:47, [D])
// └── test-topic (exchange, type 'topic', [D])
// ├── topic-q1 (queue, key=topic-q1, idle since 2017-05-25 19:14:17, [D|AD|EX])
// └── topic-q2 (queue, key=topic-q2, idle since 2017-05-25 19:14:21, [D])

}
10 changes: 10 additions & 0 deletions pkg/rabbitmq_rest_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,16 @@ type RabbitExchange struct {
Arguments map[string]interface{} `json:"arguments,omitempty"`
//Arguments struct {
//} `json:"arguments"`
MessageStats struct {
PublishOut int `json:"publish_out"`
PublishOutDetails struct {
Rate float64 `json:"rate"`
} `json:"publish_out_details"`
PublishIn int `json:"publish_in"`
PublishInDetails struct {
Rate float64 `json:"rate"`
} `json:"publish_in_details"`
} `json:"message_stats,omitempty"`
}

// ChannelDetails model channel_details in RabbitConsumer
Expand Down

0 comments on commit 1290dec

Please sign in to comment.