forked from aws-observability/aws-otel-collector
-
Notifications
You must be signed in to change notification settings - Fork 0
/
aws-otel-container-insights-prometheus-ec2-deployment-cfn.yaml
323 lines (317 loc) · 12.7 KB
/
aws-otel-container-insights-prometheus-ec2-deployment-cfn.yaml
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
Parameters:
ClusterName:
Type: String
Description: Enter the name of your ECS cluster from which you want to collect prometheus metrics
# IAM
CreateIAMRoles:
Type: String
Default: 'False'
AllowedValues:
- 'True'
- 'False'
Description: Create new default IAM roles or use existing ones.
ConstraintDescription: must specify True or False.
TaskRoleArn:
Type: String
Default: Default
Description: Enter the role arn you want to use as the ecs task role
ExecutionRoleArn:
Type: String
Default: Default
Description: Enter the role arn you want to use as the ecs execution role
# Collector
CollectorImage:
Type: String
Default: 'public.ecr.aws/aws-observability/aws-otel-collector:latest'
Conditions:
CreateRoles: !Equals
- !Ref CreateIAMRoles
- 'True'
DefaultTaskRole: !Equals
- !Ref TaskRoleArn
- Default
DefaultExecutionRole: !Equals
- !Ref ExecutionRoleArn
- Default
Resources:
ECSTaskDefinition:
Type: 'AWS::ECS::TaskDefinition'
Properties:
Family: !Sub 'adot-container-insights-prometheus-${ClusterName}'
TaskRoleArn: !If
- CreateRoles
- !GetAtt
- ECSTaskRole
- Arn
- !If
- DefaultTaskRole
- !Sub 'arn:aws:iam::${AWS::AccountId}:role/AWSOTelRole'
- !Ref TaskRoleArn
ExecutionRoleArn: !If
- CreateRoles
- !GetAtt
- ECSExecutionRole
- Arn
- !If
- DefaultExecutionRole
- !Sub 'arn:aws:iam::${AWS::AccountId}:role/AWSOTelExecutionRole'
- !Ref ExecutionRoleArn
NetworkMode: bridge
ContainerDefinitions:
- LogConfiguration:
LogDriver: awslogs
Options:
awslogs-create-group: 'True'
awslogs-group: !Sub '/ecs/aws-otel-collector/${ClusterName}'
awslogs-region: !Ref 'AWS::Region'
awslogs-stream-prefix: ecs
Image: !Ref CollectorImage
Name: aws-collector
Secrets:
- Name: AOT_CONFIG_CONTENT
ValueFrom: !Sub 'AmazonCloudWatch-AOC-ECS-Prometheus-${ClusterName}'
Memory: '512'
RequiresCompatibilities:
- EC2
Cpu: '256'
ECSReplicaService:
Type: 'AWS::ECS::Service'
Properties:
TaskDefinition: !Ref ECSTaskDefinition
Cluster: !Ref ClusterName
LaunchType: EC2
SchedulingStrategy: REPLICA
DesiredCount: 1
ServiceName: adot-container-insights-prometheus-service
ECSTaskRole:
Type: 'AWS::IAM::Role'
Condition: CreateRoles
Properties:
Description: Allows ECS tasks to call AWS services on your behalf.
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
- Sid: ''
Effect: Allow
Principal:
Service: ecs-tasks.amazonaws.com
Action: 'sts:AssumeRole'
Policies:
- PolicyName: AWSOpenTelemetryPolicy
PolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Action:
- 'logs:PutLogEvents'
- 'logs:CreateLogGroup'
- 'logs:CreateLogStream'
- 'logs:DescribeLogStreams'
- 'logs:DescribeLogGroups'
- 'xray:PutTraceSegments'
- 'xray:PutTelemetryRecords'
- 'xray:GetSamplingRules'
- 'xray:GetSamplingTargets'
- 'xray:GetSamplingStatisticSummaries'
- 'ssm:GetParameters'
Resource: '*'
- PolicyName: AWSOpenTelemetryPolicyPrometheusECSDiscovery
PolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Action:
- 'ec2:DescribeInstances'
- 'ecs:ListTasks'
- 'ecs:ListServices'
- 'ecs:DescribeContainerInstances'
- 'ecs:DescribeServices'
- 'ecs:DescribeTasks'
- 'ecs:DescribeTaskDefinition'
Resource: '*'
RoleName: AWSOTelRolePrometheusECS
ECSExecutionRole:
Type: 'AWS::IAM::Role'
Condition: CreateRoles
Properties:
Description: >-
Allows ECS container agent makes calls to the Amazon ECS API on your
behalf.
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
- Sid: ''
Effect: Allow
Principal:
Service: ecs-tasks.amazonaws.com
Action: 'sts:AssumeRole'
ManagedPolicyArns:
- 'arn:aws:iam::aws:policy/service-role/AmazonECSTaskExecutionRolePolicy'
- 'arn:aws:iam::aws:policy/CloudWatchLogsFullAccess'
- 'arn:aws:iam::aws:policy/AmazonSSMReadOnlyAccess'
RoleName: AWSOTelExecutionRolePrometheusECS
AocConfigSSMParameter:
Type: AWS::SSM::Parameter
Properties:
Name: !Sub 'AmazonCloudWatch-AOC-ECS-Prometheus-${ClusterName}'
Type: String
Tier: Intelligent-Tiering
Description: !Sub 'CWAgent SSM Parameter with App Mesh and Java EMF Definition for ECS Cluster: ${ClusterName}'
Value: !Sub |-
extensions:
ecs_observer:
cluster_name: '${ClusterName}'
cluster_region: '${AWS::Region}'
result_file: '/etc/ecs_sd_targets.yaml'
refresh_interval: 60s
job_label_name: prometheus_job
# nginx and nginx plus
# https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/ContainerInsights-Prometheus-Setup-nginx-ecs.html
services:
- name_pattern: '^.*nginx-service$'
metrics_ports:
- 9113
job_name: nginx-prometheus-exporter
# jmx
docker_labels:
- port_label: 'ECS_PROMETHEUS_EXPORTER_PORT'
# App Mesh, port and metrics are from envoy sidecar
task_definitions:
- arn_pattern: '.*:task-definition/.*-ColorTeller-(white):[0-9]+'
metrics_path: '/stats/prometheus'
metrics_ports:
- 9901
job_name: ecs-appmesh-color
- arn_pattern: '.*:task-definition/.*-ColorGateway:[0-9]+'
metrics_path: '/stats/prometheus'
metrics_ports:
- 9901
job_name: ecs-appmesh-color
receivers:
prometheus:
config:
scrape_configs:
- job_name: "ecssd"
file_sd_configs:
- files:
- '/etc/ecs_sd_targets.yaml'
relabel_configs:
- source_labels: [ __meta_ecs_cluster_name ] # ClusterName
action: replace
target_label: ClusterName
- source_labels: [ __meta_ecs_service_name ] # ServiceName
action: replace
target_label: ServiceName
- source_labels: [ __meta_ecs_task_definition_family ] # TaskDefinitionFamily
action: replace
target_label: TaskDefinitionFamily
- source_labels: [ __meta_ecs_container_name ] # container_name
action: replace
target_label: container_name
- action: labelmap # docker labels
regex: ^__meta_ecs_container_labels_(.+)$
replacement: '$$1'
exporters:
awsemf:
region: '${AWS::Region}'
namespace: ECS/ContainerInsights/Prometheus
log_group_name: "/aws/ecs/containerinsights/${ClusterName}/prometheus"
dimension_rollup_option: NoDimensionRollup
metric_declarations:
# nginx
- dimensions: [ [ ClusterName, TaskDefinitionFamily, ServiceName ] ]
label_matchers:
- label_names:
- ServiceName
regex: '^.*nginx-service$'
metric_name_selectors:
- "^nginx_.*$"
# nginx plus
- dimensions: [ [ ClusterName, TaskDefinitionFamily, ServiceName ] ]
label_matchers:
- label_names:
- ServiceName
regex: '^.*nginx-plus-service$'
metric_name_selectors:
- "^nginxplus_connections_accepted$"
- "^nginxplus_connections_active$"
- "^nginxplus_connections_dropped$"
- "^nginxplus_connections_idle$"
- "^nginxplus_http_requests_total$"
- "^nginxplus_ssl_handshakes$"
- "^nginxplus_ssl_handshakes_failed$"
- "^nginxplus_up$"
- "^nginxplus_upstream_server_health_checks_fails$"
- dimensions: [ [ ClusterName, TaskDefinitionFamily, ServiceName, upstream ] ]
label_matchers:
- label_names:
- ServiceName
regex: '^.*nginx-plus-service$'
metric_name_selectors:
- "^nginxplus_upstream_server_response_time$"
- dimensions: [ [ ClusterName, TaskDefinitionFamily, ServiceName, code ] ]
label_matchers:
- label_names:
- ServiceName
regex: '^.*nginx-plus-service$'
metric_name_selectors:
- "^nginxplus_upstream_server_responses$"
- "^nginxplus_server_zone_responses$"
# jmx
- dimensions: [ [ ClusterName, TaskDefinitionFamily, area ] ]
label_matchers:
- label_names:
- Java_EMF_Metrics
regex: ^true$
metric_name_selectors:
- "^jvm_memory_bytes_used$"
- dimensions: [ [ ClusterName, TaskDefinitionFamily, pool ] ]
label_matchers:
- label_names:
- Java_EMF_Metrics
regex: ^true$
metric_name_selectors:
- "^jvm_memory_pool_bytes_used$"
- dimensions: [ [ ClusterName, TaskDefinitionFamily ] ]
label_matchers:
- label_names:
- Java_EMF_Metrics
regex: ^true$
metric_name_selectors:
- "^jvm_threads_(current|daemon)$"
- "^jvm_classes_loaded$"
- "^java_lang_operatingsystem_(freephysicalmemorysize|totalphysicalmemorysize|freeswapspacesize|totalswapspacesize|systemcpuload|processcpuload|availableprocessors|openfiledescriptorcount)$"
- "^catalina_manager_(rejectedsessions|activesessions)$"
- "^jvm_gc_collection_seconds_(count|sum)$"
- "^catalina_globalrequestprocessor_(bytesreceived|bytessent|requestcount|errorcount|processingtime)$"
# AppMesh envoy
- dimensions: [ [ "ClusterName","TaskDefinitionFamily" ] ]
label_matchers:
- label_names:
- container_name
regex: ^envoy$
metric_name_selectors:
- "^envoy_http_downstream_rq_(total|xx)$"
- "^envoy_cluster_upstream_cx_(r|t)x_bytes_total$"
- "^envoy_cluster_membership_(healthy|total)$"
- "^envoy_server_memory_(allocated|heap_size)$"
- "^envoy_cluster_upstream_cx_(connect_timeout|destroy_local_with_active_rq)$"
- "^envoy_cluster_upstream_rq_(pending_failure_eject|pending_overflow|timeout|per_try_timeout|rx_reset|maintenance_mode)$"
- "^envoy_http_downstream_cx_destroy_remote_active_rq$"
- "^envoy_cluster_upstream_flow_control_(paused_reading_total|resumed_reading_total|backed_up_total|drained_total)$"
- "^envoy_cluster_upstream_rq_retry$"
- "^envoy_cluster_upstream_rq_retry_(success|overflow)$"
- "^envoy_server_(version|uptime|live)$"
- dimensions: [ [ "ClusterName","TaskDefinitionFamily","envoy_http_conn_manager_prefix","envoy_response_code_class" ] ]
label_matchers:
- label_names:
- container_name
regex: ^envoy$
metric_name_selectors:
- "^envoy_http_downstream_rq_xx$"
service:
extensions: [ ecs_observer ]
pipelines:
metrics:
receivers: [ prometheus ]
exporters: [ awsemf ]