Skip to content

Commit

Permalink
Merge pull request #6 from ojung/easy-installation
Browse files Browse the repository at this point in the history
Enable easy installation
  • Loading branch information
oskar committed Sep 23, 2015
2 parents 41a4567 + 1ca1856 commit a747f08
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 14 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ pom.xml.asc
/mbeanz/pip-selfcheck.json
/mbeanz/Python
mbeanz/.Python
/dist
6 changes: 3 additions & 3 deletions mbeanz/mbeanz
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

Expand All @@ -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']])
Expand Down
6 changes: 2 additions & 4 deletions project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 1 addition & 2 deletions src/mbeanz/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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]]
Expand Down
19 changes: 14 additions & 5 deletions src/mbeanz/handler.clj
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@
[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]])
(:import java.lang.management.ManagementFactory))

(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))
Expand Down Expand Up @@ -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))))))

0 comments on commit a747f08

Please sign in to comment.