Giter Site home page Giter Site logo

capacitor's Introduction

Capacitor Build Status

PLEASE NOTE THIS LIBRARY IS NO LONGER MAINTAINED!!!

A Clojure client for InfluxDB.

Follow the [download instructions on influxdb.com] (https://influxdata.com/downloads/) to install the latest version of InfluxDB.

Support for InfluxDB v0.8.x is removed starting with v0.6.0.

Installation

Leiningen

Capacitor is distributed via Clojars. Add the following to your dependencies in project.clj:

:dependencies [[capacitor "0.6.0"]]

Usage

Require public functions

(use 'capacitor.core)

Configure a client

(def client (make-client {:db "mynewdb"}))

The default-client options are:

{:host     "localhost"
 :scheme   "http"
 :port     8086
 :username "root"
 :password "root"
 :db       "testdb"
 :version  "0.9"}

Get database server version

(version client)
;; => "0.11.0"

Ping database server

(ping client)
;; => 2.479 (response time in ms)

Create a database

(create-db client)
;; => true

List databases

(list-dbs client)
;; => ("_internal" "mynewdb")

Create a database user

(create-db-user client "myuser" "mypassword")
;; => true

List database users

(list-db-users client)
;; => [{:columns ["user" "admin"], :values [["myuser" false]]}]

You can also zipmap columns with their values adding a :results key:

(list-db-users client true)
;; => ({:results ({:admin false, :user "myuser"})})

Configure a client for the database user

(def c (make-client {:db "mynewdb" :username "myuser" :password "mypassword"}))

Writing data points

A point can be a map containing the following keys:

(write-point c
  {:measurement "cpu_load"
   :tags        {"host" "1" "dc" 1}
   :fields      {"value" 1.1}
   :timestamp   1457624412})

Which can be shortened to a vector:

(write-point c
;; measurement tags                fields        timestamp
  ["cpu_load"  {"host" "1" "dc" 1} {"value" 1.2} 1457624413])

You can write multiple points at once with write-points:

(write-points c
  [{:measurement "cpu_load"
     :tags        {"host" "2" "dc" 1}
     :fields      {"value" 0.4}
     :timestamp   1457624412}
    {:measurement "cpu_load"
     :tags        {"host" "3" "dc" 1}
     :fields      {"value" 0.8}
     :timestamp   1457624412}])

Or use the vector form for points:

(write-points c
  [["cpu_load" {"host" "8" "dc" 2} {"value" 0.7} 1457624412]
   ["cpu_load" {"host" "9" "dc" 2} {"value" 0.5} 1457624412]])

Write SQLish queries

(db-query c "SHOW SERIES" true)

(db-query c "SELECT * FROM cpu_load" true)

(db-query c "SELECT MAX(value) FROM cpu_load GROUP BY dc, host" true)

API Docs

API docs (codox)

Contributors

License

Copyright ยฉ 2013โ€“2016 Olivier Lauzon

Distributed under the Eclipse Public License.

capacitor's People

Contributors

jayp avatar kfirmanty avatar olauzon avatar pradeepchhetri avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

capacitor's Issues

Clojars version and AOT

The version currently deployed to clojars (0.3.1) has :aot :all and cannot be used alongside a current version of core.async.

I get the following when I try and use with [org.clojure/core.async "0.1.346.0-17112a-alpha"]: No single method: add_BANG__STAR_ of interface: clojure.core.async.impl.protocols.Buffer found for function: add!* of protocol: Buffer

Presumably clash is possible with the other dependencies too.

I see that 0.4.0 has already fixed this and I've built a non-canonical fork here: https://clojars.org/org.clojars.curvelogic/capacitor in case anyone's having similar problems.

...but if 0.4.0 is going to take a while it is probably worth publishing a 0.3.x that can be used with more recent dependencies?

Writing to multiple series in the same batch

Hi,

I'm quiet new to clojure, so I might have misinterpreted the docs, but it seems like post-points can only write to a single time-serie at a time.
Am I right about this, and if so, are they plans to add a method to write to multiple series in the batch ?

Odd behavior for timestamps older than 2001-09-09T01:46:40 (1000000000000)

If you try to insert any point whose timestamp is older than 2001-09-09T01:46:40, it will be converted to 2001-09-09T01:46:40, except for timestamp = 0 that will be correctly inserted as 1970-01-01T00:00:00.

I saw that there is a right padding logic to make ts always have a certain number of zeros.
Would not be clearer if write-point function had an optional param for user set what kind of precision he/she wants, instead of this padding logic?

Anyway capacitor is an excellent library, thanks for creating it.

Missing riddley.util requirement?

If I have capacitor 0.2.2 in my project deps, it will cause an exception when required, due to missing dependency on riddley.util. It works fine if I add riddley to my project deps manually. Not sure what's happening, since riddley doesn't seem to be explicitly referenced in capacitor's dependencies. Let me know if I can help debug it further.

=> (require '[capacitor.core :as inf])

ClassNotFoundException riddley.Util  java.net.URLClassLoader$1.run (URLClassLoader.java:372)

=> (pst)
ClassNotFoundException riddley.Util
        java.net.URLClassLoader$1.run (URLClassLoader.java:372)
        java.net.URLClassLoader$1.run (URLClassLoader.java:361)
        java.security.AccessController.doPrivileged (AccessController.java:-2)
        java.net.URLClassLoader.findClass (URLClassLoader.java:360)
        java.lang.ClassLoader.loadClass (ClassLoader.java:424)
        sun.misc.Launcher$AppClassLoader.loadClass (Launcher.java:308)
        java.lang.ClassLoader.loadClass (ClassLoader.java:357)
        java.lang.Class.forName0 (Class.java:-2)
        java.lang.Class.forName (Class.java:259)
        riddley.compiler/loading--4910--auto-- (compiler.clj:1)
        riddley.compiler__init.load (:1)
        riddley.compiler__init.<clinit> (:-1)
nil

Sync post-points should be able to send points to different series

Currently implementation artificially prevents specifying series-name on a per point basis, instead asking for a general series-name where to send all of them. IMO, it's unnecessary and much better behaviour is the one you use in async where every event can have a separate series-name specified.

results->maps? option in db-query throws

journey.core=> (capacitor.core/db-query db/client "SHOW MEASUREMENTS" true)
IllegalArgumentException No method in multimethod 'fmap' for dispatch value: class java.lang.Integer  clojure.lang.MultiFn.getFn (MultiFn.java:156)
journey.core=> *e
#error {
 :cause "No method in multimethod 'fmap' for dispatch value: class java.lang.Integer"
 :via
 [{:type java.lang.IllegalArgumentException
   :message "No method in multimethod 'fmap' for dispatch value: class java.lang.Integer"
   :at [clojure.lang.MultiFn getFn "MultiFn.java" 156]}]
 :trace
 [[clojure.lang.MultiFn getFn "MultiFn.java" 156]
  [clojure.lang.MultiFn invoke "MultiFn.java" 233]
  [capacitor.http$fmap_func invokeStatic "http.clj" 16]
  [capacitor.http$fmap_func invoke "http.clj" 14]
  [capacitor.http$fmap_func$fn__16954 invoke "http.clj" 16]
  [clojure.algo.generic.functor$eval16891$fn__16892$iter__16893__16897$fn__16898 invoke "functor.clj" 35]
  [clojure.lang.LazySeq sval "LazySeq.java" 40]
  [clojure.lang.LazySeq seq "LazySeq.java" 49]
  [clojure.lang.RT seq "RT.java" 521]
  [clojure.core$seq__4357 invokeStatic "core.clj" 137]
  [clojure.core.protocols$seq_reduce invokeStatic "protocols.clj" 24]
  [clojure.core.protocols$fn__6738 invokeStatic "protocols.clj" 75]
  [clojure.core.protocols$fn__6738 invoke "protocols.clj" 75]
  [clojure.core.protocols$fn__6684$G__6679__6697 invoke "protocols.clj" 13]
  [clojure.core$reduce invokeStatic "core.clj" 6545]
  [clojure.core$into invokeStatic "core.clj" 6610]
  [clojure.core$into invoke "core.clj" 6604]
  [clojure.algo.generic.functor$eval16891$fn__16892 invoke "functor.clj" 35]
  [clojure.lang.MultiFn invoke "MultiFn.java" 233]
  [capacitor.http$fmap_func invokeStatic "http.clj" 16]
  [capacitor.http$fmap_func invoke "http.clj" 14]
  [capacitor.http$fmap_func$fn__16954 invoke "http.clj" 16]
  [clojure.core$map$fn__4785 invoke "core.clj" 2644]
  [clojure.lang.LazySeq sval "LazySeq.java" 40]
  [clojure.lang.LazySeq seq "LazySeq.java" 49]
  [clojure.lang.RT seq "RT.java" 521]
  [clojure.core$seq__4357 invokeStatic "core.clj" 137]
  [clojure.core.protocols$seq_reduce invokeStatic "protocols.clj" 24]
  [clojure.core.protocols$fn__6738 invokeStatic "protocols.clj" 75]
  [clojure.core.protocols$fn__6738 invoke "protocols.clj" 75]
  [clojure.core.protocols$fn__6684$G__6679__6697 invoke "protocols.clj" 13]
  [clojure.core$reduce invokeStatic "core.clj" 6545]
  [clojure.core$into invokeStatic "core.clj" 6610]
  [clojure.core$into invoke "core.clj" 6604]
  [clojure.algo.generic.functor$eval16887$fn__16888 invoke "functor.clj" 31]
  [clojure.lang.MultiFn invoke "MultiFn.java" 233]
  [capacitor.http$fmap_func invokeStatic "http.clj" 16]
  [capacitor.http$fmap_func invoke "http.clj" 14]
  [capacitor.http$fmap_func$fn__16954 invoke "http.clj" 16]
  [clojure.algo.generic.functor$eval16891$fn__16892$iter__16893__16897$fn__16898 invoke "functor.clj" 35]
  [clojure.lang.LazySeq sval "LazySeq.java" 40]
  [clojure.lang.LazySeq seq "LazySeq.java" 49]
  [clojure.lang.RT seq "RT.java" 521]
  [clojure.core$seq__4357 invokeStatic "core.clj" 137]
  [clojure.core.protocols$seq_reduce invokeStatic "protocols.clj" 24]
  [clojure.core.protocols$fn__6738 invokeStatic "protocols.clj" 75]
  [clojure.core.protocols$fn__6738 invoke "protocols.clj" 75]
  [clojure.core.protocols$fn__6684$G__6679__6697 invoke "protocols.clj" 13]
  [clojure.core$reduce invokeStatic "core.clj" 6545]
  [clojure.core$into invokeStatic "core.clj" 6610]
  [clojure.core$into invoke "core.clj" 6604]
  [clojure.algo.generic.functor$eval16891$fn__16892 invoke "functor.clj" 35]
  [clojure.lang.MultiFn invoke "MultiFn.java" 233]
  [capacitor.http$fmap_func invokeStatic "http.clj" 16]
  [capacitor.http$fmap_func invoke "http.clj" 14]
  [capacitor.http$results__GT_maps invokeStatic "http.clj" 20]
  [capacitor.http$results__GT_maps invoke "http.clj" 18]
  [capacitor.http$extract invokeStatic "http.clj" 24]
  [capacitor.http$extract doInvoke "http.clj" 22]
  [clojure.lang.RestFn invoke "RestFn.java" 423]
  [capacitor.query$db_query invokeStatic "query.clj" 10]
  [capacitor.query$db_query invoke "query.clj" 8]
  [capacitor.core$db_query invokeStatic "core.clj" 130]
  [capacitor.core$db_query doInvoke "core.clj" 127]
...

Also happens in less trivial queries (every query I've tried so far). Latest capacitor version, latest InfluxDB (1.2.0)

Test environment?

Hi,

Sorry to write an issue here as I don't see a google group, but do you have any pointers on setting up a test environment? I tried setting up a test database however, deleting and creating the database between tests was causing issues ( they seem to happen asynchronously ), now I'm just trying to figure out how to write a statement to truncate tables between tests.

In the influx cli I can write "delete from quotes;" to truncate the quotes table, but I can't figure out how to write the equivalent via the clojure client. Any advice? Many thanks, great library.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.