Force flush before shutdown

Hi, I have been trying to write an interval metric counter for logstash and I was wondering if it was possible to force logstash to flush a message before shutdown so that if I restarted the logstash, it would not lose any message count or data.