alibaba / Sentinel

A powerful flow control component enabling reliability, resilience and monitoring for microservices. (面向云原生微服务的高可用流控防护组件)
https://sentinelguard.io/
Apache License 2.0
22.41k stars 8.03k forks source link

Dashboard server not able to pull metrics from clients running in docker env #1378

Open nitishgoyal13 opened 4 years ago

nitishgoyal13 commented 4 years ago

Issue Description

My docker containers are running in mesos cluster and they are sending metrics to dashboard using the docker container host. Sentinel dashboard server isn't able to pull metrics from clients

My query is : I don't have a control where my docker containers will run in the mesos cluster. How shall I set the value of this variable -Dcsp.sentinel.heartbeat.client.ip = xxx so that all my docker clients should be able to send metrics?

Describe what happened (or what feature you want)

Describe what you expected to happen

I expect sentinel dashboard server to collect metrics from all sentinel clients

How to reproduce it (as minimally and precisely as possible)

Tell us your environment

Anything else we need to know?

nitishgoyal13 commented 4 years ago

@sczyh30 Can you please help out here ? And help me understand how to figure out what value needs to be set for the variable csp.sentinel.heartbeat.client.ip??

seasidesky commented 4 years ago

if your sentinel dashboard can receive your client heartbeat, then the problem may be you sentinel dashboard send fetch command but you client cannot receive it, the network is unavailable,please check:

nitishgoyal13 commented 4 years ago

Yes, that's exactly my point. How will the sentinel dashboard will collect metrics from client?

Client is registering to the dashboard with host and ip, that's only accessible within the host that docker container is running. Marathon maps the port exposed by docker via different port? Eg port 8719 will be exposed by marathon with some random port available on the host How can the client register to sentinel dashboard with the port which marathon will expose?

seasidesky commented 4 years ago

according to Requiring a specific host port you can setting "requirePorts": true in your app definition, but it is not recommended

nitishgoyal13 commented 4 years ago

I get what you are saying, but since we have multiple containers running in the same VM, not sure if the marathon will be able to start the container with the required port.

Do you have any other recommendations or any other suggestions which I can follow?

nitishgoyal13 commented 4 years ago

I finally worked it out using the environment variables which are set inside the docker env. Docker env maps the outside port to variables like PORT_8719 and PORT_8080. I used the value of these variables to register the clients with sentinel dashboard

If this use case seems to be good enough for you, I can send one pull request for supporting docker containers

Below is the snapshot of the code, I have used in my heartbeat

String host =  System.getenv("HOST");
            String port =  System.getenv("PORT_8719");

            Field field = getClass().getSuperclass()
                    .getDeclaredField("heartBeat");
            field.setAccessible(true);
            HeartbeatMessage heartBeat = (HeartbeatMessage) field.get(this);
            heartBeat.registerInformation("hostname", host);
            heartBeat.registerInformation("port", port);