Skip to content

Commit c18a111

Browse files
JMX host and port getters
Add JMX host and port getters so can be retrieved in the integrations when a connection query fails
2 parents 3f45fc5 + c88cf78 commit c18a111

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

jmx/jmx.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ var cmdErrC = make(chan error, cmdStdChanLen)
4444
var cmdWarnC = make(chan string, cmdStdChanLen)
4545
var 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
4851
type 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+
}

jmx/jmx_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ func TestQuery_WithSSL(t *testing.T) {
122122
}
123123

124124
func 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+
}

0 commit comments

Comments
 (0)