File tree Expand file tree Collapse file tree 2 files changed +32
-0
lines changed
Expand file tree Collapse file tree 2 files changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -44,6 +44,9 @@ var cmdErrC = make(chan error, cmdStdChanLen)
4444var cmdWarnC = make (chan string , cmdStdChanLen )
4545var done sync.WaitGroup
4646
47+ var jmxHost string
48+ var jmxPort string
49+
4750// jmxClientError error is returned when the nrjmx tool can not continue
4851type jmxClientError string
4952
@@ -215,6 +218,9 @@ func openConnection(config *connectionConfig) (err error) {
215218
216219 cliCommand := config .command ()
217220
221+ jmxHost = config .hostname
222+ jmxPort = config .port
223+
218224 ctx , cancel = context .WithCancel (context .Background ())
219225 cmd = exec .CommandContext (ctx , cliCommand [0 ], cliCommand [1 :]... )
220226
@@ -396,3 +402,13 @@ func logAvailableWarnings(channel chan string) {
396402 }
397403 }
398404}
405+
406+ // HostName returns the host the nrjmx is connected to
407+ func HostName () string {
408+ return jmxHost
409+ }
410+
411+ // Port returns the port the nrjmx is connected to
412+ func Port () string {
413+ return jmxPort
414+ }
Original file line number Diff line number Diff line change @@ -122,6 +122,8 @@ func TestQuery_WithSSL(t *testing.T) {
122122}
123123
124124func TestOpen_WithNrjmx (t * testing.T ) {
125+ defer Close ()
126+
125127 aux := os .Getenv ("NR_JMX_TOOL" )
126128 require .NoError (t , os .Unsetenv ("NR_JMX_TOOL" ))
127129
@@ -218,3 +220,17 @@ func Test_DefaultPath_IsCorrectForOs(t *testing.T) {
218220 t .Fatal ("unexpected value" )
219221 }
220222}
223+
224+ func TestHostName (t * testing.T ) {
225+ defer Close ()
226+ host := "a-host"
227+ assert .NoError (t , OpenNoAuth (host , "" ))
228+ assert .Equal (t , host , HostName ())
229+ }
230+
231+ func TestPort (t * testing.T ) {
232+ defer Close ()
233+ port := "6666"
234+ assert .NoError (t , OpenNoAuth ("" , port ))
235+ assert .Equal (t , port , Port ())
236+ }
You can’t perform that action at this time.
0 commit comments