Roman
Roman

Reputation: 66156

Is there anything in HttpServletRequest what I can use to identify node in a cluster?

How can I identify node within a cluster using info in HttpServletRequest?

Any info which is unique for each node is suitable - I need it to distinguish logs.

Upvotes: 2

Views: 691

Answers (3)

iTech
iTech

Reputation: 18440

You can try to get the IP and hostname

// Get client's IP address
String ipAddress = request.getRemoteAddr(); // ip

// Get client's hostname
String hostname = request.getRemoteHost(); // hostname

If it did not give what you want, I would print all the request header and see if there is a unique identifier

for example, some servers would add x-forwarded-for or X_FORWARDED_FOR if the request go through proxy

Upvotes: 3

rtcarlson
rtcarlson

Reputation: 424

java.net.InetAddress.getLocalHost() would give you the name of the host that served the request. Does that get you what you need?

Upvotes: 1

gaborsch
gaborsch

Reputation: 15758

Add a system variable with -Dnode.id=1, then you can access it with System.getProperty("node.id").

Upvotes: 1

Related Questions