I'm currently attempting to split a single activity SQL record with a start and end time into multiple documents in an index. Each document will have a single timestamp (and duplicated data fields) and each timestamp is 15 minutes apart: slicing up a compile run into multiple pieces. I know of no visualization tools that end in "*ana" that can visualize records with start and end time and show the reserved resource (cores, threads, whatever...) as a line or bar in a time series plot while the job was active. I only get a blip for the values at the start of the event. I want a steady line of # cores/threads/mice on wheels used over the entirety of the duration of event until end_time.
Assume a record looks something like this:
<start_time_iso8601>, <end_time_iso8601>, <resources_used>, <user>, <project>, <hostname>
I wish to break this into multiple slices where each timestamp is 15 minutes apart. So if the difference between start_time_iso8601 and end_time_iso8601 is 48 minutes, I would have five slices with data:
start_time_iso8601, <resources_used>, <user>, <project>, <hostname>
start_time_iso8601+15 min, <resources_used>, <user>, <project>, <hostname>
start_time_iso8601+30 min, <resources_used>, <user>, <project>, <hostname>
start_time_iso8601+45 min, <resources_used>, <user>, <project>, <hostname>
end_time_iso8601, <resources_used>, <user>, <project>, <hostname>
Data is coming from a SQL database. Is this even possible? I'm trying to do it in a Ruby filter using LogStash::Event.new(), but I'm clearly missing something (including complete documentation) since I end up with all kinds of filewatch errors and warnings when I do this. Another, earlier Ruby filter called in the .conf calculates the number of slices the event will require. Now I'm looking to actually generate five new events from the first one. All in the pursuit of being able to display historical data of resources used.
Any explanation here or pointers to how LogStash::Event.new() actually works would be fine.
Here's how I'm currently trying to do this based upon the few threads I've been able to find that are kind of similar:
#!/usr/bin/env ruby
# the value of `params` is the value of the hash passed to `script_params`
# in the logstash configuration
def register(params)
#@times = params["time_field"]
end
# the filter method receives an event and must return a list of events.
# Dropping an event means not including it in the return array,
# while creating new ones only requires you to add a new instance of
# LogStash::Event to the returned array
def filter(event)
require 'time'
# The number of necessary slices was found in a previous
# filter, so generate that number of events with each
# event having its own timestamp that is set 15 minutes
# later than the previous event.
num_of_slices = event.get( "num_of_slices" )
running_timestamp = Time.parse( event.get( "@opentimestamp" ) )
end_timestamp = Time.parse( event.get( "@closetimestamp" ) )
runind = event.get( "runidx" )
num_of_slices.to_i.times { |i|
newhash = event.to_hash
gen = LogStash::Event.new( newhash )
gen.set( "runidxseq", runind.to_s + "_" + i.to_s )
gen.set( "@slice_timestamp", running_timestamp )
gen.set( "@timestamp_common", running_timestamp )
if num_of_slices > 1
if running_timestamp + 900 > end_timestamp
gen.set( "@slice_timestamp", end_timestamp )
gen.set( "@timestamp_common", end_timestamp )
end
running_timestamp = running_timestamp + 900
end
new_event_block.call( gen )
}
# First step recreated this event, so drop the incoming version.
event.cancel
end
@timestamp_common is the agreed 'reference' timestamp field to allow multiple indices to plot together with a single proper x-axis date histogram. Doing it here rather than in the .conf file as a mutate operation.
Thank you for any help.
nick