目录

Spark监控问题

概述

Spark 任务监控分为两个维度,三个模块

两个维度包括:

  1. Spark Operator
  2. Spark 应用本身

三个模块包括:

  1. Spark Operator
  2. 通过Spark Operator部署的Spark3应用
  3. Spark2.2应用

Spark Operator部署

部署 Spark Operator 建议通过 Helm,下面是渲染出来的 Pod Yaml。注意需要通过 Annotation 来暴露供 Prometheus 采集的端点等信息。

 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
# kubectl get pods -n kube-system spark-sparkoperator-848b4f5db-cxc5f -o yaml
apiVersion: v1
kind: Pod
metadata:
  annotations:
  generateName: spark-sparkoperator-
  labels:
    component: spark-operator
  name: spark-sparkoperator-848b4f5db-cxc5f
  namespace: kube-system
  ownerReferences:
  - apiVersion: extensions/v1beta1
    blockOwnerDeletion: true
    controller: true
    kind: ReplicaSet
    name: spark-sparkoperator-848b4f5db
    uid: f50d2fb6-26e3-11ea-bf25-246e9633d500
spec:
  containers:
  - args:
    - -v=5
    - -namespace=kube-system
    - -ingress-url-format=
    - -controller-threads=10
    - -resync-interval=30
    - -logtostderr
    - -enable-batch-scheduler=true
    image: hub.oa.com/runzhliu/spark-operator:latest
    imagePullPolicy: Always
    name: sparkoperator
    resources: {}
    volumeMounts:
    - mountPath: /var/run/secrets/kubernetes.io/serviceaccount
      name: default-token-8jkwb
      readOnly: true
  dnsPolicy: ClusterFirst
  nodeName: 10.246.145.93
  restartPolicy: Always
  schedulerName: default-scheduler
  securityContext: {}
  serviceAccount: default
  serviceAccountName: default
  terminationGracePeriodSeconds: 30
  volumes:
  - name: default-token-8jkwb
    secret:
      defaultMode: 420
      secretName: default-token-8jkwb

Spark Operator 需要暴露出 Metrics 信息。可以通过 Helm 重新注入参数。

 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
operatorImageName: hub.oa.com/runzhliu/spark-operator
operatorVersion: latest
imagePullPolicy: Always
replicas: 1
rbac:
  create: false
serviceAccounts:
  spark:
    create: false
    name:
  sparkoperator:
    create: false
    name:
sparkJobNamespace: ""
installCrds: true
controllerThreads: 10
resyncInterval: 30
ingressUrlFormat: ""
logLevel: 6
enableWebhook: false
webhookPort: 8080

# 这是 metrics 的控制逻辑
enableMetrics: false
metricsPort: 10254
metricsEndpoint: "/metrics"
metricsPrefix: ""

## Node labels for pod assignment
## Ref: https://kubernetes.io/docs/user-guide/node-selection/
nodeSelector: {}
podAnnotations: {}

## Resources for the sparkoperator deployment
## Ref: https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/
resources: {}

## Whether to enable batch scheduler for pod scheduling,
## if enabled, end user can specify batch scheduler name in spark application.
enableBatchScheduler: true

## Whether to enable the ResourceQuota enforcement for SparkApplication resources.
## Requires the webhook to be enabled by setting enableWebhook to true.
## Ref: https://github.com/GoogleCloudPlatform/spark-on-k8s-operator/blob/master/docs/user-guide.md#enabling-resource-quota-enforcement.
enableResourceQuotaEnforcement: false

## Whether to enable leader election when the operator Deployment has more than one replica.
## Only applicable when `replicas` is set to a value greater than 1.
## Ref: https://github.com/GoogleCloudPlatform/spark-on-k8s-operator/blob/master/docs/user-guide.md#enabling-leader-election-for-high-availability.
enableLeaderElection: false

Spark Operator 的 Metrics 样例。

  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
/ # curl http://6.27.61.213:10254/metrics
# HELP go_gc_duration_seconds A summary of the GC invocation durations.
# TYPE go_gc_duration_seconds summary
go_gc_duration_seconds{quantile="0"} 1.6119e-05
go_gc_duration_seconds{quantile="0.25"} 2.2703e-05
go_gc_duration_seconds{quantile="0.5"} 2.753e-05
go_gc_duration_seconds{quantile="0.75"} 4.4329e-05
go_gc_duration_seconds{quantile="1"} 0.00019665
go_gc_duration_seconds_sum 0.000668062
go_gc_duration_seconds_count 15
# HELP go_goroutines Number of goroutines that currently exist.
# TYPE go_goroutines gauge
go_goroutines 64
# HELP go_info Information about the Go environment.
# TYPE go_info gauge
go_info{version="go1.12.5"} 1
# HELP go_memstats_alloc_bytes Number of bytes allocated and still in use.
# TYPE go_memstats_alloc_bytes gauge
go_memstats_alloc_bytes 3.623152e+06
# HELP go_memstats_alloc_bytes_total Total number of bytes allocated, even if freed.
# TYPE go_memstats_alloc_bytes_total counter
go_memstats_alloc_bytes_total 1.1099008e+07
# HELP go_memstats_buck_hash_sys_bytes Number of bytes used by the profiling bucket hash table.
# TYPE go_memstats_buck_hash_sys_bytes gauge
go_memstats_buck_hash_sys_bytes 1.448427e+06
# HELP go_memstats_frees_total Total number of frees.
# TYPE go_memstats_frees_total counter
go_memstats_frees_total 105429
# HELP go_memstats_gc_cpu_fraction The fraction of this program's available CPU time used by the GC since the program started.
# TYPE go_memstats_gc_cpu_fraction gauge
go_memstats_gc_cpu_fraction 6.719624406231062e-06
# HELP go_memstats_gc_sys_bytes Number of bytes used for garbage collection system metadata.
# TYPE go_memstats_gc_sys_bytes gauge
go_memstats_gc_sys_bytes 2.38592e+06
# HELP go_memstats_heap_alloc_bytes Number of heap bytes allocated and still in use.
# TYPE go_memstats_heap_alloc_bytes gauge
go_memstats_heap_alloc_bytes 3.623152e+06
# HELP go_memstats_heap_idle_bytes Number of heap bytes waiting to be used.
# TYPE go_memstats_heap_idle_bytes gauge
go_memstats_heap_idle_bytes 5.955584e+07
# HELP go_memstats_heap_inuse_bytes Number of heap bytes that are in use.
# TYPE go_memstats_heap_inuse_bytes gauge
go_memstats_heap_inuse_bytes 6.569984e+06
# HELP go_memstats_heap_objects Number of allocated objects.
# TYPE go_memstats_heap_objects gauge
go_memstats_heap_objects 23583
# HELP go_memstats_heap_released_bytes Number of heap bytes released to OS.
# TYPE go_memstats_heap_released_bytes gauge
go_memstats_heap_released_bytes 5.9252736e+07
# HELP go_memstats_heap_sys_bytes Number of heap bytes obtained from system.
# TYPE go_memstats_heap_sys_bytes gauge
go_memstats_heap_sys_bytes 6.6125824e+07
# HELP go_memstats_last_gc_time_seconds Number of seconds since 1970 of last garbage collection.
# TYPE go_memstats_last_gc_time_seconds gauge
go_memstats_last_gc_time_seconds 1.581564578093046e+09
# HELP go_memstats_lookups_total Total number of pointer lookups.
# TYPE go_memstats_lookups_total counter
go_memstats_lookups_total 0
# HELP go_memstats_mallocs_total Total number of mallocs.
# TYPE go_memstats_mallocs_total counter
go_memstats_mallocs_total 129012
# HELP go_memstats_mcache_inuse_bytes Number of bytes in use by mcache structures.
# TYPE go_memstats_mcache_inuse_bytes gauge
go_memstats_mcache_inuse_bytes 6944
# HELP go_memstats_mcache_sys_bytes Number of bytes used for mcache structures obtained from system.
# TYPE go_memstats_mcache_sys_bytes gauge
go_memstats_mcache_sys_bytes 16384
# HELP go_memstats_mspan_inuse_bytes Number of bytes in use by mspan structures.
# TYPE go_memstats_mspan_inuse_bytes gauge
go_memstats_mspan_inuse_bytes 91152
# HELP go_memstats_mspan_sys_bytes Number of bytes used for mspan structures obtained from system.
# TYPE go_memstats_mspan_sys_bytes gauge
go_memstats_mspan_sys_bytes 98304
# HELP go_memstats_next_gc_bytes Number of heap bytes when next garbage collection will take place.
# TYPE go_memstats_next_gc_bytes gauge
go_memstats_next_gc_bytes 7.049776e+06
# HELP go_memstats_other_sys_bytes Number of bytes used for other system allocations.
# TYPE go_memstats_other_sys_bytes gauge
go_memstats_other_sys_bytes 1.228557e+06
# HELP go_memstats_stack_inuse_bytes Number of bytes in use by the stack allocator.
# TYPE go_memstats_stack_inuse_bytes gauge
go_memstats_stack_inuse_bytes 983040
# HELP go_memstats_stack_sys_bytes Number of bytes obtained from system for stack allocator.
# TYPE go_memstats_stack_sys_bytes gauge
go_memstats_stack_sys_bytes 983040
# HELP go_memstats_sys_bytes Number of bytes obtained from system.
# TYPE go_memstats_sys_bytes gauge
go_memstats_sys_bytes 7.2286456e+07
# HELP go_threads Number of OS threads created.
# TYPE go_threads gauge
go_threads 14
# HELP process_cpu_seconds_total Total user and system CPU time spent in seconds.
# TYPE process_cpu_seconds_total counter
process_cpu_seconds_total 1.01
# HELP process_max_fds Maximum number of open file descriptors.
# TYPE process_max_fds gauge
process_max_fds 204800
# HELP process_open_fds Number of open file descriptors.
# TYPE process_open_fds gauge
process_open_fds 8
# HELP process_resident_memory_bytes Resident memory size in bytes.
# TYPE process_resident_memory_bytes gauge
process_resident_memory_bytes 2.6206208e+07
# HELP process_start_time_seconds Start time of the process since unix epoch in seconds.
# TYPE process_start_time_seconds gauge
process_start_time_seconds 1.58156325668e+09
# HELP process_virtual_memory_bytes Virtual memory size in bytes.
# TYPE process_virtual_memory_bytes gauge
process_virtual_memory_bytes 1.38883072e+08
# HELP process_virtual_memory_max_bytes Maximum amount of virtual memory available in bytes.
# TYPE process_virtual_memory_max_bytes gauge
process_virtual_memory_max_bytes -1
# HELP promhttp_metric_handler_requests_in_flight Current number of scrapes being served.
# TYPE promhttp_metric_handler_requests_in_flight gauge
promhttp_metric_handler_requests_in_flight 1
# HELP promhttp_metric_handler_requests_total Total number of scrapes by HTTP status code.
# TYPE promhttp_metric_handler_requests_total counter
promhttp_metric_handler_requests_total{code="200"} 1
promhttp_metric_handler_requests_total{code="500"} 0
promhttp_metric_handler_requests_total{code="503"} 0
# HELP scheduled_spark_application_controller_adds Total number of adds handled by workqueue: scheduled-spark-application-controller
# TYPE scheduled_spark_application_controller_adds counter
scheduled_spark_application_controller_adds 0
# HELP scheduled_spark_application_controller_depth Current depth of workqueue: scheduled-spark-application-controller
# TYPE scheduled_spark_application_controller_depth gauge
scheduled_spark_application_controller_depth 0
# HELP scheduled_spark_application_controller_latency Latency for workqueue: scheduled-spark-application-controller
# TYPE scheduled_spark_application_controller_latency summary
scheduled_spark_application_controller_latency{quantile="0.5"} NaN
scheduled_spark_application_controller_latency{quantile="0.9"} NaN
scheduled_spark_application_controller_latency{quantile="0.99"} NaN
scheduled_spark_application_controller_latency_sum 0
scheduled_spark_application_controller_latency_count 0
# HELP scheduled_spark_application_controller_longest_running_processor_microseconds Longest running processor microseconds: scheduled-spark-application-controller
# TYPE scheduled_spark_application_controller_longest_running_processor_microseconds gauge
scheduled_spark_application_controller_longest_running_processor_microseconds 0
# HELP scheduled_spark_application_controller_retries Total number of retries handled by workqueue: scheduled-spark-application-controller
# TYPE scheduled_spark_application_controller_retries counter
scheduled_spark_application_controller_retries 0
# HELP scheduled_spark_application_controller_unfinished_work_seconds Unfinished work seconds: scheduled-spark-application-controller
# TYPE scheduled_spark_application_controller_unfinished_work_seconds gauge
scheduled_spark_application_controller_unfinished_work_seconds 0
# HELP scheduled_spark_application_controller_work_duration How long processing an item from workqueue scheduled-spark-application-controller takes.
# TYPE scheduled_spark_application_controller_work_duration summary
scheduled_spark_application_controller_work_duration{quantile="0.5"} NaN
scheduled_spark_application_controller_work_duration{quantile="0.9"} NaN
scheduled_spark_application_controller_work_duration{quantile="0.99"} NaN
scheduled_spark_application_controller_work_duration_sum 0
scheduled_spark_application_controller_work_duration_count 0
# HELP spark_application_controller_adds Total number of adds handled by workqueue: spark-application-controller
# TYPE spark_application_controller_adds counter
spark_application_controller_adds 12
# HELP spark_application_controller_depth Current depth of workqueue: spark-application-controller
# TYPE spark_application_controller_depth gauge
spark_application_controller_depth 0
# HELP spark_application_controller_latency Latency for workqueue: spark-application-controller
# TYPE spark_application_controller_latency summary
spark_application_controller_latency{quantile="0.5"} NaN
spark_application_controller_latency{quantile="0.9"} NaN
spark_application_controller_latency{quantile="0.99"} NaN
spark_application_controller_latency_sum 59457
spark_application_controller_latency_count 12
# HELP spark_application_controller_longest_running_processor_microseconds Longest running processor microseconds: spark-application-controller
# TYPE spark_application_controller_longest_running_processor_microseconds gauge
spark_application_controller_longest_running_processor_microseconds 0
# HELP spark_application_controller_retries Total number of retries handled by workqueue: spark-application-controller
# TYPE spark_application_controller_retries counter
spark_application_controller_retries 19
# HELP spark_application_controller_unfinished_work_seconds Unfinished work seconds: spark-application-controller
# TYPE spark_application_controller_unfinished_work_seconds gauge
spark_application_controller_unfinished_work_seconds 0
# HELP spark_application_controller_work_duration How long processing an item from workqueue spark-application-controller takes.
# TYPE spark_application_controller_work_duration summary
spark_application_controller_work_duration{quantile="0.5"} NaN
spark_application_controller_work_duration{quantile="0.9"} NaN
spark_application_controller_work_duration{quantile="0.99"} NaN
spark_application_controller_work_duration_sum 574253
spark_application_controller_work_duration_count 12

主要不同的指标类型,比如 Counter, Gauge, Summary, Histogram。

维度

Spark 监控的几个维度设计。

  1. Spark Operator本身的监控
  2. Spark Application的监控

关于 Spark App 的监控,需要按 namespace 来分一下。需要给指标加上相应的 namespace

警告
本文最后更新于 2017年2月1日,文中内容可能已过时,请谨慎参考。