Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/static/spec/openapi/logstash-api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -821,10 +821,16 @@ paths:
current: 78
average:
lifetime: 115
1_minute: 120
5_minutes: 110
15_minutes: 112
byte_size:
current: 32767
average:
lifetime: 14820
1_minute: 15234
5_minutes: 14012
15_minutes: 14567
events:
duration_in_millis: 365495
in: 216610
Expand Down
35 changes: 31 additions & 4 deletions logstash-core/lib/logstash/api/commands/stats.rb
Original file line number Diff line number Diff line change
Expand Up @@ -176,25 +176,52 @@ def refine_batch_metrics(stats)
# current is a tuple of [event_count, byte_size] store the reference locally to avoid repeatedly
# reading and retrieve unrelated values
current_data_point = stats[:batch][:current]
{
# average return a FlowMetric which and we need to invoke getValue to obtain the map with metric details.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having a hard time parsing this comment, not sure exactly what the message is supposed to convey.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's more a reminder for the reader why for this metric we need to invoke the getValue method.
The reason why resides in the fact that the flow metric nested in batch/[event_count | byte_szie]/average, to return the sub-document which contains the lifetime, last_1_minute etc metric values needs to be explicitly queried to return the map with those values:

Usually the paths drive to single value metric objects, but this a composite that needs explicit query to grab the contained values.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@donoghuc let me know if you want me to reword the sentence so that could sound more meaningful (a good suggestion from a native speaker is very welcome :-) )

event_count_average_flow_metric = stats[:batch][:event_count][:average].value
event_count_average_lifetime = event_count_average_flow_metric["lifetime"] ? event_count_average_flow_metric["lifetime"].round : 0
byte_size_average_flow_metric = stats[:batch][:byte_size][:average].value
byte_size_average_lifetime = byte_size_average_flow_metric["lifetime"] ? byte_size_average_flow_metric["lifetime"].round : 0
result = {
:event_count => {
# current_data_point is an instance of org.logstash.instrument.metrics.gauge.LazyDelegatingGauge so need to invoke getValue() to obtain the actual value
:current => current_data_point.value[0],
:average => {
# average return a FlowMetric which and we need to invoke getValue to obtain the map with metric details.
:lifetime => stats[:batch][:event_count][:average].value["lifetime"] ? stats[:batch][:event_count][:average].value["lifetime"].round : 0
:lifetime => event_count_average_lifetime
}
},
:byte_size => {
:current => current_data_point.value[1],
:average => {
:lifetime => stats[:batch][:byte_size][:average].value["lifetime"] ? stats[:batch][:byte_size][:average].value["lifetime"].round : 0
:lifetime => byte_size_average_lifetime
}
}
}
# Enrich byte_size and event_count averages with the last 1, 5, 15 minutes averages if available
publish_average_count_flow_metric(event_count_average_flow_metric, result, :last_1_minute)
publish_average_count_flow_metric(event_count_average_flow_metric, result, :last_5_minutes)
publish_average_count_flow_metric(event_count_average_flow_metric, result, :last_15_minutes)
publish_average_size_flow_metric(byte_size_average_flow_metric, result, :last_1_minute)
publish_average_size_flow_metric(byte_size_average_flow_metric, result, :last_5_minutes)
publish_average_size_flow_metric(byte_size_average_flow_metric, result, :last_15_minutes)
result
end
private :refine_batch_metrics


def publish_average_count_flow_metric(average_flow_metric, result, time_window)
if average_flow_metric[time_window.to_s]
result[:event_count][:average][time_window] = average_flow_metric[time_window.to_s].round
end
end
private :publish_average_count_flow_metric

def publish_average_size_flow_metric(average_flow_metric, result, time_window)
if average_flow_metric[time_window.to_s]
result[:byte_size][:average][time_window] = average_flow_metric[time_window.to_s].round
end
end
private :publish_average_size_flow_metric

def report(stats, extended_stats = nil, opts = {})
ret = {
:events => stats[:events],
Expand Down
Loading