Trying to understand REDIS Monitor command
Asked Answered
A

3

6

I'm trying to understand MONITOR command that is available in Redis and how can I use effectively to determine the load of my application. What I don't understand is how do I read the information that is being shown on the CLI. Like, I know that the number before the IP Address is the 'DB Index' but what can I infer from that number?

Example that is available on MONITOR is:.

$ redis-cli monitor
1339518083.107412 [0 127.0.0.1:60866] "keys" "*"
1339518087.877697 [0 127.0.0.1:60866] "dbsize"
1339518090.420270 [0 127.0.0.1:60866] "set" "x" "6"
1339518096.506257 [0 127.0.0.1:60866] "get" "x"
1339518099.363765 [0 127.0.0.1:60866] "del" "x"
1339518100.544926 [0 127.0.0.1:60866] "get" "x"

I'm unable to understand the significance of '1339518083.107412'.

Airframe answered 9/12, 2014 at 3:3 Comment(0)
H
10

The first part is the timestamp in the form seconds.microseconds.

Hiding answered 9/12, 2014 at 3:37 Comment(4)
Then how is this data useful in monitoring?Airframe
You can count the number of commands over a duration, aggregate their types etc.Lonnylonslesaunier
So I am assuming that the timestamp shown is the one at which command started executing and the delta between the first and the next timestamp is the time taken to execute the first command. Is it correct?Airframe
@Airframe only if the next command was processed immediately after the first one...Quitclaim
T
0

The first part is the number of seconds and microseconds since 1970/1/1 (The Unix epoch). So if you want to extract the time, you do this:

new DateTime(1970,1,1).AddSeconds(seconds).AddMilliseconds(microsecods/1000).ToLocalTime()

or you can do this to parse the whole line:

var match = Regex.Match(line, @"(?<seconds>\d+)\.(?<microsec>\d+) (?<client>\[[\d\.\s:]+?\]) \""(?<command>\w+?)\""");
var sec = long.Parse(match.Groups["seconds"].Value);
var mic = long.Parse(match.Groups["microsec"].Value);
var rest = line.Substring(match.Groups["command"].Index + match.Groups["command"].Length + 1).Trim();
var command = match.Groups["command"].Value,
var dateTime = new DateTime(1970, 1, 1).AddSeconds(sec).AddMilliseconds(mic / 1000).ToLocalTime()
Transgression answered 10/7, 2019 at 6:5 Comment(0)
D
0

Adding to the answers offered so far, and for the sake of those who want to know what that epoch time (indicated from the monitor command) is "to you" without writing code, you can use the free online tool at https://www.epochconverter.com/.

Simply copy/paste the time reported (such as 1717171962.847139), then drop that (including the decimal value) into the site's first form field, and click Timestamp to Human Date.

It will report the time back to you as your local day, time, including seconds and milliseconds. It also reports the GMT time and even the time relative to when you pasted it in. :-) For example, here's what it reported to me just now, for that time:

Assuming that this timestamp is in seconds:
GMT: Friday, May 31, 2024 4:12:42.847 PM
Your time zone: Friday, May 31, 2024 11:12:42.847 AM GMT-05:00 DST
Relative: 25 minutes ago

Quite nifty. I couldn't see a way to use the site by passing in the epoch time as a URL (though it does offer a "batch" feature, offering a form for if you had a number of times you wanted to convert).

I'd love to find a way to tell the Redis monitor command to simply report the time in a human-readable form, but I've not found it yet.

Delusion answered 31/5 at 16:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.