| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
package uk.co.gidley.jmxmonitor; |
| 18 |
|
|
| 19 |
|
import org.apache.commons.cli.CommandLine; |
| 20 |
|
import org.apache.commons.cli.CommandLineParser; |
| 21 |
|
import org.apache.commons.cli.HelpFormatter; |
| 22 |
|
import org.apache.commons.cli.Option; |
| 23 |
|
import org.apache.commons.cli.Options; |
| 24 |
|
import org.apache.commons.cli.ParseException; |
| 25 |
|
import org.apache.commons.cli.PosixParser; |
| 26 |
|
import org.slf4j.Logger; |
| 27 |
|
import org.slf4j.LoggerFactory; |
| 28 |
|
import uk.co.gidley.jmxmonitor.services.InitialisationException; |
| 29 |
|
|
| 30 |
|
import java.io.File; |
| 31 |
|
import java.io.IOException; |
| 32 |
|
|
| 33 |
|
|
| 34 |
|
|
| 35 |
|
|
|
|
|
| 73.5% |
Uncovered Elements: 9 (34) |
Complexity: 7 |
Complexity Density: 0.24 |
|
| 36 |
|
public class JmxMonitor { |
| 37 |
|
|
| 38 |
|
private static final Logger logger = LoggerFactory.getLogger(JmxMonitor.class); |
| 39 |
|
private static final String STOP = "stop"; |
| 40 |
|
|
|
|
|
| 72.7% |
Uncovered Elements: 9 (33) |
Complexity: 7 |
Complexity Density: 0.24 |
|
| 41 |
5
|
public static void main(String[] args) {... |
| 42 |
5
|
System.out.println("Starting JMX Monitor"); |
| 43 |
|
|
| 44 |
5
|
Options options = new Options(); |
| 45 |
5
|
Option configurationFileOption = new Option("c", true, "Configuration Path"); |
| 46 |
5
|
configurationFileOption.setRequired(true); |
| 47 |
5
|
configurationFileOption.setArgs(1); |
| 48 |
5
|
options.addOption(configurationFileOption); |
| 49 |
5
|
Option stopOption = new Option(STOP, false, "Pass to " + STOP + " the process"); |
| 50 |
5
|
options.addOption(stopOption); |
| 51 |
|
|
| 52 |
5
|
CommandLineParser parser = new PosixParser(); |
| 53 |
5
|
try { |
| 54 |
5
|
CommandLine cmd = parser.parse(options, args); |
| 55 |
2
|
String configurationFile = cmd.getOptionValue("c"); |
| 56 |
2
|
System.out.println("ConfigurationFile is " + configurationFile); |
| 57 |
2
|
File file = new File(configurationFile); |
| 58 |
2
|
if (file.exists() && file.canRead()) { |
| 59 |
2
|
if (cmd.hasOption(STOP)) { |
| 60 |
0
|
logger.debug("Stopping existing JMXMonitor"); |
| 61 |
0
|
new RegistryManager(configurationFile).stop(); |
| 62 |
|
} else { |
| 63 |
2
|
logger.debug("Starting new JMXMonitor"); |
| 64 |
2
|
new RegistryManager(configurationFile).start(); |
| 65 |
|
} |
| 66 |
|
} else { |
| 67 |
0
|
logger.error("Unable to read configuration exiting {}", file); |
| 68 |
|
} |
| 69 |
|
|
| 70 |
|
|
| 71 |
|
} catch (ParseException e) { |
| 72 |
3
|
logger.error("Exception occured {}", e); |
| 73 |
3
|
HelpFormatter formatter = new HelpFormatter(); |
| 74 |
3
|
formatter.printHelp("jmxMonitor", options); |
| 75 |
|
} catch (InitialisationException e) { |
| 76 |
0
|
logger.error("{}", e); |
| 77 |
0
|
throw new RuntimeException(e); |
| 78 |
|
} catch (IOException e) { |
| 79 |
0
|
logger.error("{}", e); |
| 80 |
0
|
throw new RuntimeException(e); |
| 81 |
|
} |
| 82 |
|
|
| 83 |
5
|
System.out.println("Exiting JMX Monitor"); |
| 84 |
|
} |
| 85 |
|
|
| 86 |
|
} |