0

我的数据狗代理拒绝连接,该代理试图从其自己的 docker 容器中存在的内部应用程序收集 JMX(通过 RMI)指标。但是,jconsole 能够从存在于其自己的 docker 容器中的应用程序中收集指标。datadog-agent 存在于它自己的容器中。两个容器都存在于同一主机上的同一网络中。有任何想法吗?我查看了其他堆栈溢出问题。

  • 已在自定义 jmx.yaml 文件 /etc/dd-agent/conf.d/jmx.yaml 中尝试了 IP 地址 0.0.0.0 和特定主机地址

Docker 容器 0:
* 运行输出 kafka 流指标的 my_streams_app
* 通过以下方式执行:

`docker run -d --name my_streams_app  
      -v /var/run/docker.sock:/var/run/docker.sock:ro  
      -v /proc/:/host/proc/:ro  
      -v /sys/fs/cgroup/:/host/sys/fs/cgroup:ro  
      -e API_KEY=someapikeyhere  
      -e SD_JMX_ENABLE=yes -p 9998:9998 --network=my_streams_default quay.io/temp/my_streams`
  • jconsole 能够获取发出的指标。

Docker 容器 1:
* 在容器内运行 datadog-agent * Datadog-agent 使用 JMX 默认 (RMI) 从上面容器 0 中存在的 my_streams_app 获取指标。
* 两个容器在同一主机(我的笔记本电脑 MAC OSX)内的同一网络上运行
* 能够从 docker 容器中的 datadog-agent 中的 netcat 到另一个容器中的 my_streams_app ip 和端口。使用 0.0.0.0 和 9998,还可以使用特定 IP 地址
* 命令从容器内运行 datadog 代理

docker run -v /var/run/docker.sock:/var/run/docker.sock:ro  -v /proc/:/host/proc/:ro -v /sys/fs/cgroup/:/host/sys/fs/cgroup:ro -e LOG_LEVEL=DEBUG -e SD_BACKEND=docker --network=mystreams_default 4b1488e74733
  • 用于通过 datadog jmx 从容器内收集指标的 jmx 配置:

    实例:

    • 主机:0.0.0.0 端口:9998 标签:newTag:my_streams jmx_url:“服务:jmx:rmi:///jndi/rmi://0.0.0.0:9998/jmxrmi” 名称:jmx_instance

    docker_images: - my_streams_app

    init_config: is_jmx: true conf: - include: domain: '"kafka.streams"' bean: '"kafka.streams":type="stream-metrics",client-id="my_test-1-StreamThread-1"'属性:commit-calls-rate:metric_type:gauge commit-time-avg:metric_type:gauge commit-time-max:metric_type:gauge poll-calls-rate:metric_type:gauge

JConsole:
* 从 docker 容器 0 中的 my_streams_app 收集指标,上面通过:

jconsole 0.0.0.0:9998  

错误输出:

2017-07-05 20:48:20,236 | ERROR | App | Cannot connect to instance service:jmx:rmi:///jndi/rmi://0.0.0.0:9998/jmxrmi. java.io.IOException: 

Failed to retrieve RMIServer stub: javax.naming.ServiceUnavailableException [Root exception is java.rmi.ConnectException: Connection refused to host: 0.0.0.0; nested exception is: 
    java.net.ConnectException: Connection refused (Connection refused)]
java.io.IOException: java.io.IOException: Failed to retrieve RMIServer stub: javax.naming.ServiceUnavailableException [Root exception is java.rmi.ConnectException: Connection refused to host: 0.0.0.0; nested exception is: 
    java.net.ConnectException: Connection refused (Connection refused)]
    at org.datadog.jmxfetch.Connection.connectWithTimeout(Connection.java:117)
    at org.datadog.jmxfetch.Connection.createConnection(Connection.java:61)
    at org.datadog.jmxfetch.RemoteConnection.<init>(RemoteConnection.java:56)
    at org.datadog.jmxfetch.ConnectionFactory.createConnection(ConnectionFactory.java:29)
    at org.datadog.jmxfetch.Instance.getConnection(Instance.java:162)
    at org.datadog.jmxfetch.Instance.init(Instance.java:173)
    at org.datadog.jmxfetch.App.init(App.java:511)
    at org.datadog.jmxfetch.App.main(App.java:115)
Caused by: java.io.IOException: Failed to retrieve RMIServer stub: javax.naming.ServiceUnavailableException [Root exception is java.rmi.ConnectException: Connection refused to host: 0.0.0.0; nested exception is: 
    java.net.ConnectException: Connection refused (Connection refused)]
    at javax.management.remote.rmi.RMIConnector.connect(RMIConnector.java:370)
    at javax.management.remote.JMXConnectorFactory.connect(JMXConnectorFactory.java:268)
    at org.datadog.jmxfetch.Connection$1.run(Connection.java:86)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:473)
    at java.util.concurrent.FutureTask.run(FutureTask.java:262)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:745)
Caused by: javax.naming.ServiceUnavailableException [Root exception is java.rmi.ConnectException: Connection refused to host: 0.0.0.0; nested exception is: 
    java.net.ConnectException: Connection refused (Connection refused)]
    at com.sun.jndi.rmi.registry.RegistryContext.lookup(RegistryContext.java:142)
    at com.sun.jndi.toolkit.url.GenericURLContext.lookup(GenericURLContext.java:204)
    at javax.naming.InitialContext.lookup(InitialContext.java:415)
    at javax.management.remote.rmi.RMIConnector.findRMIServerJNDI(RMIConnector.java:1928)
    at javax.management.remote.rmi.RMIConnector.findRMIServer(RMIConnector.java:1895)
    at javax.management.remote.rmi.RMIConnector.connect(RMIConnector.java:287)
    ... 7 more
Caused by: java.rmi.ConnectException: Connection refused to host: 0.0.0.0; nested exception is: 
    java.net.ConnectException: Connection refused (Connection refused)
    at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:619)
    at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:216)
    at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:202)
    at sun.rmi.server.UnicastRef.newCall(UnicastRef.java:341)
    at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
    at com.sun.jndi.rmi.registry.RegistryContext.lookup(RegistryContext.java:138)
    ... 12 more
Caused by: java.net.ConnectException: Connection refused (Connection refused)
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:198)
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
    at java.net.Socket.connect(Socket.java:580)
    at java.net.Socket.connect(Socket.java:529)
    at java.net.Socket.<init>(Socket.java:429)
    at java.net.Socket.<init>(Socket.java:209)
    at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirectSocketFactory.java:40)
    at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMasterSocketFactory.java:147)
    at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:613)

rmir​​egistry 已根据Failed to retrieve RMIServer stub启动

4

1 回答 1

0

解决方案:

  • 码头集装箱 0

    • 运行输出指标的应用程序
    • 在输出指标的应用程序中创建一个 bash 脚本。
    • 在脚本中使用将 docker 容器 $HOSTNAME 环境变量的值设置为 jmxremote.host 和 rmi.server.hostname。

    #!/bin/sh
    java -Djava.util.logging.config.file=logging.properties -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote。 ssl=false -Dcom.sun.management.jmxremote.rmi.port=9998 -Dcom.sun.management.jmxremote.port=9998 -Djava.rmi.server.hostname=$HOSTNAME -Dcom.sun.management.jmxremote.host =$HOSTNAME -Dcom.sun.management.jmxremote.local.only=false -jar /app/my-streams.jar

    • 记得设置 chmod +x
    • 将 dockerfile CMD 设置为运行上面的脚本,如下所示:
      CMD["./"]
  • 码头集装箱 1

    • 运行 datadog 代理的容器
    • 如上所述配置问题中提到的 jmx.yaml 文件。只需将主机设置为应用程序名称
  • 可以从堆栈溢出帖子中获得更多的东西。但以上修复了从 datadog-agent 中发现错误的指标。


以下是如何运行每个组件:

docker container 0
* my-streams
* 在选项卡中启动依赖服务
** mvn clean package docker:build
** docker-compose up

  • 另一个选项卡启动 my-streams-app
    ** docker kill my-streams-app
    ** docker rm my-streams-app
    ** docker run -d --name my-streams-app -p 9998:9998 -- network= mystreams_default quay.io/myimage/my-streams

docker 容器 1
* docker build -t dd-agent-my-streams 。
* docker run -v /var/run/docker.sock:/var/run/docker.sock:ro -v /proc/:/host/proc/:ro -v /sys/fs/cgroup/:/host/ sys/fs/cgroup:ro -e LOG_LEVEL=DEBUG -e SD_BACKEND=docker --network=mystreams_default

ssh 进入 docker 容器 1 以验证指标是否有效
* docker ps // 查找要登录的容器的名称
* docker exec -it /bin/bash
root@904e6561cc97:/# service datadog-agent configcheck
root@904e6561cc97:/ # service datadog-agent jmx list_everything
root@904e6561cc97:/# service datadog-agent jmx collect

于 2017-07-06T00:17:35.177 回答