diff --git a/.gitignore b/.gitignore index ac3ef25..e9206d6 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,4 @@ pom.xml.asc /mbeanz/pip-selfcheck.json /mbeanz/Python mbeanz/.Python +/dist diff --git a/mbeanz/mbeanz b/mbeanz/mbeanz index 9a66ad7..a21a39e 100755 --- a/mbeanz/mbeanz +++ b/mbeanz/mbeanz @@ -3,7 +3,7 @@ from __future__ import print_function import json import requests -import subprocess32 +import subprocess port = [line.rstrip('\n') for line in open('/var/tmp/mbeanz.port')][0] api_url = 'http://localhost:' + port @@ -21,7 +21,7 @@ def get_mbeans(): def select_mbean(): mbeans = str.join('\n', get_mbeans()) - fzf = subprocess32.Popen('fzf', stdin = subprocess32.PIPE, stdout = subprocess32.PIPE) + fzf = subprocess.Popen('fzf', stdin = subprocess.PIPE, stdout = subprocess.PIPE) mbean_operation = fzf.communicate(mbeans)[0].rstrip('\n').split(' ') return tuple(mbean_operation) @@ -33,7 +33,7 @@ def get_signature_string(index, description): def choose_signature(descriptions): strings = [get_signature_string(i, descr) for i, descr in enumerate(descriptions)] lines = str.join('\n', strings) - fzf = subprocess32.Popen('fzf', stdin = subprocess32.PIPE, stdout = subprocess32.PIPE) + fzf = subprocess.Popen('fzf', stdin = subprocess.PIPE, stdout = subprocess.PIPE) index = fzf.communicate(lines)[0].split(' ')[0] chosen = descriptions[int(index)] return tuple([chosen['description'], chosen['signature']]) diff --git a/project.clj b/project.clj index d0c0c37..212e6c9 100644 --- a/project.clj +++ b/project.clj @@ -12,13 +12,11 @@ [ring/ring-defaults "0.1.2"] [ring/ring-json "0.4.0"] [org.clojure/data.json "0.2.6"] - [clj-stacktrace "0.2.8"] - [environ "1.0.1"]] + [clj-stacktrace "0.2.8"]] :plugins [[lein-ring "0.8.13"] [jonase/eastwood "0.2.1"] [lein-kibit "0.1.2"] - [lein-cloverage "1.0.6"] - [lein-environ "1.0.1"]] + [lein-cloverage "1.0.6"]] :ring {:handler mbeanz.handler/app} :main mbeanz.handler :target-path "target/%s" diff --git a/src/mbeanz/core.clj b/src/mbeanz/core.clj index 2d1557e..9a97f0c 100644 --- a/src/mbeanz/core.clj +++ b/src/mbeanz/core.clj @@ -2,8 +2,7 @@ (:gen-class) (:require [clojure.java.jmx :as jmx] [clojure.core.match :refer [match]] - [mbeanz.common :refer :all] - [environ.core :refer [env]]) + [mbeanz.common :refer :all]) (:import [java.lang.IllegalArgumentException])) (defn get-identifiers [[bean-name & bean-ops]] diff --git a/src/mbeanz/handler.clj b/src/mbeanz/handler.clj index 354c256..04f4ee7 100644 --- a/src/mbeanz/handler.clj +++ b/src/mbeanz/handler.clj @@ -6,8 +6,8 @@ [compojure.core :refer :all] [mbeanz.core :refer :all] [mbeanz.common :refer :all] - [environ.core :refer [env]] - [clojure.java.jmx :as jmx]) + [clojure.java.jmx :as jmx] + [clojure.edn :as edn]) (:use [org.httpkit.server :only [run-server]] [clj-stacktrace.core :only [parse-exception]] [clojure.java.io :only [writer]]) @@ -15,11 +15,11 @@ (defonce server (atom nil)) -(def object-pattern (delay (or (env :mbeanz-object-pattern) "*:*"))) +(defonce object-pattern (atom "java.lang:*")) -(def jmx-remote-host (delay (or (env :mbeanz-jmx-remote-host) "localhost"))) +(defonce jmx-remote-host (atom "localhost")) -(def jmx-remote-port (delay (or (Integer/parseInt (env :mbeanz-jmx-remote-port)) 11080))) +(defonce jmx-remote-port (atom 1080)) (defn- identifier-string [identifiers] (map #(str (:bean %) " " (stringify (:operation %))) identifiers)) @@ -64,7 +64,16 @@ (wrap-json-response) (wrap-defaults api-defaults))) +(defn- reset-if-set [config key atom] + (when-let [value (key config)] + (reset! atom value))) + (defn -main [& args] + (when-let [config-file-path (first args)] + (let [config (edn/read-string (slurp config-file-path))] + (reset-if-set config :object-pattern object-pattern) + (reset-if-set config :jmx-remote-host jmx-remote-host) + (reset-if-set config :jmx-remote-port jmx-remote-port))) (reset! server (run-server app {:port 0})) (with-open [my-writer (writer "/var/tmp/mbeanz.port")] (.write my-writer (str (:local-port (meta @server))))))