How to monitor connected clients to a server usind InfluxDB and Grafana

Hello all,

I am having a server, to which clients can connect. I want to have a statistics about how many clients are connected at a time. For each client I record the remote IP address, too.

I am putting it into influxdb like this: I add one “row” in influxdb per client all with the same timestamp. That means if 4 clients are connected I write 4 records with the same timestamp into influxdb. I then hoped to rely on the count function of the Grafana query to plot the number of connected clients over time.

I is however not working properly. Is this possible to arrange data in InfluxDB like this? How does the Grafana query look like (e.g. get the number of connected clients of the last data point)?

Thanks for your help,
Thomas

Hello all,

I am having a server, to which clients can connect. I want to have a
statistics about how many clients are connected at a time. For each client
I record the remote IP address, too.

I am putting it into influxdb like this: I add one “row” in influxdb per
client all with the same timestamp.

…and, what else besides the timestamp? Without knowing what your records
look like, we can only guess how we might do such a thing, and probably come
up with something completely different from what you’re doing.

That means if 4 clients are connected I write 4 records with the same
timestamp into influxdb.

Personally I think I would write one record containing the remote IP address
each time a client connects, and then repeat each time interval until it
disconnects. “Time interval” is whatever resolution you want in the accuracy
of the measurements - do you want to know to the nearest minute, or the
nearest second, or something in between, when a client connected and
disconnected?

I then hoped to rely on the count function of the Grafana query to plot the
number of connected clients over time.

That sounds like a good plan.

Show us what your Grafana query is? Otherwise we can only guess what might be
wrong or might be improved.

I is however not working properly.

In what way is it not working?

You get no results at all? You get wrong results? You get duplicated
results? Give us some detail so we know what’s happening.

Is this possible to arrange data in InfluxDB like this?

I’m sure it is.

How does the Grafana query look like (e.g. get the number of connected
clients of the last data point)?

We’d need to know what your InfluxDB data set looks like to be able to answer
that.

Antony.

Thanks for your response. Let me address the points you brought up:

Structure of data in the database
I am using Telegraf to fetch the data and the line response looks like this:

> SSH_Tarpit,address_type=IPv4,host=myhost.com,url=http://localhost:8888 duration=169659.61936,ip_address="124.6.1.150" 1559753173000000000
> SSH_Tarpit,address_type=IPv4,host=myhost.com,url=http://localhost:8888 duration=88731.547528,ip_address="24.231.75.237" 1559753173000000000
> SSH_Tarpit,address_type=IPv4,host=myhost.com,url=http://localhost:8888 duration=117999.266295,ip_address="14.32.29.69" 1559753173000000000

In this case I am storing the address type as a tag, and the ip address and the duration as values for each connected client.

Querying the database and visualization
I am using a standard graph panel in grafana using the following query:

SELECT count("ip_address") FROM "SSH_Tarpit" WHERE time >= now() - 2d GROUP BY time(2m) fill(null)

I am unsure what I have to to with the GROUP_BY clause. It just gets wrong values, maybe because the summation is not working properly. I am using a query interval of 5s and I have also set 5s as the min time interval in the query pane of the graph. For me it seem not grouping at all would be better but I do not fully understand this grouping stuff to be honest when usind in connection with a count() function.

Thanks again for your support,
Thomas