Giter Club home page Giter Club logo

capacitor's Introduction

l3nz's Capacitor

The library is available on Clojars:

Clojars Project

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 [[lenz/capacitor "0.6.0.2"]]

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

Watchers

 avatar  avatar  avatar

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.