riemann/riemann

output plugin for timescaleDB

poojabms opened this issue · 2 comments

Hi,

We are looking at sending alerts generated by riemann to timescaleDB(an extension to postgresDB). We don't see any plugin available already. Is there any plan of implementing one in near future? If not, what would be the best way to send the data to any database for which a plugin is not available? We don't have any expertise on clojure. so writing a clojure plugin would be the last option for us. Appreciate any other pointers/suggestions.

Thanks in advance.

You could send your events to RabbitMQ (or Kafka), pull them out via programming language of choice, process and then put into TimescaleDB.
Using RabbitMQ, though, would require functionality proposed in #968 .

sanel commented

I haven't used TimescaleDB and I'm not sure if TimescaleDB has fixed schema, but from this [1] it looks like the schema is designed ad-hoc.

I think this might work, assuming you have time, host, service and metric colums (can be adjusted down below).

(add-dependencies
 :coordinates [[org.clojure/java.jdbc "0.7.12"]]
 :repositories {"clojars" "https://clojars.org/repo"})

(require '[clojure.java.jdbc :as j])

(defn timescaledb [db-spec table]
 (fn [events]
   (doseq [event events]
     (j/insert! db-spec table
       ;; adjust columns if necessary
       {:host    (:host event)
        :service (:service event)
        :metric  (:metric event)
        :time    (:time event)}))))

(def timescale
  (timescaledb {:dbtype "postgresql"
                :dbname "mydatabase"}
               "mytable"))
(streams
 timescale)

[1] https://docs.timescale.com/timescaledb/latest/quick-start/java/#insert_rows