How do I get statsd to increment a number

I have an output rule for statsd

    statsd {
        host      => "graphite-statsd"
        port      => 8125
        namespace => ""
        sender    => "%{backend_name}"
        increment => [
          "%{http_status_code}"
        ]
      }

this used to work great, but recently we upgraded logstash and it complains you can not increment a integer.

I can make this work by changing "%{http_status_code}" to "{http_status_code}X" however by adding the X I am corrupting my existing counters.

What can I do to make %{https_status_code} be treated as a string and not a number?

What's the exact error message?

NoMethodError: undefined method `gsub' for 200:Fixnum
            build_stat at /opt/logstash/vendor/bundle/jruby/1.9/gems/logstash-output-statsd-2.0.7/lib/logstash/outputs/statsd.rb:138
               receive at /opt/logstash/vendor/bundle/jruby/1.9/gems/logstash-output-statsd-2.0.7/lib/logstash/outputs/statsd.rb:113
                  each at org/jruby/RubyArray.java:1613
               receive at /opt/logstash/vendor/bundle/jruby/1.9/gems/logstash-output-statsd-2.0.7/lib/logstash/outputs/statsd.rb:112
         multi_receive at /opt/logstash/vendor/bundle/jruby/1.9/gems/logstash-core-2.3.4-java/lib/logstash/outputs/base.rb:83
                  each at org/jruby/RubyArray.java:1613
         multi_receive at /opt/logstash/vendor/bundle/jruby/1.9/gems/logstash-core-2.3.4-java/lib/logstash/outputs/base.rb:83
  worker_multi_receive at /opt/logstash/vendor/bundle/jruby/1.9/gems/logstash-core-2.3.4-java/lib/logstash/output_delegator.rb:130
         multi_receive at /opt/logstash/vendor/bundle/jruby/1.9/gems/logstash-core-2.3.4-java/lib/logstash/output_delegator.rb:114
          output_batch at /opt/logstash/vendor/bundle/jruby/1.9/gems/logstash-core-2.3.4-java/lib/logstash/pipeline.rb:301
                  each at org/jruby/RubyHash.java:1342
          output_batch at /opt/logstash/vendor/bundle/jruby/1.9/gems/logstash-core-2.3.4-java/lib/logstash/pipeline.rb:301
           worker_loop at /opt/logstash/vendor/bundle/jruby/1.9/gems/logstash-core-2.3.4-java/lib/logstash/pipeline.rb:232
         start_workers at /opt/logstash/vendor/bundle/jruby/1.9/gems/logstash-core-2.3.4-java/lib/logstash/pipeline.rb:201


probably changing:

to

metric = metric.to_s.gsub('::','.').gsub(RESERVED_CHARACTERS_REGEX, '_')

will do the trick, but then I have to patch the plugin.

FWIW I think this PR would fix it:

another option is to add a field that is a string version of http_status_code, like:

 mutate { add_field => { "http_status_code_string" => "%{http_status_code}" } }
 mutate { convert => { "number" => "http_status_code" } }

I see, if I do that how to I avoid shipping it to elastic?

ah you have other outputs, then nevermind, you'd have to disable dynamic mapping on ES to ignore new fields

1 Like