2014-01-14-twitter-trending-riemann.clj

view raw

; -*- mode: clojure; -*-
; vim: filetype=clojure

(logging/init)
(instrumentation {:enabled? false})
(udp-server)
(tcp-server)
(periodically-expire 1)

(let [store    (index)
      trending (top 10 :metric (tag "top" store) store)]
  (streams
    (by :service (moving-time-window 3600 (smap folds/sum trending)))))

2014-01-14-twitter-trending-firehose.rb

view raw

require 'tweetstream'
require 'riemann/client'

TweetStream.configure do |config|
  config.consumer_key       = 'xxx'
  config.consumer_secret    = 'xxx'
  config.oauth_token        = 'xxx'
  config.oauth_token_secret = 'xxx'
  config.auth_method        = :oauth
end

riemann = Riemann::Client.new


TweetStream::Client.new.sample do |status|
  tags = status.text.scan(/\s#([[:alnum:]]+)/).map{|x| x.first.downcase}

  tags.each do |tag|
    puts "emitting #{tag}"
    riemann << {
      service: "#{tag}",
      metric: 1.0,
      tags: ["twitter"],
      ttl: 3600
    }
  end
end