Skip to content

Commit

Permalink
Merge branch 'release-3.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
greglook committed Nov 6, 2018
2 parents 1185843 + 46c8e1d commit 45c6a4f
Show file tree
Hide file tree
Showing 19 changed files with 423 additions and 89 deletions.
2 changes: 2 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ jobs:
working_directory: ~/repo
docker:
- image: circleci/clojure:lein-2.7.1
environment:
SOLANUM_LOG_APPENDER: nop
steps:
- checkout
- restore_cache:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/solanum
/dist
/target
/classes
/checkouts
Expand Down
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ This project adheres to [Semantic Versioning](http://semver.org/).

...

## [3.1.0] - 2018-11-05

### Added
- New HTTP source allows for checking URL endpoints and asserting that the
response meets certain properties.

## [3.0.0] - 2018-10-27

Clojure rewrite.
Expand All @@ -17,5 +23,6 @@ Clojure rewrite.

Final cut of Ruby version.

[Unreleased]: https://github.com/greglook/solanum/compare/3.0.0...HEAD
[Unreleased]: https://github.com/greglook/solanum/compare/3.1.0...HEAD
[3.1.0]: https://github.com/greglook/solanum/compare/3.0.0...3.1.0
[3.0.0]: https://github.com/greglook/solanum/compare/2.0.0...3.0.0
25 changes: 15 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
# Build file for Solanum
#
# https://www.astrecipes.net/blog/2018/07/20/cmd-line-apps-with-clojure-and-graalvm/
# https://medium.com/graalvm/instant-netty-startup-using-graalvm-native-image-generation-ed6f14ff7692

default: lint
default: package

.PHONY: setup clean lint test uberjar
.PHONY: setup clean lint test uberjar package

# TODO: fetch graal?
version := $(shell grep defproject project.clj | cut -d ' ' -f 3 | tr -d \")
platform := $(shell uname -s | tr '[:upper:]' '[:lower:]')
release_name := solanum_$(version)_$(platform)

# TODO: fetch graal?
setup:
lein deps

clean:
rm -rf target solanum
rm -rf target dist solanum

lint:
lein check
Expand All @@ -26,14 +26,19 @@ target/uberjar/solanum.jar: src/* resources/* svm/java/*

uberjar: target/uberjar/solanum.jar

solanum: reflection-config=svm/reflection-config.json
# TODO: --static ?
solanum: reflection-config := svm/reflection-config.json
solanum: target/uberjar/solanum.jar $(reflection-config)
$(GRAAL_PATH)/bin/native-image \
--report-unsupported-elements-at-runtime \
--delay-class-initialization-to-runtime=io.netty.handler.ssl.ReferenceCountedOpenSslEngine \
-H:ReflectionConfigurationFiles=$(reflection-config) \
-J-Xmx3G -J-Xms3G \
--no-server \
-jar $<

# seems to be automatic because of --report-unsupported-elements-at-runtime
#--delay-class-initialization-to-runtime=io.netty.handler.ssl.ReferenceCountedOpenSslEngine \
dist/$(release_name).tar.gz: solanum
@mkdir -p dist
tar -cvzf $@ $^

package: dist/$(release_name).tar.gz
9 changes: 3 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,9 @@ gem installs.

## Installation

Releases are published on Clojars and GitHub. To use the latest version with
Leiningen, add the following dependency to your project definition:

[![Clojars Project](http://clojars.org/mvxcvi/solanum/latest-version.svg)](http://clojars.org/mvxcvi/solanum)

To install the native binaries, simply place them on your path.
Releases are published on the [GitHub project](https://github.com/greglook/solanum/releases).
The native binaries are self-contained, so to install them simply place them on
your path.


## Metric Events
Expand Down
24 changes: 16 additions & 8 deletions config.yml → example-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,22 @@ sources:
- type: tcp
label: postgresql
port: 5432
#- type: certificate
# host: www.google.com
# period: 300
# attributes:
# ttl: 3600
# expiry_states:
# warning: 180
# critical: 30
- type: http
period: 300
label: vault
url: 'http://localhost:8200/v1/sys/health'
response_checks:
- type: status
values: [201, 429]
- type: data
key: initialized
value: true
- type: data
key: sealed
value: false
record_fields:
standby: standby
version: version

outputs:
- type: print
Expand Down
15 changes: 9 additions & 6 deletions project.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(defproject mvxcvi/solanum "3.0.0"
(defproject mvxcvi/solanum "3.1.0"
:description "Local host monitoring daemon."
:url "https://github.com/greglook/solanum"
:license {:name "Public Domain"
Expand All @@ -9,12 +9,20 @@

:dependencies
[[org.clojure/clojure "1.9.0"]
[org.clojure/data.json "0.2.6"]
[org.clojure/tools.cli "0.4.1"]
[org.clojure/tools.logging "0.4.1"]
[ch.qos.logback/logback-classic "1.2.3"]
[clj-http-lite "0.3.0"]
[org.yaml/snakeyaml "1.23"]
[riemann-clojure-client "0.5.0"]]

:cljfmt
{:padding-lines 2
:max-consecutive-blank-lines 3
:indents {cond [[:block 0]]
case [[:block 0]]}}

:hiera
{:cluster-depth 2
:vertical false
Expand All @@ -29,11 +37,6 @@
[org.clojure/tools.namespace "0.2.11"]]
:jvm-opts ["-DSOLANUM_LOG_APPENDER=repl"]}

:test
{:jvm-opts ["-DSOLANUM_LOG_APPENDER=nop"
"-DSOLANUM_LOG_LEVEL_ROOT=TRACE"
"-DSOLANUM_LOG_LEVEL=TRACE"]}

:svm
{:java-source-paths ["svm/java"]
:dependencies
Expand Down
3 changes: 2 additions & 1 deletion src/solanum/channel.clj
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
(ns solanum.channel
"Shared event channel."
"Shared event channel logic for sending collected metric events to be written
to outputs."
(:import
(java.util.concurrent
LinkedBlockingQueue
Expand Down
27 changes: 17 additions & 10 deletions src/solanum/config.clj
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,44 @@
[clojure.string :as str]
[clojure.tools.logging :as log]
[clojure.walk :as walk]
[solanum.output.core :as output]
[solanum.output.print]
[solanum.output.riemann]
[solanum.source.core :as source]
[solanum.source.cpu]
[solanum.source.disk-space]
[solanum.source.disk-stats]
[solanum.source.http]
[solanum.source.load]
[solanum.source.memory]
[solanum.source.network]
[solanum.source.process]
[solanum.source.tcp]
[solanum.source.test]
[solanum.source.uptime]
[solanum.output.core :as output]
[solanum.output.print]
[solanum.output.riemann]
[solanum.util :as u])
(:import
org.yaml.snakeyaml.Yaml))


;; ## File Loading

(defn- keybabify
"Replace underscores in a keyword with hyphens. Only uses the name portion."
[k]
(keyword (str/replace (name k) "_" "-")))


(defn- coerce-map
"Coerces a Java map into a Clojure map, keywordizing the keys and `:type`
values."
[m]
(into {}
(map (fn coerce-entry
[[k v]]
(let [k (u/keybabify k)]
(let [k (keybabify k)]
[k (if (= :type k)
(u/keybabify v)
(keybabify v)
v)])))
m))

Expand All @@ -62,17 +69,17 @@
(let [parser (Yaml.)
data (.load parser (slurp file))]
(walk/prewalk yaml->clj data))
(catch Exception ex
(log/error ex "Failed to load configuration from" path)))
(catch Exception ex
(log/error ex "Failed to load configuration from" path)))
(log/warn "Can't load configuration from nonexistent file" path))))


(defn- merge-config
"Merge configuration maps together to produce a combined config."
[a b]
{:defaults (u/merge-attrs (:defaults a) (:defaults b))
:sources (u/merge-vec (:sources a) (:sources b))
:outputs (u/merge-vec (:outputs a) (:outputs b))})
:sources (into (vec (:sources a)) (:sources b))
:outputs (into (vec (:outputs a)) (:outputs b))})



Expand Down Expand Up @@ -100,7 +107,7 @@
(log/error ex "Failed to initialize output:" (pr-str output-config)))))


(defn initialize-plugins
(defn- initialize-plugins
"Initialize all source and output plugins."
[config]
(-> (into {} config)
Expand Down
3 changes: 2 additions & 1 deletion src/solanum/output/riemann.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
[riemann.client :as riemann]
[solanum.output.core :as output])
(:import
io.riemann.riemann.client.RiemannClient))
(io.riemann.riemann.client
RiemannClient)))


(defn- add-timestamp
Expand Down
19 changes: 8 additions & 11 deletions src/solanum/scheduler.clj
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
(ns solanum.scheduler
"Event collection scheduling code."
(:require
[clojure.tools.logging :as log]
[solanum.channel :as chan]
[solanum.source.core :as source]
[solanum.util :as u]
[clojure.tools.logging :as log])
[solanum.util :as u])
(:import
(java.time
Instant)
(java.time.temporal
ChronoUnit)
java.time.Instant
java.time.temporal.ChronoUnit
(java.util
PriorityQueue
Queue)))
Expand Down Expand Up @@ -44,11 +42,10 @@
(defn collect-source
"Collect events from a source and put them onto the event channel."
[defaults source]
(let [prep-event (comp
#(assoc % :time (event-time))
(partial u/merge-attrs
defaults
(:attributes source)))]
(let [prep-event (comp #(assoc % :time (event-time))
(partial u/merge-attrs
defaults
(:attributes source)))]
(try
(log/debug "Collecting events from" (pr-str source))
(into [] (map prep-event) (source/collect-events source))
Expand Down
9 changes: 9 additions & 0 deletions src/solanum/source/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@

;; ## Event Helpers

(defn stopwatch
"Constructs a delayed value which will yield the number of milliseconds
elapsed since its construction when realized."
[]
(let [start (System/nanoTime)]
(delay
(/ (- (System/nanoTime) start) 1e6))))


(defn byte-str
"Format a byte size into a human-friendly string representation."
[size]
Expand Down
Loading

0 comments on commit 45c6a4f

Please sign in to comment.