user95025
user95025

Reputation: 175

Trying to understand REDIS Monitor command

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'.

Upvotes: 6

Views: 4521

Answers (3)

charlie arehart
charlie arehart

Reputation: 6884

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.

Upvotes: 0

Mahmood Dehghan
Mahmood Dehghan

Reputation: 8265

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()

Upvotes: 0

Barış Uşaklı
Barış Uşaklı

Reputation: 13532

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

Upvotes: 10

Related Questions