summaryrefslogtreecommitdiff
path: root/debian/mongoreplay.1
blob: 68448ff912123f0c123aa93bd738cef254b018ce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
.\" Man page generated from reStructuredText.
.
.TH "MONGOREPLAY" "1" "Oct 29, 2019" "4.2" "mongodb-manual"
.SH NAME
mongoreplay \- MongoDB Traffic Capture and Replay Tool
.
.nr rst2man-indent-level 0
.
.de1 rstReportMargin
\\$1 \\n[an-margin]
level \\n[rst2man-indent-level]
level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
-
\\n[rst2man-indent0]
\\n[rst2man-indent1]
\\n[rst2man-indent2]
..
.de1 INDENT
.\" .rstReportMargin pre:
. RS \\$1
. nr rst2man-indent\\n[rst2man-indent-level] \\n[an-margin]
. nr rst2man-indent-level +1
.\" .rstReportMargin post:
..
.de UNINDENT
. RE
.\" indent \\n[an-margin]
.\" old: \\n[rst2man-indent\\n[rst2man-indent-level]]
.nr rst2man-indent-level -1
.\" new: \\n[rst2man-indent\\n[rst2man-indent-level]]
.in \\n[rst2man-indent\\n[rst2man-indent-level]]u
..
.SS On this page
.INDENT 0.0
.IP \(bu 2
\fI\%Synopsis\fP
.IP \(bu 2
\fI\%Availability\fP
.IP \(bu 2
\fI\%Required Access\fP
.IP \(bu 2
\fI\%Options\fP
.IP \(bu 2
\fI\%Commands\fP
.IP \(bu 2
\fI\%mongoreplay Report Format\fP
.IP \(bu 2
\fI\%Examples\fP
.UNINDENT
.SH SYNOPSIS
.sp
New in version 3.4.

.INDENT 0.0
.INDENT 3.5
.IP "Availability"
.sp
Available for Linux and macOS.
.UNINDENT
.UNINDENT
.sp
\fI\%mongoreplay\fP is a traffic capture and replay tool for MongoDB
that you can use to inspect and record commands sent to a MongoDB
instance, and then replay those commands back onto another host at a
later time.
.sp
\fI\%mongoreplay\fP can help you preview how your MongoDB deployment
will perform a production workload under a different environment,
such as with a different storage engine, on different hardware, or
with a different operating system configuration.
\fI\%mongoreplay\fP can also help reproduce and investigate an issue by
recording and replaying the operations that trigger the issue.
Finally, \fI\%mongoreplay\fP serves as a more flexible version of
the legacy \fBmongosniff\fP tool to help you investigate database activity.
.sp
Run \fI\%mongoreplay\fP from the system command line, not the \fBmongo\fP shell.
.SH AVAILABILITY
.sp
The \fI\%mongoreplay\fP tool is part of the MongoDB tools package. Consult the
installation guide for your platform for
instructions on how to install the tools package as part of your
MongoDB installation.
.sp
The tools package is also available from the
\fI\%MongoDB Download Center\fP,
either as a separate \fBtools\fP download, or contained within the
\fBTGZ\fP or \fBZIP\fP downloads, depending on platform. The \fBmongoreplay\fP tool is not available on Windows.
.INDENT 0.0
.INDENT 3.5
.SH TIP
.sp
If downloading the \fBTGZ\fP or \fBZIP\fP files from the Download
Center, you may want to update your \fBPATH\fP environment
variable to include the directory where you installed these tools.
See the installation guide
for your platform for more information.
.UNINDENT
.UNINDENT
.SH REQUIRED ACCESS
.sp
\fI\%mongoreplay\fP requires access to the network interface that
the \fI\%record\fP or \fI\%monitor\fP commands will
listen on. You may need to run \fI\%mongoreplay\fP with root privileges
to access the network device.
.sp
\fI\%mongoreplay\fP will not work with MongoDB instances using an SSL connection.
.sp
\fBWARNING:\fP
.INDENT 0.0
.INDENT 3.5
Only use root privileges when connecting to trusted sources.
.UNINDENT
.UNINDENT
.sp
If you are using \fI\%play\fP to connect to a MongoDB deployment
that enforces access control, you must
connect as a user with the required privileges to execute the
recorded operations. Include the user\(aqs credentials in the
\fI\%\-\-host\fP MongoDB connection string.
.SH OPTIONS
.INDENT 0.0
.TP
.B mongoreplay
.UNINDENT
.INDENT 0.0
.TP
.B \-\-verbosity, \-v
Increases the amount of internal reporting returned on standard output
or in log files. Increase the verbosity with the \fB\-v\fP form by
including the option multiple times, (e.g. \fB\-vvvvv\fP\&.)
.UNINDENT
.INDENT 0.0
.TP
.B \-\-debug, \-d
Increases the amount of detail about \fBmongoreplay\fP operations
and errors recorded
in log files. Increase the debugging detail with the \fB\-d\fP form by
including the option multiple times, (e.g. \fB\-ddd\fP\&.)
.UNINDENT
.INDENT 0.0
.TP
.B \-\-silent, \-s
When set, \fBmongoreplay\fP does not produce any log output.
.UNINDENT
.INDENT 0.0
.TP
.B \-\-help
Returns information on the options and use of \fBmongoreplay\fP\&.
.UNINDENT
.SH COMMANDS
.sp
\fI\%mongoreplay\fP includes the following \fIcommands\fP to record,
play back, and monitor MongoDB network traffic.
.SS \fBmongoreplay record\fP
.sp
\fI\%record\fP produces a playback file based on
network traffic. \fI\%record\fP supports collecting network
traffic directly or can
accept a \fI\%pcap file\fP
to produce the playback file.
The playback file contains a list of all requests sent to the
\fBmongod\fP instance during the recording as well as all
responses transmitted to the client during the recording. The playback
file also records metadata for each request, such as the connection
identifier and timestamp.
.sp
The following prototype uses \fI\%mongoreplay\fP to record data
on the loopback network interface and creates a playback file
located at \fB~/recordings/playback\fP\&.
.INDENT 0.0
.INDENT 3.5
.sp
.nf
.ft C
mongoreplay record \-i eth0 \-e "port 27017" \-p ~/recordings/playback
.ft P
.fi
.UNINDENT
.UNINDENT
.sp
Similarly, the following prototype uses \fI\%mongoreplay\fP
to produce a playback file from an existing pcap file:
.INDENT 0.0
.INDENT 3.5
.sp
.nf
.ft C
mongoreplay record \-f traffic.pcap \-p ~/recordings/playback
.ft P
.fi
.UNINDENT
.UNINDENT
.sp
\fBrecord\fP supports the following options:
.INDENT 0.0
.TP
.B mongoreplay record
.UNINDENT
.INDENT 0.0
.TP
.B record
.UNINDENT
.INDENT 0.0
.TP
.B \-f <path>
Specifies the path to a pcap file that \fI\%record\fP should read to
produce a playback file.
.sp
Use \fB\-f\fP as an alternative to capturing network traffic using
\fB\-i\fP\&. You must specify \fIeither\fP \fB\-f\fP or \fB\-i\fP\&. If you include
both options, \fBmongoreplay record\fP produces an error.
.UNINDENT
.INDENT 0.0
.TP
.B \-b <number>
Size of heap used to merge separate streams together.
.UNINDENT
.INDENT 0.0
.TP
.B \-\-expr <filter expression>, \-e <filter expression>
An expression in \fI\%Berkeley Packet Filter (BPF) syntax\fP to apply to incoming traffic to
record. Required if you are capturing traffic from a network interface using
\fI\%\-i\fP\&.
.sp
For example, to capture traffic from a MongoDB instance running on
port 27017, you would specify \fB\-e \(aqport 27017\(aq\fP\&.
.UNINDENT
.INDENT 0.0
.TP
.B \-i <interface>
Specifies the network interface that \fI\%record\fP should listen on to
capture network traffic.
.sp
Use with \fI\%\-e\fP\&.
.sp
Use \fB\-i\fP as an alternative to reading an existing pcap file with
\fB\-i\fP\&. You must specify \fIeither\fP \fB\-f\fP or \fB\-i\fP\&. If you include
both options, \fBmongoreplay record\fP produces an error.
.UNINDENT
.INDENT 0.0
.TP
.B \-\-gzip <boolean>
If specified, \fI\%record\fP compresses the playback file with gzip.
.UNINDENT
.INDENT 0.0
.TP
.B \-\-playback\-file <path>, \-p <path>
Specifies the path to which to write the playback file.
.sp
The produced playback file is a BSON file.
.UNINDENT
.INDENT 0.0
.INDENT 3.5
.SS See
.sp
\fI\%Use record\fP for examples of using
\fI\%mongoreplay\fP with the \fBrecord\fP command.
.UNINDENT
.UNINDENT
.SS \fBmongoreplay play\fP
.sp
\fBNOTE:\fP
.INDENT 0.0
.INDENT 3.5
Starting in MongoDB 4.0, \fI\%mongoreplay play\fP supports a new
\fBMONGOREPLAY_HOST\fP environment variable that specifies the
MongoDB connection string. The new environment
vairable can be used instead of the command\-line \fI\%\-\-host\fP option.
.UNINDENT
.UNINDENT
.INDENT 0.0
.TP
.B play
\fI\%play\fP replays a playback file created with
\fI\%record\fP against a \fBmongod\fP instance.
.UNINDENT
.sp
For example, the following uses \fI\%mongoreplay play\fP to replay the
\fB~/recordings/playback\fP playback file to the \fBmongod\fP instance running on
\fB192.168.0.4:27018\fP:
.INDENT 0.0
.IP \(bu 2
Using the \fI\%\-\-host\fP option:
.INDENT 2.0
.INDENT 3.5
.sp
.nf
.ft C
mongoreplay play \-p ~/recordings/playback \-\-report ~/reports/replay_stats.json \-\-host mongodb://192.168.0.4:27018
.ft P
.fi
.UNINDENT
.UNINDENT
.IP \(bu 2
Using the \fBMONGOREPLAY_HOST\fP environment variable (Available starting in MongoDB 4.0):
.INDENT 2.0
.INDENT 3.5
.sp
.nf
.ft C
export MONGOREPLAY_HOST="mongodb://192.168.0.4:27018"
mongoreplay play \-p ~/recordings/playback \-\-report ~/reports/replay_stats.json
.ft P
.fi
.UNINDENT
.UNINDENT
.UNINDENT
.SS \fBplay\fP Options
.sp
\fBplay\fP supports the following options:
.INDENT 0.0
.TP
.B mongoreplay play
.UNINDENT
.INDENT 0.0
.TP
.B \-\-collect <json|format|none>
\fIDefault\fP: format
.sp
Specifies the output format for the collected statistics.
.INDENT 7.0
.IP \(bu 2
\fBjson\fP: outputs stat information as json
.IP \(bu 2
\fBformat\fP: uses the formatting specified in the \fB\-\-format\fP option
to produce the output file.
.IP \(bu 2
\fBnone\fP: does not provide any output
.UNINDENT
.UNINDENT
.INDENT 0.0
.TP
.B \-\-report <path>
Specifies the path to which to write an execution report.
Use \fI\%\-\-collect\fP to specify the output format for the report.
.sp
If you do not specify \fB\-\-report\fP, \fI\%play\fP writes to STDOUT.
.UNINDENT
.INDENT 0.0
.TP
.B \-\-no\-truncate
If specified, disables truncation of large reply payload data in the
\fI\%play\fP log output.
.UNINDENT
.INDENT 0.0
.TP
.B \-\-format
\fIDefault\fP: \fB%F{blue}%t%f %F{cyan}(Connection: %o:%i)%f %F{yellow}%l%f
%F{red}%T %c%f %F{white}%n%f
%F{green}%Q{Request:}%f%q%F{green}%R{Response:}%f%r)\fP
.sp
Specifies the format for terminal output.
You can specify arguments immediately after the format \(aqverbs\(aq by wrapping
them in curly braces, as in \fB%Q{<arg>}\fP\&.
.sp
If you specify \fI\%\-\-format\fP, also specify \fBformat\fP as the value for the
\fI\%\-\-collect\fP option.
.sp
\fI\%\-\-format\fP supports the following verbs:
.INDENT 7.0
.IP \(bu 2
\fB%n\fP: namespace
.IP \(bu 2
\fB%l\fP: latency
.IP \(bu 2
\fB%t\fP: time. You may optionally specify the date layout using the
Go Programming Language\(aqs \fI\%time formatting\fP\&. Go
uses \fBMon Jan 2 15:04:05 MST 2006\fP as its reference time. You
must specify the time format using the reference time. Thus, if you
wanted to print the date in format \fByyyy\-mm\-dd hh:mm\fP, you would
specify \fB%t{2006\-01\-02 15:04}\fP\&. Refer to the Go \fI\%time formatting\fP
documentation for more information.
.IP \(bu 2
\fB%T\fP: op time
.IP \(bu 2
\fB%c\fP: command
.IP \(bu 2
\fB%o\fP: number of connections
.IP \(bu 2
\fB%i\fP: request ID
.IP \(bu 2
\fB%q\fP: request. You may optinally specified a dot\-delimited field
within the JSON structure, as in, \fB%q{command_args.documents}\fP\&.
.IP \(bu 2
\fB%r\fP: response. You may optinally specified a dot\-delimited field
within the JSON structure, as in, \fB%q{command_args.documents}\fP\&.
.IP \(bu 2
\fB%Q{<arg>}\fP: display \fB<arg>\fP on presence of request data
.IP \(bu 2
\fB%R{<arg>}\fP: display \fB<arg>\fP on presence of response data
.UNINDENT
.sp
In addition, \fI\%\-\-format\fP supports the following start/end ANSI escape sequences:
.INDENT 7.0
.IP \(bu 2
\fB%B\fP/\fB%b\fP: bold
.IP \(bu 2
\fB%U\fP/\fB%u\fP: underline
.IP \(bu 2
\fB%S\fP/\fB%s\fP: standout
.IP \(bu 2
\fB%F\fP/\fB%f\fP: text color (required arg \-\- word or number, 8\-color)
.IP \(bu 2
\fB%K\fP/\fB%k\fP: background color (required arg \-\- same as %F/%f)
.UNINDENT
.UNINDENT
.INDENT 0.0
.TP
.B \-\-no\-colors
When set, removes colors from the \fI\%default format\fP\&.
.UNINDENT
.INDENT 0.0
.TP
.B \-\-playback\-file <path>, \-p <path>
Specifies the path from which to read the playback file.
.sp
If the playback file was created using the \fI\%\-\-gzip\fP option, you must also specify \fB\-\-gzip\fP
when running \fI\%play\fP\&.
.UNINDENT
.INDENT 0.0
.TP
.B \-\-speed number
\fIDefault\fP: 1.0
.sp
Specifies a multiplier to adjust playback speed. \fB\-\-speed 1.0\fP
processes the playback file in real time; \fB\-\-speed 0.5\fP at half
speed; \fB\-\-speed 3.0\fP at triple speed.
.sp
The specified speed is a \fItarget\fP speed. If \fBmongoreplay play\fP encounters
a bottleneck, playback may be slower than the specified multiplier.
.UNINDENT
.INDENT 0.0
.TP
.B \-\-host <uri connection string>
\fIDefault\fP: mongodb://localhost:27017
.sp
Specifies a MongoDB connection string
for the MongoDB deployment to which to
play back the captured network traffic.
.sp
By default, \fI\%play\fP
attempts to connect to a \fBmongod\fP instance running on the localhost on
port number \fB27017\fP\&.
.sp
\fBNOTE:\fP
.INDENT 7.0
.INDENT 3.5
Starting in MongoDB 4.0, \fI\%mongoreplay play\fP supports a new
\fBMONGOREPLAY_HOST\fP environment variable that specifies the
connection string for the MongoDB deployment. The new environment
vairable can be used instead of the command\-line \fI\%\-\-host\fP option.
.sp
If \fI\%\-\-host\fP command\-line option is
specified, the \fI\%\-\-host\fP value overrides
the environment variable.
.UNINDENT
.UNINDENT
.UNINDENT
.INDENT 0.0
.TP
.B \-\-repeat number
\fIDefault\fP: 1
.sp
Specifies the number of times to play the playback file.
.UNINDENT
.INDENT 0.0
.TP
.B \-\-queueTime number
\fIDefault\fP: 15
.sp
Specifies the maximum time, in seconds, to queue operations in advance
of transmitting them.
.UNINDENT
.INDENT 0.0
.TP
.B \-\-no\-preprocess
When set, \fI\%play\fP does not preprocess the input file to pre\-map
data such as MongoDB cursor IDs.
.UNINDENT
.INDENT 0.0
.TP
.B \-\-gzip <boolean>
If specified, \fI\%play\fP decompresses the playback file with gzip.
.UNINDENT
.INDENT 0.0
.INDENT 3.5
.SS See
.sp
\fI\%Use play\fP for examples of using
\fI\%mongoreplay\fP with the \fI\%play\fP command.
.UNINDENT
.UNINDENT
.SS \fBmongoreplay monitor\fP
.sp
\fI\%monitor\fP inspects live or pre\-recorded
MongoDB network traffic.
.sp
The following prototype uses \fI\%mongoreplay\fP to produce a
JSON report based on the \fBplayback.bson\fP playback file in the \fB~/recordings\fP directory:
.INDENT 0.0
.INDENT 3.5
.sp
.nf
.ft C
mongoreplay monitor \-\-collect json \-\-report ~/reports/monitor\-report.json \-p ~/recordings/playback.bson
.ft P
.fi
.UNINDENT
.UNINDENT
.sp
\fBmonitor\fP supports the following options:
.INDENT 0.0
.TP
.B mongoreplay monitor
.UNINDENT
.INDENT 0.0
.TP
.B monitor
.UNINDENT
.INDENT 0.0
.TP
.B \-\-collect <json|format|none>
\fIDefault\fP: format
.sp
Specifies the output format for the collected statistics.
.INDENT 7.0
.IP \(bu 2
\fBjson\fP: outputs stat information as json
.IP \(bu 2
\fBformat\fP: uses the formatting specified in the \fB\-\-format\fP option
to produce the output file.
.IP \(bu 2
\fBnone\fP: does not provide any output
.UNINDENT
.UNINDENT
.INDENT 0.0
.TP
.B \-\-report <path>
Specifies the path to which to write an execution report.
Use \fI\%\-\-collect\fP to specify the output format for the report.
.sp
If you do not specify \fB\-\-report\fP, \fI\%monitor\fP writes to STDOUT.
.UNINDENT
.INDENT 0.0
.TP
.B \-\-no\-truncate
If specified, disables truncation of large reply payload data in the
\fI\%monitor\fP log output.
.UNINDENT
.INDENT 0.0
.TP
.B \-\-format
\fIDefault\fP: \fB%F{blue}%t%f %F{cyan}(Connection: %o:%i)%f %F{yellow}%l%f
%F{red}%T %c%f %F{white}%n%f
%F{green}%Q{Request:}%f%q%F{green}%R{Response:}%f%r)\fP
.sp
Specifies the format for terminal output.
You can specify arguments immediately after the format \(aqverbs\(aq by wrapping
them in curly braces, as in \fB%Q{<arg>}\fP\&.
.sp
If you specify \fI\%\-\-format\fP, also specify \fBformat\fP as the value for the
\fI\%\-\-collect\fP option.
.sp
\fI\%\-\-format\fP supports the following verbs:
.INDENT 7.0
.IP \(bu 2
\fB%n\fP: namespace
.IP \(bu 2
\fB%l\fP: latency
.IP \(bu 2
\fB%t\fP: time. You may optionally specify the date layout using the
Go Programming Language\(aqs \fI\%time formatting\fP\&. Go
uses \fBMon Jan 2 15:04:05 MST 2006\fP as its reference time. You
must specify the time format using the reference time. Thus, if you
wanted to print the date in format \fByyyy\-mm\-dd hh:mm\fP, you would
specify \fB%t{2006\-01\-02 15:04}\fP\&. Refer to the Go \fI\%time formatting\fP
documentation for more information.
.IP \(bu 2
\fB%T\fP: op time
.IP \(bu 2
\fB%c\fP: command
.IP \(bu 2
\fB%o\fP: number of connections
.IP \(bu 2
\fB%i\fP: request ID
.IP \(bu 2
\fB%q\fP: request. You may optinally specified a dot\-delimited field
within the JSON structure, as in, \fB%q{command_args.documents}\fP\&.
.IP \(bu 2
\fB%r\fP: response. You may optinally specified a dot\-delimited field
within the JSON structure, as in, \fB%q{command_args.documents}\fP\&.
.IP \(bu 2
\fB%Q{<arg>}\fP: display \fB<arg>\fP on presence of request data
.IP \(bu 2
\fB%R{<arg>}\fP: display \fB<arg>\fP on presence of response data
.UNINDENT
.sp
In addition, \fI\%\-\-format\fP supports the following start/end ANSI escape sequences:
.INDENT 7.0
.IP \(bu 2
\fB%B\fP/\fB%b\fP: bold
.IP \(bu 2
\fB%U\fP/\fB%u\fP: underline
.IP \(bu 2
\fB%S\fP/\fB%s\fP: standout
.IP \(bu 2
\fB%F\fP/\fB%f\fP: text color (required arg \-\- word or number, 8\-color)
.IP \(bu 2
\fB%K\fP/\fB%k\fP: background color (required arg \-\- same as %F/%f)
.UNINDENT
.UNINDENT
.INDENT 0.0
.TP
.B \-\-no\-colors
When set, removes colors from the \fI\%default format\fP\&.
.UNINDENT
.INDENT 0.0
.TP
.B \-f <path>
Specifies the path to a pcap file that \fI\%monitor\fP should read to
produce a playback file.
.sp
Use \fB\-f\fP as an alternative to capturing network traffic using
\fB\-i\fP\&. You must specify \fIeither\fP \fB\-f\fP or \fB\-i\fP\&. If you include
both options, \fBmongoreplay monitor\fP produces an error.
.UNINDENT
.INDENT 0.0
.TP
.B \-b <number>
Size of heap used to merge separate streams together.
.UNINDENT
.INDENT 0.0
.TP
.B \-\-expr <filter expression>, \-e <filter expression>
An expression in \fI\%Berkeley Packet Filter (BPF) syntax\fP to apply to incoming traffic to
record. Required if you are capturing traffic from a network interface using
\fI\%\-i\fP\&.
.sp
For example, to capture traffic from a MongoDB instance running on
port 27017, you would specify \fB\-e \(aqport 27017\(aq\fP\&.
.UNINDENT
.INDENT 0.0
.TP
.B \-i <interface>
Specifies the network interface that \fI\%monitor\fP should listen on to
capture network traffic.
.sp
Use with \fI\%\-e\fP\&.
.sp
Use \fB\-i\fP as an alternative to reading an existing pcap file with
\fB\-i\fP\&. You must specify \fIeither\fP \fB\-f\fP or \fB\-i\fP\&. If you include
both options, \fBmongoreplay monitor\fP produces an error.
.UNINDENT
.INDENT 0.0
.TP
.B \-\-paired
When specified, \fI\%monitor\fP outputs one line for each request/reply pair record.
.UNINDENT
.INDENT 0.0
.TP
.B \-\-gzip <boolean>
If specified, \fI\%monitor\fP decompresses the playback file with gzip.
.UNINDENT
.INDENT 0.0
.TP
.B \-\-playback\-file <path>, \-p <path>
Specifies the path from which to read the playback file.
.UNINDENT
.INDENT 0.0
.INDENT 3.5
.SS See
.sp
\fI\%Use monitor\fP for examples of using
\fI\%mongoreplay\fP with the \fI\%monitor\fP command.
.UNINDENT
.UNINDENT
.SH MONGOREPLAY REPORT FORMAT
.sp
\fI\%monitor\fP and \fI\%play\fP can produce
reports based on a playback file when run with the \fB\-\-report\fP option.
.SS Sample Record
.sp
The following is an example record from a JSON\-formatted
\fI\%monitor\fP report:
.INDENT 0.0
.INDENT 3.5
.sp
.nf
.ft C
{
   "order" : 21,
   "op" : "op_msg",
   "command" : "aggregate",
   "ns" : "test",
   "request_data" : {
      "sections" : [
         {
            "payload" : {
               "$db" : "test",
               "aggregate" : "foo",
               "cursor" : {},
               "lsid" : {
                  "id" : {
                     "$binary" : "eBZNIaAbRTiAoWkaNZ0T8Q==",
                     "$type" : "04"
                  }
               },
               "pipeline" : [
                  { "$match" : { "borough" : "Queens" } },
                  { "$group" : { "_id" : "$cuisine", "count" : { "$sum": 1 } } }
               ]
            },
            "payloadType" : 0
         }
      ]
   },
   "connection_num" : 0,
   "seen" : "2018\-11\-15T14:07:07.136794\-05:00",
   "request_id" : 25
}
.ft P
.fi
.UNINDENT
.UNINDENT
.SS Fields
.sp
\fI\%mongoreplay\fP reports can include the following fields:
.INDENT 0.0
.TP
.B order
A monotonically increasing key indicating the order in which the
operations were recorded and played back. This can be used to
reconstruct the ordering of the series of operations executed on a
connection, since the order in which they appear in the report file
may not match the playback order.
.UNINDENT
.INDENT 0.0
.TP
.B op
The type of operation represented by the request: i.e. "query",
"insert", "command", "getmore".
.UNINDENT
.INDENT 0.0
.TP
.B command
The name of the database command performed, such as \fBisMaster\fP or
\fBgetLastError\fP\&. This field is left blank for operations that are not
commands, such as queries and inserts.
.UNINDENT
.INDENT 0.0
.TP
.B ns
The namespace on which the request was executed.
.UNINDENT
.INDENT 0.0
.TP
.B request_data
The payload of the operation.
.INDENT 7.0
.IP \(bu 2
Query operations: \fBrequest_data\fP contains the actual
query that was issued.
.IP \(bu 2
Insert operations: \fBrequest_data\fP contains the documents
being inserted.
.IP \(bu 2
Update operations: \fBrequest_data\fP contains the query
selector and the update modifier.
.UNINDENT
.UNINDENT
.INDENT 0.0
.TP
.B reply_data
The payload of the reply to the request.
.UNINDENT
.INDENT 0.0
.TP
.B nreturned
The number of documents returned as a result of the operation.
.UNINDENT
.INDENT 0.0
.TP
.B played_at
The time at which the \fI\%play\fP command executed
the operation.
.UNINDENT
.INDENT 0.0
.TP
.B play_at
The time at which the operation was supposed to be executed by
the \fI\%play\fP command.
.UNINDENT
.INDENT 0.0
.TP
.B playbacklag_us
The difference in microseconds in time between \fBplayed_at\fP
and \fBplay_at\fP\&. Higher values generally indicate that the
target server is not able to keep up with the rate at which requests
need to be executed according to the playback file.
.UNINDENT
.INDENT 0.0
.TP
.B connection_num
A key that identifies the connection on which the request was
executed. All requests/replies that executed on the same connection
have the same value for \fBconnection_num\fP\&.
.sp
The \fBconnection_num\fP value
does \fInot\fP match the connection ID logged on the server side.
.UNINDENT
.INDENT 0.0
.TP
.B latency_us
The time difference in microseconds between when the request was
sent by the client and when a response from the server was received.
.UNINDENT
.INDENT 0.0
.TP
.B errors
Lists any errors returned from the server.
.UNINDENT
.INDENT 0.0
.TP
.B msg
Lists the error message returned from the server.
.UNINDENT
.INDENT 0.0
.TP
.B seen
The time at which the operation was originally captured.
.UNINDENT
.INDENT 0.0
.TP
.B request_id
The ID of the MongoDB operation. The \fBrequest_id\fP for a request
operation is the same as the \fBresponse_id\fP for the corresponding
reply.
.UNINDENT
.SS Output Formatting with \fB\-\-format\fP
.sp
\fI\%monitor\fP and \fI\%play\fP output to either the
terminal or, when run with \fB\-\-report\fP (i.e. \fI\%monitor \-\-report\fP or \fI\%play \-\-report\fP), to a file.
.sp
Use the \fB\-\-collect\fP (\fI\%monitor \-\-collect\fP or \fI\%play \-\-collect\fP)
option to specify the format of the output:
.INDENT 0.0
.IP \(bu 2
\fB\-\-collect json\fP produces JSON output,
.IP \(bu 2
\fB\-\-collect format\fP outputs the data based on the formatting
specified by the \fB\-\-format\fP option for \fI\%monitor\fP and \fI\%play\fP .
.UNINDENT
.SH EXAMPLES
.SS Use \fI\%record\fP
.SS Capture TCP data with \fBrecord\fP
.sp
To create a recording of traffic, use the \fI\%record\fP command. The
following operation records traffic through port \fB27017\fP on the
\fBeth0\fP network interface and writes the captured traffic to
\fB~/recordings/recording.bson\fP:
.INDENT 0.0
.INDENT 3.5
.sp
.nf
.ft C
mongoreplay record \-i eth0 \-e "port 27017" \-p ~/recordings/recording.bson
.ft P
.fi
.UNINDENT
.UNINDENT
.sp
The produced playback file contains everything needed to re\-execute
the workload on another system.
.SS Record a Playback File from Existing pcap Data
.sp
If you do not wish to use \fI\%mongoreplay\fP to capture traffic, you
can capture traffic using a utility such as \fBtcpdump\fP and then create a
\fI\%mongoreplay\fP recording from the static pcap file.
.sp
\fBWARNING:\fP
.INDENT 0.0
.INDENT 3.5
Only use root privileges when connecting to a trusted source.
.UNINDENT
.UNINDENT
.sp
The following operation uses \fBtcpdump\fP to capture traffic through
port \fB27017\fP on the \fBeth0\fP network interface and writes the captured
data to a pcap file called \fBtraffic.pcap\fP:
.INDENT 0.0
.INDENT 3.5
.sp
.nf
.ft C
sudo tcpdump \-B $((100*1024)) \-i eth0 \-n "port 27017" \-w traffic.pcap
.ft P
.fi
.UNINDENT
.UNINDENT
.sp
To create the \fI\%mongoreplay\fP playback file, you can use
\fI\%record\fP with the \fI\%\-f\fP
option to specify the pcap file from which to create the playback file,
as in the following:
.INDENT 0.0
.INDENT 3.5
.sp
.nf
.ft C
mongoreplay record \-f traffic.pcap \-p ~/recordings/playback.bson
.ft P
.fi
.UNINDENT
.UNINDENT
.sp
The produced playback file contains everything needed to re\-execute
the workload on another system.
.SS Use \fI\%play\fP
.SS Execute a Playback File Against a Target Host
.sp
\fI\%play\fP takes a playback file and executes the
recorded operations against the \fBmongodb://example.com:27018\fP host.
Since the \fBmongod\fP enforces authentication, the
connection string specified to
\fI\%\-\-host\fP also includes the username, password, and authentication
database so that \fI\%mongoreplay\fP can write to the database.
.INDENT 0.0
.INDENT 3.5
.sp
.nf
.ft C
mongoreplay play \-p ~/recordings/recording.bson \-\-host mongodb://username:password@example.com:27018/admin
.ft P
.fi
.UNINDENT
.UNINDENT
.sp
By default, \fB~bin.play\fP executes the playback
file at the rate of the recording. \fI\%\-\-speed\fP lets you modify
the playback speed. For example, the following operation executes
the operations in \fBrecording.bson\fP at twice the recording speed:
.INDENT 0.0
.INDENT 3.5
.sp
.nf
.ft C
mongoreplay play \-p ~/recordings/recording.bson \-\-speed=2.0 \-\-host mongodb://username:password@example.com:27018/admin
.ft P
.fi
.UNINDENT
.UNINDENT
.SS Log Metrics About Execution Performance during Playback
.sp
\fI\%play\fP can produce a report with detailed metrics
about the performance of each operation executed during playback.
.sp
The following example executes playback against the
\fBmongodb://example.com:27017\fP host and produces a JSON report written to
\fB~/reports/playback\-report.json\fP
.INDENT 0.0
.INDENT 3.5
.sp
.nf
.ft C
mongoreplay play \-p ~/recordings/recording.bson \-\-report ~/reports/playback\-report.json \-\-collect json \-\-host mongodb://example.com:27017
.ft P
.fi
.UNINDENT
.UNINDENT
.sp
The \fBplay\fP report contents would resemble:
.INDENT 0.0
.INDENT 3.5
.sp
.nf
.ft C
{
   "order" : 0,
   "op" : "op_msg",
   "command" : "isMaster",
   "ns" : "test",
   "request_data" : {
      "sections" : [
         {
            "payload" : {
               "$db" : "test",
               "forShell" : 1,
               "isMaster" : 1
            },
            "payloadType" : 0
         }
      ]
   },
   "reply_data" : {
      "sections" : [
         {
            "payload" : {
               "ismaster" : true,
               "localTime" : {
                  "$date" : "2018\-11\-15T21:35:01.843Z"
               },
               "logicalSessionTimeoutMinutes" : 30,
               "maxBsonObjectSize" : 16777216,
               "maxMessageSizeBytes" : 48000000,
               "maxWireVersion" : 7,
               "maxWriteBatchSize" : 100000,
               "minWireVersion" : 0,
               "ok" : 1,
               "readOnly" : false
            },
            "payloadType" : 0
         }
      ]
   },
   "played_at" : "2018\-11\-15T16:35:01.84304\-05:00",
   "play_at" : "2018\-11\-15T16:35:01.842903\-05:00",
   "playbacklag_us" : 137,
   "connection_num" : 1,
   "latency_us" : 151,
   "seen" : "2018\-11\-15T21:30:33.379675Z",
   "request_id" : 21
}
{
   "order" : 2,
   "op" : "op_msg",
   "command" : "listCollections",
   "ns" : "test",
   "request_data" : {
      "sections" : [
         {
            "payload" : {
               "$db" : "test",
               "authorizedCollections" : true,
               "filter" : {

               },
               "listCollections" : 1,
               "lsid" : {
                  "id" : {
                     "$binary" : "esmcqhiXSIWSpKGb4sOekw==",
                     "$type" : "04"
                  }
               },
               "nameOnly" : true
            },
            "payloadType" : 0
         }
      ]
   },
   "reply_data" : {
      "sections" : [
         {
            "payload" : {
               "cursor" : {
                  "firstBatch" : [ ],
                  "id" : {
                     "$numberLong" : "0"
                  },
                  "ns" : "test.$cmd.listCollections"
               },
               "ok" : 1
            },
            "payloadType" : 0
         }
      ]
   },
   "played_at" : "2018\-11\-15T16:35:08.715002\-05:00",
   "play_at" : "2018\-11\-15T16:35:08.713539\-05:00",
   "playbacklag_us" : 1463,
   "connection_num" : 1,
   "latency_us" : 331,
   "seen" : "2018\-11\-15T21:30:40.250311Z",
   "request_id" : 22
}
{
   "order" : 4,
   "op" : "op_msg",
   "command" : "isMaster",
   "ns" : "test",
   "request_data" : {
      "sections" : [
         {
            "payload" : {
               "$db" : "test",
               "forShell" : 1,
               "isMaster" : 1
            },
            "payloadType" : 0
         }
      ]
   },
   "reply_data" : {
      "sections" : [
         {
            "payload" : {
               "ismaster" : true,
               "localTime" : {
                  "$date" : "2018\-11\-15T21:35:08.715Z"
               },
               "logicalSessionTimeoutMinutes" : 30,
               "maxBsonObjectSize" : 16777216,
               "maxMessageSizeBytes" : 48000000,
               "maxWireVersion" : 7,
               "maxWriteBatchSize" : 100000,
               "minWireVersion" : 0,
               "ok" : 1,
               "readOnly" : false
            },
            "payloadType" : 0
         }
      ]
   },
   "played_at" : "2018\-11\-15T16:35:08.715554\-05:00",
   "play_at" : "2018\-11\-15T16:35:08.71471\-05:00",
   "playbacklag_us" : 844,
   "connection_num" : 1,
   "latency_us" : 208,
   "seen" : "2018\-11\-15T21:30:40.251482Z",
   "request_id" : 23
}
.ft P
.fi
.UNINDENT
.UNINDENT
.sp
Refer to \fI\%mongoreplay Report Format\fP for a description of each field.
.SS Use \fI\%monitor\fP
.SS Inspect Recorded Operations
.sp
\fI\%monitor\fP can create a report based on the
contents of a playback file. \fI\%monitor\fP\(aqs report includes
\fIall\fP operations and some metadata about each operation\(aqs execution.
.sp
The following operation uses \fI\%monitor\fP to create a JSON
report based on the contents of the \fBrecording.bson\fP playback file
located in the \fB~/recordings\fP directory and write the report to
\fB~/reports/monitoring\-report.json\fP:
.INDENT 0.0
.INDENT 3.5
.sp
.nf
.ft C
mongoreplay monitor \-p ~/recordings/recording.bson \-\-report ~/reports/monitoring\-report.json \-\-collect json
.ft P
.fi
.UNINDENT
.UNINDENT
.sp
The report contents would resemble:
.INDENT 0.0
.INDENT 3.5
.sp
.nf
.ft C
{
   "order" : 0,
   "op" : "op_msg",
   "command" : "isMaster",
   "ns" : "test",
   "request_data" : {
      "sections" : [
         {
            "payload" : {
               "$db" : "test",
               "forShell" : 1,
               "isMaster" : 1
            },
            "payloadType" : 0
         }
      ]
   },
   "connection_num" : 0,
   "seen" : "2018\-11\-15T21:30:33.379675Z",
   "request_id" : 21
}
{
   "order" : 1,
   "op" : "op_msg",
   "command" : "aggregate",
   "ns" : "test",
   "request_data" : {
      "sections" : [
         {
            "payload" : {
               "$db" : "test",
               "aggregate" : "restaurants",
               "cursor" : {

               },
               "lsid" : {
                  "id" : {
                     "$binary" : "esmcqhiXSIWSpKGb4sOekw==",
                     "$type" : "04"
                  }
               },
               "pipeline" : [
                  {
                     "$match" : {
                        "borough" : "Manhattan"
                     }
                  },
                  {
                     "$group" : {
                        "_id" : "$cuisine"
                     }
                  }
               ]
            },
            "payloadType" : 0
         }
      ]
   },
   "connection_num" : 0,
   "seen" : "2018\-11\-15T16:28:52.870007\-05:00",
   "request_id" : 13
}
{
   "order" : 1,
   "op" : "op_msg",
   "command" : "reply",
   "reply_data" : {
      "sections" : [
         {
            "payload" : {
               "ismaster" : true,
               "localTime" : {
                  "$date" : "2018\-11\-15T21:30:33.379Z"
               },
               "logicalSessionTimeoutMinutes" : 30,
               "maxBsonObjectSize" : 16777216,
               "maxMessageSizeBytes" : 48000000,
               "maxWireVersion" : 7,
               "maxWriteBatchSize" : 100000,
               "minWireVersion" : 0,
               "ok" : 1,
               "readOnly" : false
            },
            "payloadType" : 0
         }
      ]
   },
   "connection_num" : 0,
   "latency_us" : 174,
   "seen" : "2018\-11\-15T21:30:33.379849Z",
   "request_id" : 21
}
{
   "order" : 2,
   "op" : "op_msg",
   "command" : "listCollections",
   "ns" : "test",
   "request_data" : {
      "sections" : [
         {
            "payload" : {
               "$db" : "test",
               "authorizedCollections" : true,
               "filter" : {

               },
               "listCollections" : 1,
               "lsid" : {
                  "id" : {
                     "$binary" : "esmcqhiXSIWSpKGb4sOekw==",
                     "$type" : "04"
                  }
               },
               "nameOnly" : true
            },
            "payloadType" : 0
         }
      ]
   },
   "connection_num" : 0,
   "seen" : "2018\-11\-15T21:30:40.250311Z",
   "request_id" : 22
}
.ft P
.fi
.UNINDENT
.UNINDENT
.sp
Refer to \fI\%mongoreplay Report Format\fP for a description of each field.
.SS Inspect Live MongoDB Traffic
.sp
\fI\%monitor\fP can also inspect live traffic and, optionally,
create a report based on the observed operations.
.sp
To monitor traffic in real time in your terminal, omit the
\fI\%\-\-report\fP option, as in the
following:
.INDENT 0.0
.INDENT 3.5
.sp
.nf
.ft C
mongoreplay monitor \-i eth0 \-e \(aqport 27017\(aq \-\-collect json
.ft P
.fi
.UNINDENT
.UNINDENT
.sp
Optionally, you can create a report based on the operations observed
using \fI\%monitor\fP\&. The following example creates a JSON
report written to \fB~/reports/monitor\-live.json\fP based on the traffic
through port \fB27017\fP on the \fBeth0\fP network interface:
.INDENT 0.0
.INDENT 3.5
.sp
.nf
.ft C
mongoreplay monitor \-i eth0 \-e \(aqport 27017\(aq \-\-report ~/reports/monitor\-live.json \-\-collect json
.ft P
.fi
.UNINDENT
.UNINDENT
.SH AUTHOR
MongoDB Documentation Project
.SH COPYRIGHT
2008-2019
.\" Generated by docutils manpage writer.
.