Metric's meter.count ruby variable name?


(Kelvin Fann) #1

I am trying to edit the metric's meter.count value with the ruby filter. Does anyone know the variable name of the metric?
I know it isn't Event['meter_name.count']


(Magnus Bäck) #2

event['meter_name.count'] works fine for me (with Logstash 1.5).

input {
  stdin {}
}

filter {
  metrics {
    meter => "meter_name"
    add_tag => "metric"
  }
  ruby {
    code => "
      event['message'] = 'Current count is: ' + event['meter_name.count'].to_s
    "
  }
}

output {
  if "metric" in [tags] {
    stdout {
      codec => json_lines
    }
  }
}

(Kelvin Fann) #3

That only gives me an instance (copy) of the actual meter_name.count. I believe that is the same thing as simply outputting the meter's info. I need to be able to change the meter_name.count so that all metric event instances will use that changed count after I change it.

I need to be able to do something like this (the following code will error):

input {
 stdin {}
}

filter {
  metrics {
    meter => "meter_name"
    add_tag => "metric"
  }
  ruby {
    code => "
      if meter_name.count > SOMENUM then meter_name.count = 0 done
    "
  }
}

output {
  if "metric" in [tags] {
    stdout {
        codec => rubydebug
    }
  }
}

(Magnus Bäck) #4

Oh, sorry. I missed the part about you wanting to modify the count. That's not supported, but it might be possible to access the filters via the pipeline object, locate the metrics filter, and access its members. Even if that's possible I'd try to find another way of solving the original problem.


(Kelvin Fann) #5

Well, my goal is to simply reset the counter after a certain amount/time. I know there is a clear_interval but I cannot seem to set the clear to occur directly after a flush. Is there a way to accomplish that?

Right now it seems that if I set clear_interval and flush_interval to the same time, the order of occurrences is set (I think the commands are set asynchronously?)


(system) #6