Total Number of connections for each connected Redis Service
Asked Answered
C

5

5

How to check which service is consuming more resources on Redis.

Or which service has the highest number of connections on Redis?

Clothesline answered 19/7, 2017 at 10:48 Comment(0)
Y
8

You can type the command "CLIENT LIST", You'll see these like :

id=39 addr=127.0.0.1:34706 fd=7 name= age=141156 idle=0 flags=N db=0 sub=0 psub=0 multi=-1 qbuf=0 qbuf-free=32768 obl=0 oll=0 omem=0 events=r cmd=client
id=78 addr=127.0.0.1:58014 fd=5 name= age=63779 idle=0 flags=N db=0 sub=0 psub=0 multi=-1 qbuf=0 qbuf-free=0 obl=0 oll=0 omem=0 events=r cmd=llen
id=80 addr=127.0.0.1:36826 fd=6 name= age=46776 idle=1685 flags=N db=1 sub=0 psub=0 multi=-1 qbuf=0 qbuf-free=0 obl=0 oll=0 omem=0 events=r cmd=del

The most useful keys for your answer is "age" && "idle" , "age" means the total duration of the connection in seconds and "idle" means idle time of this connection. so (age - idle) / age relects this client uses server's cpu more than other client which the value is smaller , but not very precisely

Other command also can give you some suggestions, like "INFO" and "MONITOR" . INFO gives you a statistics information about redis server , such as the memory usage, the command processed, the cpu usage, the connected clients and so on , you can refer this to get more.

"MONITOR" gives you a real time display which says that what happens now, what command is being executed, who sent this command. Maybe you can compute the every client resource using by the MONITOR output.

e.g. for every command, you first parse it and using a cost to add the client cost sum. In time consuming computing, SET is O(1) and Lrange is O(N). But this is also difficult to do this very precisely. But you can log this using this command like :

 redis-cli monitor > redis-command.log

you can use this log to do some analytics. but notes that MONITOR command will reduce your redis server throughput, check this

Yolandoyolane answered 20/7, 2017 at 2:19 Comment(1)
Thank you. One more thing, is it possible to get environment name from IP address? I am using boto3 but cant find out how to get environment nameClothesline
R
4

Do simply

info clients

output

connected_clients:xxx
client_longest_output_list:xxx
client_biggest_input_buf:x
blocked_clients:xx
Richards answered 13/1, 2023 at 17:9 Comment(0)
G
2

To get which client is having higher number of connection we can use the below shell script

#!/bin/bash

# Get the list of clients with their connection count
clients=$(redis-cli client list | awk '{print $2}' | sort | uniq -c | sort -rn)

# Print the client with the highest number of connections
highest=$(echo "$clients" | head -n 1)
echo "Client with the highest number of connections: $highest"

This will provide the top first client which has more no of clients I hope it will help!!

Gotham answered 22/2, 2023 at 12:2 Comment(0)
B
1

If you run the "client list" command against your Redis instance, you should be able to see the entire list of clients connected to your redis instance along with their IP addresses. You can then see which clients (services) have the highest number of connections to your Redis instance.

Belva answered 19/7, 2017 at 16:21 Comment(4)
How can I check which client have the highest number of connections?Clothesline
The command just gives you an IP addresses and a name per connection. You can name every connection, perhaps by prepending or appending the client name to each connection. You will need to aggregate this information to find out which IP address or client has the most connections.Belva
Is it possible to get environment name from IP address?Clothesline
I'm assuming that you are asking about the client name. You can parse the name from the client list output, when the IP address you are looking for matches. I don't know of any ready made lookup mechanism.Belva
S
0

To get the connection count per client IP, run the following command

redis-cli CLIENT LIST | awk -F[=:] '{print $3}' | sort | uniq -c | sort 

Or in case awk cmd didn't work properly:

redis-cli CLIENT LIST | cut -f 2 -d " " | cut -f 2 -d "=" | cut -f 1 -d":" | sort | uniq -c | sort

The output would be something like this:

     1 10.10.X.X
     8 10.10.X.X
     15 10.10.X.X
     20 10.10.X.X
Schweiz answered 22/10, 2023 at 9:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.