Skip to content

Commit

Permalink
cli,
Browse files Browse the repository at this point in the history
some refactoring
  • Loading branch information
tcurdt committed Feb 14, 2012
1 parent a65d7b6 commit 8f14262
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 15 deletions.
15 changes: 7 additions & 8 deletions src/main/java/org/vafer/jmx/Agent.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,13 @@ public void stop() {

public static void premain(String args, Instrumentation inst) {
System.out.println("Starting jmx2any agent");
Agent agent = new Agent(args);
agent.start();
new Agent(args).start();
}

public static void main(String[] args) throws Exception {
premain("/Users/tcurdt/Projects/jmx2any/config.yaml", null);
while(true) {
Thread.sleep(10*1000);
}
}
// public static void main(String[] args) throws Exception {
// premain("/Users/tcurdt/Projects/jmx2any/config.yaml", null);
// while(true) {
// Thread.sleep(10*1000);
// }
// }
}
3 changes: 3 additions & 0 deletions src/main/java/org/vafer/jmx/Exporter.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package org.vafer.jmx;

import org.vafer.jmx.output.*;
import org.vafer.jmx.pipe.CompositePipe;
import org.vafer.jmx.pipe.ConverterPipe;
import org.vafer.jmx.pipe.JmxPipe;
import org.yaml.snakeyaml.Yaml;

import java.io.FileInputStream;
Expand Down
27 changes: 25 additions & 2 deletions src/main/java/org/vafer/jmx/Main.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,34 @@
package org.vafer.jmx;

import com.beust.jcommander.JCommander;
import com.beust.jcommander.Parameter;

public final class Main {

public static void main(String[] args) throws Exception {
// @Parameter(names = "-url", description = "jmx url")
// private String url = "service:jmx:rmi:///jndi/rmi://localhost:7199/jmxrmi";
//
// @Parameter(names = "-query", description = "query")
// private String query = "";

@Parameter(names = "-config", description = "path to config file", required = true)
private String configPath = "";

private void run() throws Exception {
Exporter exporter = new Exporter();
Exporter.Config config = exporter.load("/Users/tcurdt/Projects/jmx2any/config.yaml");
Exporter.Config config = exporter.load(configPath);
exporter.output(config);
}

public static void main(String[] args) throws Exception {
Main m = new Main();
JCommander cli = new JCommander(m);
try {
cli.parse(args);
} catch(Exception e) {
cli.usage();
System.exit(1);
}
m.run();
}
}
36 changes: 34 additions & 2 deletions src/main/java/org/vafer/jmx/output/OutputFactory.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,43 @@
package org.vafer.jmx.output;

import java.util.Locale;
import java.util.Map;

import static org.vafer.jmx.output.GangliaOutput.UDPAddressingMode;
import static org.vafer.jmx.output.GangliaOutput.ProtocolVersion;

public final class OutputFactory {

public static Output createOutput(Map<String, ?> config) {
// System.out.println("" + config);
return new ConsoleOutput();
final String type = ((String) config.get("type")).toLowerCase(Locale.US);

if ("ganglia".equals(type)) {

String group = (String) config.get("address");
Integer port = (Integer) config.get("port");
UDPAddressingMode mode = UDPAddressingMode.valueOf((String)config.get("mode"));
ProtocolVersion version = ProtocolVersion.valueOf((String)config.get("version"));
return new GangliaOutput(group, port, mode, version);

} else if ("graphite".equals(type)) {

String host = (String) config.get("address");
Integer port = (Integer) config.get("port");
return new GraphiteOutput(host, port);

} else if ("nagios".equals(type)) {

return new NagiosOutput();

} else if ("file".equals(type)) {

return new FileOutput();

} else {

System.err.println("jmx2any: unknown output type [" + type + "]");
return new ConsoleOutput();

}
}
}
1 change: 1 addition & 0 deletions src/main/java/org/vafer/jmx/output/OutputFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.vafer.jmx.JmxQuery;
import org.vafer.jmx.formatter.DefaultFormatter;
import org.vafer.jmx.pipe.JmxPipe;

import javax.management.AttributeNotFoundException;
import javax.management.InstanceNotFoundException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.vafer.jmx.output;
package org.vafer.jmx.pipe;

import org.vafer.jmx.JmxQuery;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package org.vafer.jmx.output;
package org.vafer.jmx.pipe;

import org.vafer.jmx.JmxQuery;
import org.vafer.jmx.formatter.DefaultFormatter;
import org.vafer.jmx.output.Enums;
import org.vafer.jmx.output.Output;

import java.io.IOException;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.vafer.jmx.output;
package org.vafer.jmx.pipe;

import org.vafer.jmx.JmxQuery;

Expand Down

0 comments on commit 8f14262

Please sign in to comment.