-
Notifications
You must be signed in to change notification settings - Fork 16
/
cloudwatch_metrics.aws.txt
1003 lines (788 loc) · 52.9 KB
/
cloudwatch_metrics.aws.txt
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
CLOUDWATCH METRICS
VERSION ==> #2023-12-12
SUMMARY ==> #Metric: name, namespace, dimensions
#Managed metrics: usage, quota
#Metric data: single|histogram|aggregation, unit, timestamp, resolution
#Simple query: time, aggregation, labels
#Insight query: SQL-like, aggregation, dimensions filtering|grouping, sorting, slicing
#Math query: math, undefined, time fields, bool logic
#Search query: name|namespace|dimensions, tokenize, partial match, bool logic
#Connectors: custom, CSV, RDS, Prometheus, OpenSearch
#Aggregation: period, min|max, avg|sum|count, percentile [rank], outliers
#Stream: Kinesis Firehose, all|filtered metrics, aggregation
#Embedded metrics: logs, format, Node library, Lambda|EC2|ECS metadata
/=+===============================+=\
/ : : \
)==: API :==(
\ :_______________________________: /
\=+===============================+=/
SERVICE_DOMAIN #'monitoring.amazonaws.com'
FORMAT ==> #Request: query parameter, with ?Action and ?Version, and ARR.members.NUM
#Response: XML
REQ_ID #RES.ResponseMetadata.RequestId
PAGINATION ==> #Req:
# - NextToken STR
# - MaxResults NUM (def: 100, max: 500)
# - except GetMetricData(): MaxDatapoints NUM (def: 1e5), based on METRIC_DATA_RES.Values length
#Res: NextToken STR
THROTTLING ==> #ListMetrics(): 25/s (flexible)
#PutMetricData(): 500/s (flexible)
#GetMetricData():
# - 50 calls/s (flexible)
# - 10 calls/s if INSIGHT_QUERY
# - 4e5 DATAPOINT/s
# - twice less for DATAPOINTs in last 3h
# - 10 times more if INSIGHT_QUERY
#GetMetricStatistics(): 400/s (flexible)
PRICING ==> #METRIC: 1$/3.33 custom METRICs
# - 3x cheaper after 1e4, 6x after 2.5e5, 15x after 1e6
#API calls: 1$/1e5 calls
# - free: 1e6 calls/month
# - GetMetricData():
# - multiplied by numbers of METRICs requested
# - never free
#AWS managed METRICs: free
# - only 10 free with high-Resolution
#METRIC_STREAM: 1$/3e5 METRIC updates
# - multiplied by each 5 AdditionalStatistics
# - also cost of Kinesis
CloudWatchFullAccessV2 #AWS managed POLICY. Grants all CloudWatch PACTIONs: Metrics, Alarms, Dashboard, Logs, Observability
CloudWatchReadOnlyAccess #Same but readonly
/=+===============================+=\
/ : : \
)==: METRIC :==(
\ :_______________________________: /
\=+===============================+=/
ListMetrics() #Req: METRIC_LIST_REQ
#Res: METRIC_LIST
METRIC_LIST_REQ.MetricName
METRIC_LIST_REQ.Namespace
METRIC_LIST_REQ.Dimensions #METRIC.*
METRIC_LIST.Metrics #METRIC_ARR
METRIC #Timeseries, usually (but not necessarily):
# - about a AWS resource
# - measuring performance or availability (e.g. CPU usage)
#Not logged with CloudTrail
METRIC.MetricName #'METRIC'
METRIC.Namespace #Prefixes 'METRIC', similar to a NAMEPATH
METRIC.Dimensions #DIMENSION_ARR
DIMENSION #Part of identifier, like MetricName|Namespace but:
# - has key + value
# - can have multiple
#Cannot be omitted when identifying METRIC unless:
# - no other matching METRIC, i.e. no ambiguity
# - managed METRIC from some specific SERVICEs, like EC2
#Max 30 per METRIC
DIMENSION.Name #'DVAR'
DIMENSION.Value #'DVAL'
METRIC_LIST_REQ.RecentlyActive #Only METRICs with at least one METRIC_DATUM in last:
# - default: 2 weeks
# - 'PT3H': 3h
/=+===============================+=\
/ : : \
)==: METRIC CDK :==(
\ :_______________________________: /
\=+===============================+=/
new Metric(OPTS) #CMETRIC. METRIC, with also related METRIC_DATUM.* (PERIOD, unit) and WIDGET info (label, color, account, region)
#Is not a CSRESOURCE, not even a CONSTRUCT, i.e. does not create a RESOURCE
#Instead, it is only used to simplify passing METRIC OBJs as arguments, e.g. to CloudWatch Alarms|Dashboard
CMETRIC.with(OPTS)->CMETRIC2 #
CKRESOURCE.metric #Like new Metric(OPTS) but already fills OPTS.namespace|dimensionsMap|account|region
('METRIC'[, OPTS])->CMETRIC #For most CKRESOURCEs with METRICs
CKRESOURCE.metricMETRIC
(OPTS)->CMETRIC #Same but also fills OPTS.metricName|statistic
SERVICEMetrics.METRICSTAT #Underlying method used by CKRESOURCE.metricMETRIC()
(DOBJ)->CMETRIC_OPTS #Returns CMETRIC_OPTS.namespace|metricName|statistic
#If DOBJ, also returns OPTS.dimensionsMap DOBJ
#Automatically generated for each AWS managed metrics
# - i.e. can be used for METRICs not available as CKRESOURCE.metricMETRIC(),
# which is manually generated instead
OPTS|CMETRIC[_STAT].metricName
OPTS|CMETRIC[_STAT].namespace #METRIC.*
OPTS.dimensionsMap
CMETRIC.dimensions #DOBJ
CMETRIC_STAT.dims #DIMENSION_ARR: name 'DVAR', value 'DVAL'
OPTS|CMETRIC[_STAT].account #'ACCOUNT_ID', e.g. used in WIDGETs
OPTS|CMETRIC[_STAT].region #'REGION', e.g. used in WIDGETs
CMETRIC.attachTo
(CONSTRUCT)->CMETRIC2 #Set CMETRIC.account|region using CONTRUCT's CSTACK (unless agnostic)
new XW.cloudwatch.Metric ##XMETRIC. Similar to CMETRIC but for Pulumi
(OBJ[, REZ]) ##Combines METRIC|METRIC_DATUM|METRIC_ALARM|WOPTS, only their most used RPROPs.
##Only in code: does not provision anything.
##OBJ:
## - name|namespace|dimensions: like METRIC.*
## - unit: like METRIC_DATUM.*
## - period|statistic|extendedStatistic: like METRIC_ALARM.*
## - color|label|visible|yAxis: like WOPTS.*
XMETRIC.KEY ##From OBJ.KEY, after defaults and validation
XMETRIC.withKEY(VAL)->XMETRIC ##Adds|merges XMETRIC.KEY VAL
XMETRIC.with(OBJ)->XMETRIC ##Same with multiple ones
XMETRIC.resource ##REZ, used as ROPTS.parent when creating METRIC_ALARM
XW.SERVICE.metrics.METRIC ##With Pulumi, exposed by many SERVICEs.
(OBJ)->XMETRIC ##Wraps new XW.cloudwatch.Metric(OBJ), but with a given name|namespace|dimensions|unit
##Not documented yet
/=+===============================+=\
/ : : \
)==: MANAGED :==(
\ :_______________________________: /
\=+===============================+=/
AWS MANAGED METRICS ==> #Metrics automatically sent by many AWS SERVICEs
CUSTOM METRICS ==> #Non-AWS managed METRIC
AWS/SERVICE #Namespace for most managed METRICs
#Usually high timestamp resolution
AWS/Usage #Namespace for managed METRICs related to resource usage when limited by a quota
SERVICE_QUOTA(ARR) #MATH_QUERY function returning ARR2. Quotas for a given resource.
#ARR must be from a AWS/Usage/* METRIC
AWS/Usage/CallCount #METRIC with resource usage
#DVARs:
# - Service 'SERVICE'
# - Type 'API', Resource 'ACTION'
# - Type 'Resource', Resource 'ARN'
# - Class STR
/=+===============================+=\
/ : : \
)==: AGGREGATION :==(
\ :_______________________________: /
\=+===============================+=/
ISTAT #MIN|MAX|AVG|SUM|COUNT
#Used by INSIGHT_QUERY and DEXPLORER.aggregateBy
ASTAT #Same but called Minimum, Maximum, Average, Sum, SampleCount
#Used by AGGR_QUERY_REQ|METRIC_ALARM.Statistics, SIMPLE_QUERY.Stat
NSTAT #Like ASTAT, but no Average
#Used by METRIC_DATUM.StatisticValues
EXTENDED STATISTICS ==> #ESTAT|XSTAT cannot be used when DATAPOINTs:
# - are not single|discrete, i.e. were added by METRIC_DATUM.Values|StatisticValues
# - are negative
ESTAT #'pNUM' (percentile)
#Used by AGGR_QUERY_REQ|METRIC_ALARM.ExtendedStatistics
XSTAT #ASTAT, ESTAT or one of:
# - 'pNUM': percentile
# - TM(RANGE):
# - like Average but without outliers outside RANGE
# - "trimmed mean"
# - IQM:
# - same as TM(25%:75%)
# - "inter-quartile mean"
# - WM(RANGE):
# - like Average but outliers outside RANGE are clamped to min|max non-outliers
# - "Winsorized mean"
# - TC(RANGE):
# - like SampleCount but without outliers outside RANGE
# - "trimmed count"
# - TS(RANGE):
# - like Sum but without outliers outside RANGE
# - "trimmed sum"
# - PR(RANGE):
# - percentage of values within RANGE
# - "percentile rank"
# - tm|vm|tc|ts|prNUM: same as TM|VM|TC|TS|PR(:NUM%)
#Used by METRIC_STREAM AdditionalStatistics, ${PROP('Stat')}, SEARCH(),
#ANOMALY_DETECTOR.SingleMetricAnomalyDetector, DEXPLORER, WIDGET
RANGE #[NUM[%]]:[NUM2[%]]
#Targets only values >NUM (def: min) and <=NUM2 (def: max)
#If %, use percentiles instead
UNDEFINED ==> #A PERIOD with no METRIC_DATUM is aggregated to undefined
#Also called "missing value"
/=+===============================+=\
/ : : \
)==: AGGREGATION CDK :==(
\ :_______________________________: /
\=+===============================+=/
Stats.MINIMUM|MAXIMUM|AVERAGE|SUM
|SAMPLE_COUNT #'ASTAT'
Stats.IQM #'IQM'
Stats.percentile|p(NUM)->'pNUM' #
Stats.trimmedMean|tm(NUM)->'tmNUM'#
Stats.trimmedMean|tm
(NUM, NUM2)->'TM(NUM%:NUM2%)' #
Stats.winsorizedMean|wm(...)->STR
Stats.trimmedCount|tc(...)->STR
Stats.trimmedSum|ts(...)->STR
Stats.percentileRank|pr(...)->STR #Same
/=+===============================+=\
/ : : \
)==: DATA PUT :==(
\ :_______________________________: /
\=+===============================+=/
PutMetricData() #Req: METRIC_DATA
#Res: empty
METRIC_DATA.MetricData #METRIC_DATUM_ARR
#Max 1e3, 1MB
#Not logged with CloudTrail
METRIC_DATUM #1|n DATAPOINTs
#If METRIC does not exist, creates it.
#Kept for 15 months
DATAPOINT #Single value of a METRIC
#1 datapoint with METRIC_DATUM.Value, multiple with METRIC_DATUM.Values|StatisticValues
#To minimize number of requests, prefer the later, on a regular PERIOD
METRIC_DATUM.MetricName
METRIC_DATA.Namespace
METRIC_DATUM.Dimensions #METRIC.*
COND_KEY cloudwatch:namespace #METRIC_DATA.Namespace. Only with PutMetricData()
METRIC_DATUM.Value #NUM. Single DATAPOINT
METRIC_DATUM.Values|Counts #NUM_ARR. Multiple DATAPOINTs, as histogram
#Max 150
METRIC_DATUM.StatisticValues.NSTAT#NUM. Multiple DATAPOINTs, as aggregation
METRIC_DATUM.Unit #One of:
# - "[Micro|Milli]Seconds"
# - "Percent"
# - "Count[/Second]"
# - "[Kilo|Mega|Giga|Tera]bits|bytes[/Second]"
# - "None"
METRIC_DATUM.Timestamp #DATE_NUM (def: now)
#If >3h|24h ago, can take 2h|48h to show up
#Min: 2 weeks earlier, max: 2h later
METRIC_DATUM.StorageResolution #NUM of secs to round Timestamp.
#Either 1s ("high") or 1m (def, "regular")
RESOLUTION #Timestamp rounding degrades with time:
# - before 3h: StorageResolution
# - after 3h: 1m
# - after 15d: 5m
# - after 63d: 1h
ENVVAR
AWS_DISABLE_REQUEST_COMPRESSION
CONFIG.disable_request_compression#If true (def), compress HTTP request body with PutMetricData()
COPTS.disableRequestCompression #Uses Content-Encoding: gzip [C]
ENVVAR AWS_REQUEST_
MIN_COMPRESSION_SIZE_BYTES
CONFIG.request_
min_compression_size_bytes
COPTS
.requestMinCompressionSizeBytes #NUM (def: 10KB, min: 0, max: 10MB). Do not compress if lower
/=+===============================+=\
/ : : \
)==: DATA PUT CDK :==(
\ :_______________________________: /
\=+===============================+=/
CMETRIC_OPTS.statistic #'XSTAT' (def: 'Average')
#Can be case-insensitive
CMETRIC[_STAT].statistic #Same but case-normalized. Also, if ISTAT -> ASTAT instead
CMETRIC[_OPTS].unit
CMETRIC_STAT.unitFilter #STR. METRIC_DATUM.Unit
CMETRIC[_OPTS|STAT].period #DURATION (def: 5m). PERIOD
Metric.grantPutMetricData
(YGRANTABLE)->CGRANT #Allow cloudwatch:PutMetricData on any RESOURCE
/=+===============================+=\
/ : : \
)==: QUERY :==(
\ :_______________________________: /
\=+===============================+=/
GetMetricData() #Req: METRIC_DATA_REQS
#Res: METRIC_DATA_RESS
METRIC_DATA_REQS.MetricDataQueries#METRIC_DATA_REQ_ARR
#Max 500
#Max 1e4 METRICs being queried
METRIC_DATA_REQ|SIMPLE_QUERY #PERIOD. NUM (in secs) (def: 1m).
.Period #Granularity of result: each PERIOD returns a single value aggregating multiple DATAPOINTs
#Must be a multiple of RESOLUTION
# - if RESOLUTION 1s, must be 1|5|10|30
#Max: 1 day
METRIC_DATA_REQS.StartTime #Matching METRIC_DATUM.Timestamp. Inclusive.
#Rounded by PERIOD
#Must be within last 3h if there is a INSIGHT_QUERY
METRIC_DATA_REQS.EndTime #Matching METRIC_DATUM.Timestamp. Exclusive.
#Rounded by PERIOD
METRIC_DATA_REQS.ScanBy #'TimestampDescending|TimestampAscending'. Sorting order
METRIC_DATA_REQ.MetricStat #SIMPLE_QUERY
#Returns a single METRIC_DATA_RES
SIMPLE_QUERY.Metric #METRIC
SIMPLE_QUERY.Stat #ASTAT applied on each PERIOD
SIMPLE_QUERY.Unit #Filter by METRIC_DATUM.Unit. Does not try to convert
METRIC_DATA_REQ.Expression #'INSIGHT_QUERY|MATH_QUERY'. Advanced query
#Cannot be used together with METRIC_DATA_REQ.MetricStat
#Max 1 INSIGHT_QUERY per METRIC_DATA_REQS
METRIC_DATA_RESS.MetricDataResults#METRIC_DATA_RES_ARR
METRIC_DATA_RES #1 METRIC_DATA_REQ -> 1|n METRIC_DATA_RES depending on SIMPLE_QUERY|INSIGHT_QUERY|MATH_QUERY
METRIC_DATA_REQ|RES.Id #'MVAR'
#Either lowercase_underscored or camelCase
METRIC_DATA_RES.Values #NUM_ARR. Each response value
METRIC_DATA_RES.Timestamps #DATE_NUM_ARR. Same length as Values
METRIC_DATA_REQ.ReturnData #BOOL (def: true).
#If false, do not any return METRIC_DATA_RES, i.e. only used as input of another METRIC_DATA_REQ
METRIC_DATA_RES[S].Messages #MESSAGE_DATA_ARR
MESSAGE_DATA #Error message
MESSAGE_DATA.Code #STR
MESSAGE_DATA.Value #'MESSAGE'
METRIC_DATA_RES.StatusCode #One of:
# - 'Complete': ok
# - 'PartialData': paginated
# - 'InternalError': error, but can retry
# - 'Forbidden': auth error
/=+===============================+=\
/ : : \
)==: AGGREGATION QUERY :==(
\ :_______________________________: /
\=+===============================+=/
GetMetricStatistics() #Req: AGGR_QUERY_REQ
#Res: AGGR_QUERY_RESS
AGGR_QUERY_REQ #Similar to METRIC_DATA_REQ using MetricStat, but simpler and can use ESTAT
AGGR_QUERY_RESS.Datapoints #AGGR_QUERY_RES_ARR
#Max 1440, otherwise error
AGGR_QUERY_REQ.MetricName
AGGR_QUERY_REQ.Namespace
AGGR_QUERY_REQ.Dimensions #METRIC.*
AGGR_QUERY_REQ|RES.Unit #Like SIMPLE_QUERY.*
AGGR_QUERY_REQ.Period #Like METRIC_DATA_REQ.*
#Each METRIC_DATA_RES aggregates multiple DATAPOINTs in a single PERIOD
AGGR_QUERY_REQ.StartTime|EndTime #Like METRIC_DATA_REQS.*
AGGR_QUERY_RES.Timestamp #'DATE'
AGGR_QUERY_REQ.Statistics #'ASTAT'_ARR to populate in AGGR_QUERY_RES.*
AGGR_QUERY_RES.ASTAT #NUM
AGGR_QUERY_REQ.ExtendedStatistics #'ESTAT'_ARR to populate in AGGR_QUERY_RES.ExtendedStatistics.*
#Cannot be used with AGGR_QUERY_REQ.Statistics
#Max 10
AGGR_QUERY_RES
.ExtendedStatistics.ESTAT #NUM
AGGR_QUERY_RESS.Label #STR
/=+===============================+=\
/ : : \
)==: LABELS :==(
\ :_______________________________: /
\=+===============================+=/
METRIC_DATA_REQ|RES.Label #LABEL. Description
#Def: '${LABEL}'
METRIC_DATA_REQS #'+|-NNNN'. Timezone to use in ${*TIME*}
.LabelOptions.Timezone #Def: UTC
${...} #"Dynamic label"
#Can be added to LABEL
#Computed in each METRIC_DATA_RES, based on its Values|Timestamps ARR
#Max 5 per Label
${LABEL} #Concatenates METRIC.Namespace|MetricName and DVAR|DVALs
${FIRST|LAST} #First|last value
${MIN|MAX} #
${SUM} #
${AVG} #
${DATAPOINT_COUNT} #Length
${FIRST_LAST_RANGE} #LAST - FIRST
${MIN_MAX_RANGE} #MAX - MIN
${FIRST|LAST_TIME}
${MIN|MAX_TIME}
${FIRST_LAST_TIME_RANGE}
${MIN|MAX_TIME_RANGE} #Same but with timestamps
${FIRST|LAST_TIME_RELATIVE}
${MIN|MAX_TIME_RELATIVE} #Same but with duration since timestamps
${PROP('Region')} #REGION
${PROP('MetricName')} #'METRIC'
${PROP('Namespace')} #NAMESPACE
${PROP('Dim.DVAR')} #DVAL
${PROP('Period')} #PERIOD
${PROP('Stat')} #Current 'XSTAT'
/=+===============================+=\
/ : : \
)==: LABELS CDK :==(
\ :_______________________________: /
\=+===============================+=/
ICMETRIC[_OPTS|RENDER].label #'LABEL'
CMETRIC.toString()->STR #CMETRIC.label|metricName
CMATH.toString()->STR #CMATH.label|expression
/=+===============================+=\
/ : : \
)==: INSIGHT QUERY :==(
\ :_______________________________: /
\=+===============================+=/
INSIGHT_QUERY #SQL-like expression to compute a query on METRIC_DATUMs
#Returns ARR|ARR_ARR (one|multiple METRIC_DATA_RESs) depending on whether GROUP BY is used
#Max 1e4 METRICs being matched
#Syntax follows
SELECT ISTAT(NAME) #Use METRIC with MetricName NAME and Namespace NAMESPACE
FROM NAMESPACE #Aggregate each PERIOD according to ISTAT
#NAMESPACE can also be SCHEMA(NAMESPACE[, DVAR, ...])
# - same as NAMESPACE, but only for METRICs with exact same DVAR
# - must also have same number of DVARs, including none
WHERE DVAR [!]= DVAL [AND ...] #Filter by DVAL
GROUP BY DVAR[, ...] #Splits into multiple ARRs grouped by DVAR
#Missing DVAR are named "Other"
ORDER BY ISTAT() [DESC|ASC] #Sort ARRs created by GROUP BY
#Def: ASC
LIMIT NUM #Only first NUM values
#Def|max NUM: 500
QUOTING ==> #'-quote: around DVAL
#"-quote:
# - around NAME|NAMESPACE|DVAR unless only [:alnum:]_ and not reserved word
# - reserved word: big list, documented online
#\-escape: on ' " inside ' " quote
PACTION cloudwatch:GenerateQuery #Allows generating INSIGHT_QUERYs from AI prompts in the UI
/=+===============================+=\
/ : : \
)==: MATH QUERY :==(
\ :_______________________________: /
\=+===============================+=/
MATH_QUERY #DSL to compute a query on METRIC_DATUMs
#While INSIGHT_QUERY is more focused on filtering|grouping|sorting|slicing,
#MATH_QUERY is more focused on transforming and combining multiple METRICs|INSIGHT_QUERY
#Return value must be either:
# - ARR: one METRIC_DATA_RES
# - ARR_ARR: multiple METRIC_DATA_RESs
MVAR #ARR. METRIC_DATA_RES with matching Id
mNUM #ARR. METRIC_DATA_RES number NUM
METRICS([STR]) #ARR_ARR. All METRIC_DATA_RESs, except ones using MATH_QUERY
#If STR, only ones with MVAR including STR
METRIC_COUNT(ARR_ARR) #NUM. ARR_ARR.length
[NUM,...] #ARR
[ARR,...] #ARR_ARR
[ARR_ARR,...] #Concatenated ARR_ARR
VAL #NUM, ARR or ARR_ARR
BOOL #Actually 0|1
UNDEFINED ==> #Converted to 0
#If division by 0, VAL ignored
VAL + - * / ^ VAL2 #VAL3
-VAL #VAL2
VAL == != <= >= < > VAL2 #VAL3
VAL && || VAL2 #VAL3
VAL AND OR VAL2 #Same
FIRST|LAST(ARR) #NUM
ABS(VAL) #VAL2
CEIL(VAL) #VAL2
FLOOR(VAL) #VAL2
LOG[10](VAL) #VAL2
MIN|MAX(ARR|ARR_ARR) #VAL|ARR
SUM(ARR|ARR_ARR) #VAL|ARR
AVG(ARR|ARR_ARR) #VAL|ARR
STDDEV(ARR|ARR_ARR) #VAL|ARR
DATAPOINT_COUNT(ARR|ARR_ARR) #VAL|ARR. Length, after ARR_ARR flattening, excluding undefined
DIFF(ARR|ARR_ARR) #ARR|ARR_ARR. Difference with previous value.
DIFF_TIME(ARR|ARR_ARR) #ARR|ARR_ARR. Difference with previous timestamp (in secs)
RATE(ARR|ARR_ARR) #ARR|ARR_ARR. Difference with previous value, divided by difference between timestamps (in secs)
RUNNING_SUM(ARR|ARR_ARR) #ARR|ARR_ARR. Sum with all previous values
TIME_SERIES(NUM) #ARR of repeated value NUM
FILL(ARR|ARR_ARR, FILLER) #ARR|ARR_ARR, but fills undefined according to FILLER:
# - NUM: repeated value
# - ARR: serial value
# - REPEAT: last non-undefined value
# - LINEAR: interpolation between last|next non-undefined value
SLICE(ARR_ARR, NUM[, NUM2]) #ARR_ARR, but only from index NUM (inclusive) to NUM2 (exclusive, def: end)
REMOVE_EMPTY(ARR_ARR) #ARR_ARR, but without ARR of length 0
SORT(ARR_ARR, FUNC,ASC|DESC[,NUM])#ARR_ARR, but sorted.
#Sort using each FUNC(ARR) as key, with FUNC being MIN|MAX|SUM|AVG
#If NUM, truncates to NUM values
PERIOD(ARR) #NUM. PERIOD
EPOCH(ARR) #ARR2. Timestamps of ARR, but converted to DATE_NUM
MINUTE(ARR) #ARR2. Timestamps of ARR, but only with the minute
HOUR(ARR) #Same with hour
DAY(ARR) #Same with day of the week
DATE(ARR) #Same with day of the month
MONTH(ARR) #Same with month
YEAR(ARR) #Same with year
IF(BOOL[_ARR],NUM|ARR[,NUM2|ARR2])#ARR3 with each element:
# - taken either from NUM|ARR or NUM2|ARR2
# - depending on BOOL[_ARR]
#If some values are ARR and not others, scalar values are repeated
#undefined in:
# - BOOL_ARR -> undefined
# - NUM|ARR -> 0
# - NUM2|ARR2 -> undefined
#Def NUM2: undefined
#Def ARR2: empty
/=+===============================+=\
/ : : \
)==: MATH QUERY CDK :==(
\ :_______________________________: /
\=+===============================+=/
new MathExpression(OPTS) #CMATH. MATH_QUERY, with some related information (PERIOD, account|region, WIDGET label|color)
#Like CMETRIC, is not a CONSTRUCT nor provisioned, but only meant as a helper to pass to other SERVICEs
CMATH.with(OPTS)->CMATH2 #
ICMETRIC #CMETRIC|CMATH
CMETRIC.toMetricConfig()->OBJ #Different shape OBJ: metricStat CMETRIC_STAT, renderingProperties CMETRIC_RENDER
#Meant to abstract difference between CMETRIC and CMATH
CMATH.toMetricConfig()->OBJ #Different shape OBJ: mathExpression CMATH_STAT, renderingProperties CMATH_RENDER
OPTS|CMATH[_STAT].expression #'MATH_QUERY'
OPTS|CMATH[_STAT]
.usingMetrics.METRIC #ICMETRIC. Each return value, i.e. each METRIC_DATA_RES
OPTS|CMATH[_STAT].period #DURATION (def: 5m). PERIOD
#Set to CMATH.usingMetrics.METRIC
OPTS|CMATH[_STAT].searchAccount #'ACCOUNT_ID', e.g. used in WIDGETs
OPTS|CMATH[_STAT].searchRegion #'REGION', e.g. used in WIDGETs
/=+===============================+=\
/ : : \
)==: SEARCH QUERY :==(
\ :_______________________________: /
\=+===============================+=/
SEARCH('QUERY', 'XSTAT') #MATH_QUERY function returning ARR_ARR: METRICs mathing QUERY
#QUERY: '[FILTERS] [TERMS]'
#FILTERS: {NAMESPACE[, DVAR, ...]}
# - NAMESPACE: only METRICs with that Namespace
# - DVAR:
# - group METRICs by DVAL
# - STAT is applied on those groups
# - ignore METRICs without that DVAR
#TERMS: list of TERM separated by:
# - space: same as AND
# - AND|OR|NOT
# - parenthesis
#TERM: [TYPE=]["]...["]
# - include only METRICs with a matching MetricName|Namespace|DVAR|DVAL
# - unless "-quote:
# - partial match
# - tokenize with punctuation and camelCase
# - case insensitive, but only after tokenization
# - e.g. oneTwo -> oneTwo OR (one AND two)
# - oneTwo case-sensitive, one|two case-insensitive
# - can also use AND|OR|NOT|parenthesis in the value, e.g. TYPE = ("..." OR "...")
#TYPE: value type among:
# - MetricName
# - Namespace
# - DVAR
#"-quote:
# - required when using spaces or non-ASCII chars
# - must \-escape " \ ( )
#Max 1e3 chars for QUERY
/=+===============================+=\
/ : : \
)==: CONNNECTOR :==(
\ :_______________________________: /
\=+===============================+=/
LAMBDA('FUNCTION[:QUALIFIER]' #MATH_QUERY function returning ARR_ARR
[, ...ARGS]) #Calls Lambda FUNC (CONNECTOR)
#Goal: METRICs using external source
LAMBDA FUNCTION ==> #InvocationType 'RequestResponse'
#Timeout 10s (4.5s if ALARM)
#Must have TAG cloudwatch:datasource 'custom'
#Must:
# - be assumable by lambda.datasource.cloudwatch.amazonaws.com
# - with COND_KEY aws:SourceAccount|SourceOrg*
REQ.EventType #Either:
# - 'GetMetricData' (DATA_REQ|RES): called by LAMBDA()
# - 'DescribeGetMetricData' (MDATA_REQ|RES): metadata
DATA_REQ.GetMetricDataRequest #DATA_REQQ
DATA_REQQ.Arguments #ARGS_ARR passed to LAMBDA(). Max 20 items
DATA_REQQ.StartTime|EndTime #DATE_NUM (in secs)
DATA_REQQ.Period #NUM (in secs, min 1m)
DATA_RES #Same as METRIC_DATA_RESS
[M]DATA_RES.Error #Same as MESSAGE_DATA
MDATA_REQ #None
MDATA_RES.DataSourceConnectorName #'NAME' to show in documentation
MDATA_RES.Description #'MARKDOWN'. Documentation
MDATA_RES.ArgumentDefaults #ARGS_ARR. Default values in UI
BUILT-IN CONNECTORS ==> #Built-in ones:
# - CSV file on S3
# - RDS (SQL)
# - Prometheus (PromQL)
# - OpenSearch Service logs|traces
# - Azure Monitor
#Created through the UI:
# - use a CloudFormation STACK provisioning Lambda FUNC, its ROLE, PERMISSION and LOG_GROUP
# - can associate a VPC
S3 CSV BUILT-IN CONNECTORS ==> #Header: Timestamp, METRIC,...
#Values: 'YYYY-MM-DDTHH:MM:SSZ', NUM,...
/=+===============================+=\
/ : : \
)==: STREAM :==(
\ :_______________________________: /
\=+===============================+=/
PutMetricStream() #Req: METRIC_STREAM
# - no Arn, CreationDate, LastUpdateDate, State
# - RoleName -> RoleArn
#Res: METRIC_STREAM
# - only Arn
StartMetricStreams() #Req: METRIC_STREAM
# - only Name -> Names
#Res: empty
#Set METRIC_STREAM.State 'running'
StopMetricStreams() #Req: METRIC_STREAM
# - only Name -> Names
#Res: empty
#Set METRIC_STREAM.State 'stopped'
GetMetricStream() #Req: METRIC_STREAM
# - only Name
#Res: METRIC_STREAM
ListMetricStreams() #Req: empty
#Res: Entries METRIC_STREAM_ARR
# - no Include|ExcludeFilters, IncludeLinkedAccountsMetrics, RoleName, StatisticsConfigurations
DeleteMetricStream() #Req: METRIC_STREAM
# - only Name
#Res: empty
METRIC_STREAM #Redirect all of an ACCOUNT's METRIC_DATUMs to a Kinesis FIREHOSE
#Batch once per minute
#Can be sent out-of-order
#Not logged with CloudTrail
METRIC_STREAM.Arn #METRIC_STREAM_ARN. 'arn:aws:cloudwatch:REGION:ACCOUNT_ID:metric-stream/METRIC_STREAM'
METRIC_STREAM.Name #'METRIC_STREAM'
METRIC_STREAM.CreationDate #'DATE'
METRIC_STREAM.LastUpdateDate #'DATE'
METRIC_STREAM.FirehoseArn #FIREHOSE_ARN
METRIC_STREAM.RoleName #'ROLE' assumed by FIREHOSE
#ROLE must:
# - allow PACTIONs firehose:PutRecord[Batch]
# - have trust policy allowing Principal.Service 'streams.metrics.cloudwatch.amazonaws.com'
#Current PRINCIPAL must have iam:PassRole PACTION
METRIC_STREAM.OutputFormat #'json', 'opentelemetry0.7' or 'opentelemetry1.0'
#See online doc for specific format
METRIC_STREAM.State #'running' (def) or 'stopped'
METRIC_STREAM #METRIC_STREAM_FILTER_ARR
.Include|ExcludeFilters #Cannot use both IncludeFilters + ExcludeFilters
#Max 1e4
METRIC_STREAM_FILTER #Include|exclude METRICs with a given NAMESPACE
METRIC_STREAM_FILTER.Namespace #NAMESPACE
METRIC_STREAM_FILTER.MetricNames #'METRIC'_ARR
METRIC_STREAM
.StatisticsConfigurations #METRIC_STREAM_STAT_ARR
METRIC_STREAM_STAT #Specify XSTATs to compute for specific METRICs
METRIC_STREAM_STAT #'XSTAT'_ARR
.AdditionalStatistics #If OutputFormat 'opentelemetry0.7', can only use 'pNUM'
#Always included: Min|Max|Sum|SampleCount
#Max 20
METRIC_STREAM_STAT.IncludeMetrics #METRIC_STREAM_METRIC_ARR
#Max 100
METRIC_STREAM_METRIC #Specific METRIC targetted by METRIC_STREAM_STAT
METRIC_STREAM_METRIC.MetricName #'METRIC'
METRIC_STREAM_METRIC.Namespace #NAMESPACE
TagResource()
ListTagsForResource()
UntagResource()
RESOURCE_TAGS.ResourceARN
RESOURCE_TAGS.Tags
METRIC_STREAM.Tags #
AWS/CloudWatch/MetricStreams/* #METRICs sent for METRIC_STREAM itself, with following names
#DVAR: MetricStreamName 'METRIC_STREAM'
MetricUpdate #NUM of METRIC_DATUMs updates
TotalMetricUpdate #MetricUpdate + NUM of group of 5 AdditionalStatistics
PublishErrorRate #NUM% of unrecoverable errors sending to the FIREHOSE
QUICK SETUP ==> #In UI, sets up additional RESOURCEs to redirect from Kinesis to:
# - S3
# - third-party (Datadog, New Relic, Dynatrace, Splunk, SumoLogic)
AWS::CloudWatch::MetricStream #RESPROPs: Name, FirehoseArn, RoleArn ROLE_ARN, OutputFormat, IncludeFilters,
#IncludeLinkedAccountsMetrics, ExcludeFilters, StatisticsConfigurations, Tags
#RESATTRs: Arn, CreationDate, LastUpdateDate, State
/=+===============================+=\
/ : : \
)==: EMBEDDED MAIN :==(
\ :_______________________________: /
\=+===============================+=/
EMBEDDED METRICS ==> #CloudWatch Logs LLEVENT, where message is 'ROOT_JSON' with following format ("EMF")
#Automatically calls PutMetricData() based on METRIC_DATA contained in log message
#Goal: combining METRIC_DATA + LLEVENT
#Difference with METRIC_FILTER: structured, i.e. producer specifies METRICs in LLEVENT directly
ROOT.* #Anything, i.e. actual message
ROOT.VARR #Can be used anywhere in ROOT._aws.** as dot-delimited 'VARR' value
ROOT._aws.Timestamp #DATE_NUM
ROOT._aws.CloudWatchMetrics #EMETRIC_META_ARR
EMETRIC_META.Namespace #'NAMESPACE'
EMETRIC_META.Dimensions #EDVARS_ARR. Each EDVARS creates a new METRIC (cartesian product)
#Max 30
EDVARS #'DVAR'_ARR
#Max 250
ROOT.DVAR #'DVAL'
EMETRIC_META.Metrics #EMETRIC_ARR
#Max 100
EMETRIC.Name #'METRIC'
ROOT.METRIC #NUM
#Can also be NUM_ARR (max 100), uses as METRIC_DATUM.Values
EMETRIC.Unit|StorageResolution #Like METRIC_DATUM.*. Optional
CLOUDWATCH AGENT ==> #TCP|UDP local daemon that forwards to CloudWatch Logs
#Used by EC2 and ECS
ROOT._aws.logGroupName #'LOG_GROUP'
ROOT._aws.logStreamName #'LOG_STREAM'
CLOUDWATCH METRICS ==> #METRICs sent for embedded metrics themselves
#DVAR: LogGroupName 'LOG_GROUP'
AWS/Logs/EMFParsingErrors #NUM of LLEVENTs using invalid format for embedded metrics
AWS/Logs/EMFValidationErrors #Same but with higher-level validation instead
/=+===============================+=\
/ : : \
)==: EMBEDDED NODE MAIN :==(
\ :_______________________________: /
\=+===============================+=/
VERSION ==> #4.1.1
#Named aws-embedded-metrics
metricScope(FUNC(MLOGGER) #FUNC3(...) calls:
->FUNC2(...)[->>VAL]) # - FUNC(createMetricsLogger())
->FUNC3(...)->>VAL # - FUNC2(...)
# - MLOGGER.flush()
createMetricsLogger()->MLOGGER #
MLOGGER.*(...)->MLOGGER #For all FUNCs, except flush()
MLOGGER.flush()->> #Send metrics
#Can only send one EMETRIC_META per flush()
#Keeps:
# - MCONTEXT.namespace
# - MCONTEXT.properties
# - DOBJ
# - if MLOGGER.flushPreserveDimensions false: only default DOBJ
# - not MCONTEXT.metrics
# - not MCONTEXT.meta (except timestamp if setTimestamp() was used)
/=+===============================+=\
/ : : \
)==: EMBEDDED NODE ENV :==(
\ :_______________________________: /
\=+===============================+=/
CONF.environmentOverride #Environment, among the following ones
ENVVAR AWS_EMF_ENVIRONMENT #Def: automatically detects Lambda|ECS|EC2, otherwise use Agent
ENV 'Local' #Send metrics with console.log('ROOT_JSON')
#If needed due to max 100 ARR items in EMETRIC_META.Metrics or ROOT.METRIC, calls console.log() multiple times
ENV 'Agent' #Send metrics to CloudWatch agent
ENV 'Lambda' #logGroupName|serviceName: 'FUNCTION'
#serviceType: 'AWS::Lambda::Function'
#Send metrics with console.log() like ENV 'Local'
ROOT.executionEnvironment #'AWS_Lambda_RUNTIME'
ROOT.memorySize #'NUM' of FUNC_VERSION.MemorySize
ROOT.functionVersion #'NUM' of FUNC_VERSION.Version
ROOT.logStreamId #'LOG_STREAM'
ROOT.traceId #ENVVAR _X_AMZN_TRACE_ID
ENV 'EC2' #serviceType: 'AWS::EC2::Instance'
#Send metrics to CloudWatch agent
ROOT.imageId|instanceId|privateIP
|instanceType|availabilityZone #Instance identity fields
ROOT._aws.* #Instance identity fields
ENV 'ECS' #logGroupName|serviceName: default to 'IMAGE'
#serviceType: 'AWS::ECS::Container'
#Send metrics to CloudWatch agent
ROOT.createdAt|startedAt|image
|cluster|taskArn #Instance identity fields
ROOT.containerId #'HOSTNAME'
ROOT._aws.FormattedImageName #'IMAGE'
/=+===============================+=\
/ : : \
)==: EMBEDDED NODE CONFIG :==(
\ :_______________________________: /
\=+===============================+=/
Configuration.VAR #CONF.VAR
#Can be manually set
CONF.serviceType #'RESTYPE'. Used as default DVAR ServiceType
ENVVAR [AWS_EMF_]SERVICE_TYPE #Def: 'Unknown'
CONF.serviceName #Resource 'NAME'. Used as default DVAR ServiceName
ENVVAR [AWS_EMF_]SERVICE_NAME #Def: 'Unknown'
CONF.logGroupName #'LOG_GROUP'. Used as default DVAR LogGroup
ENVVAR AWS_EWF_LOG_GROUP_NAME #Also set to ROOT._aws.logGroupName, if ENV ECS|EC2|Agent
#Def: 'SERVICE_NAME-metrics'
CONF.logStreamName #'LOG_STREAM_NAME'. Set to ROOT._aws.logStreamName
ENVVAR AWS_EWF_LOG_STREAM_NAME #Only for ENV EC2|Agent
CONF.agentEndpoint #'tcp|udp://HOST:PORT' of Cloudwatch agent
ENVVAR AWS_EMF_AGENT_ENDPOINT #Only if ENV ECS|EC2|Agent
#Def: 'tcp://0.0.0.0:25888'
CONF.debuggingLoggingEnabled
ENVVAR
AWS_EMF_ENABLE_DEBUG_LOGGING #BOOL (def: false). Prints debugging logs with console.log()
/=+===============================+=\
/ : : \
)==: EMBEDDED NODE METRICS :==(
\ :_______________________________: /
\=+===============================+=/
CONF.namespace
ENVVAR AWS_EWF_NAMESPACE
MCONTEXT.namespace #'NAMESPACE' (def: 'aws-embedded-metrics')
MCONTEXT|MLOGGER
.setNamespace('NAMESPACE') #
MCONTEXT|MLOGGER #Set all DOBJs. DOBJ is { DVAR: DVAL, ... }
.setDimensions(DOBJ[_ARR]) #Can only use DOBJ_ARR (not DOBJ) with MCONTEXT
MCONTEXT|MLOGGER.resetDimensions()#Same as setDimensions([])
MCONTEXT|MLOGGER #Add a new DOBJ
.putDimensions(DOBJ) #Remove existing DOBJs with exact same DVARs
MCONTEXT #Set default DOBJ
.setDefaultDimensions(DOBJ) #[re]setDimensions() (but not putDimensions()) remove default DOBJ, unless using last argument BOOL true
MCONTEXT.getDimensions()->DOBJ_ARR#
MCONTEXT.metrics #MAP where key is 'METRIC' and value is MVALUES
MVALUES.values #NUM_ARR
MVALUES.addValue(NUM) #
MVALUES.unit #'UNIT' (def: 'None')
MVALUES.storageResolution #NUM (def: 60)
MCONTEXT|MLOGGER.putMetric #NUM2 is StorageResolution
('METRIC', NUM[, 'UNIT'[, NUM2]])#If 'METRIC' already exists, appended to MVALUES.values NUM_ARR
Unit.UNIT #'UNIT'
#Same spelling, except /Second -> PerSecond
StorageResolution.High|Standard #1|60
MCONTEXT.properties #OBJ set to ROOT.*
MCONTEXT|MLOGGER
.setProperty('VAR', VAL) #