A Clojure library designed to send analytics to the analytics service
EPL-1.0 License
A Clojure library designed to send analytics to the analytics service.
Analytics are broken up into two types:
Snapshots describe the state of a system at a given time, while events describe a discrete event. Events can be reported to the analytics service immedately as they occcur, while snapshots are more often reported periodically.
Two functions are supplied for sending these analytics are
store-snapshot
and store-event
.
If the analytics-client is being called from within a Trapperkeeper
application, the config
argument can be derived from Trapperkeeper's
default service config via:
(select-keys config [:analytics])
To send a snapshot to the analytics service, use the store-snapshot
function. Its arguments are:
:ssl-opts
: An object with keys :ssl-cert
, :ssl-key
, and :ssl-ca-cert
.:url
: A string representing the URL where the analytics service:fields
: An object with unique keyword keys representing theA valid call to this function might look like this:
(let [config {:analytics {:url analytics-url
:ssl-opts ssl-opts}}
analytics {:fields {:puppetserver.metric1 "value"
:puppetserver.metric2 1337
:puppetserver.metric3 ["123" "456"]
:puppetserver.metric4 {:something "extra"}}}]
(analytics-client/store-snapshot config analytics))
To send an event to the analytics service, use the store-event
function. Its arguments are:
:ssl-opts
: An object with keys :ssl-cert
, :ssl-key
, and :ssl-ca-cert
.:url
: A string representing the URL where the analytics service:event
: A string representing the name of the event. Note that this:metadata
: An optional map representing any associated metadataA valid call to this function might look like this:
(let [ssl-opts {:ssl-cert ssl-cert
:ssl-key ssl-key
:ssl-ca-cert ssl-ca-cert}
config {:analytics {:url analytics-url
:ssl-opts ssl-opts}}
analytics {:event "puppetserver.some-event"
:metadata {:property1 "value"
:property2 1337
:property3 ["123" "456"]
:property4 {:some "value"}}}
(analytics-client/store-event config analytics))
To try out the analytics-client repo, perform the following:
lein tk
.lein repl
in this repo.(store-snapshot {:fields {:hello "world"}})
Copyright © 2017 Puppet
Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.