Skip to content

Instantly share code, notes, and snippets.

@jarpy
Last active November 8, 2021 00:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jarpy/987118c4b61ad8bbea3a59f06bf6684a to your computer and use it in GitHub Desktop.
Save jarpy/987118c4b61ad8bbea3a59f06bf6684a to your computer and use it in GitHub Desktop.

Riemann Live Hacking

This document is a guide to "live hacking" a running Riemann instance. Riemann exposes an nREPL, allowing us to connect to it, live in production, and run Clojure code inside its brain.

This document can be considered a rudimentary form of literate Clojure:

  • Open it in your editor
  • Connect your editor REPL client to tcp/5557 on the Riemann instance
  • Evaluate forms

Add a stream directly to the running core

(ns riemann.config)
(let [core riemann.config/core
      new-stream (where (service =~ "wibble")
                        (tag :live-hacked (index)))]
  (locking core
    (swap! core assoc :streams (conj (:streams @core) new-stream)))

  ;; Reload services (like the TCP input) so they see the new stream.
  (doseq [service (riemann.core/core-services @core)]
    (riemann.service/reload! service @core)))

Remove the most recently added stream

(let [core riemann.config/core]
  (locking core
    (swap! core assoc :streams (butlast (:streams @core))))
  (doseq [service (riemann.core/core-services @riemann.config/core)]
    (riemann.service/reload! service @riemann.config/core)))

Inject an event

(riemann.core/stream!
 @riemann.config/core
 (riemann.common/event
  {:host "wibblator"
   :service "wibble water level"
   :metric 500
   :time (riemann.time/unix-time)}))

Search the index for events using the Riemann query language

(riemann.index/search
 (riemann.config/index)
 (riemann.query/ast "service =~ \"wibble %\""))

Retrieve one field from found events

(map :metric
     (riemann.index/search
      (riemann.config/index)
      (riemann.query/ast "service = \"wibble water level\"")))

Delete everything from the index

(riemann.index/clear (:index @riemann.config/core))

Reset Riemann to undo your meddling

⚠️ Resets stream state.

(riemann.bin/reload!)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment