-
Notifications
You must be signed in to change notification settings - Fork 28k
/
StreamingPage.scala
180 lines (161 loc) · 6.51 KB
/
StreamingPage.scala
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
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.spark.streaming.ui
import java.util.Calendar
import javax.servlet.http.HttpServletRequest
import scala.xml.Node
import org.apache.spark.Logging
import org.apache.spark.ui._
import org.apache.spark.ui.UIUtils._
import org.apache.spark.util.Distribution
/** Page for Spark Web UI that shows statistics of a streaming job */
private[ui] class StreamingPage(parent: StreamingTab)
extends WebUIPage("") with Logging {
private val listener = parent.listener
private val startTime = Calendar.getInstance().getTime()
private val emptyCellTest = "-"
/** Render the page */
override def render(request: HttpServletRequest): Seq[Node] = {
val content =
generateBasicStats() ++
<br></br><h4>Statistics over last {listener.completedBatches.size} processed batches</h4> ++
generateNetworkStatsTable() ++
generateBatchStatsTable()
UIUtils.headerSparkPage(
content, parent.basePath, parent.appName, "Streaming", parent.headerTabs, parent, Some(5000))
}
/** Generate basic stats of the streaming program */
private def generateBasicStats(): Seq[Node] = {
val timeSinceStart = System.currentTimeMillis() - startTime.getTime
<ul class ="unstyled">
<li>
<strong>Started at: </strong> {startTime.toString}
</li>
<li>
<strong>Time since start: </strong>{formatDurationVerbose(timeSinceStart)}
</li>
<li>
<strong>Network receivers: </strong>{listener.numNetworkReceivers}
</li>
<li>
<strong>Batch interval: </strong>{formatDurationVerbose(listener.batchDuration)}
</li>
<li>
<strong>Processed batches: </strong>{listener.numTotalCompletedBatches}
</li>
<li>
<strong>Waiting batches: </strong>{listener.numUnprocessedBatches}
</li>
</ul>
}
/** Generate stats of data received over the network the streaming program */
private def generateNetworkStatsTable(): Seq[Node] = {
val receivedRecordDistributions = listener.receivedRecordsDistributions
val lastBatchReceivedRecord = listener.lastReceivedBatchRecords
val table = if (receivedRecordDistributions.size > 0) {
val headerRow = Seq(
"Receiver",
"Location",
"Records in last batch\n[" + formatDate(Calendar.getInstance().getTime()) + "]",
"Minimum rate\n[records/sec]",
"25th percentile rate\n[records/sec]",
"Median rate\n[records/sec]",
"75th percentile rate\n[records/sec]",
"Maximum rate\n[records/sec]"
)
val dataRows = (0 until listener.numNetworkReceivers).map { receiverId =>
val receiverInfo = listener.receiverInfo(receiverId)
val receiverName = receiverInfo.map(_.toString).getOrElse(s"Receiver-$receiverId")
val receiverLocation = receiverInfo.map(_.location).getOrElse(emptyCellTest)
val receiverLastBatchRecords = formatDurationVerbose(lastBatchReceivedRecord(receiverId))
val receivedRecordStats = receivedRecordDistributions(receiverId).map { d =>
d.getQuantiles().map(r => formatDurationVerbose(r.toLong))
}.getOrElse {
Seq(emptyCellTest, emptyCellTest, emptyCellTest, emptyCellTest, emptyCellTest)
}
Seq(receiverName, receiverLocation, receiverLastBatchRecords) ++ receivedRecordStats
}
Some(listingTable(headerRow, dataRows))
} else {
None
}
val content =
<h5>Network Input Statistics</h5> ++
<div>{table.getOrElse("No network receivers")}</div>
content
}
/** Generate stats of batch jobs of the streaming program */
private def generateBatchStatsTable(): Seq[Node] = {
val numBatches = listener.completedBatches.size
val lastCompletedBatch = listener.lastCompletedBatch
val table = if (numBatches > 0) {
val processingDelayQuantilesRow = {
Seq(
"Processing Time",
formatDurationOption(lastCompletedBatch.flatMap(_.processingDelay))
) ++ getQuantiles(listener.processingDelayDistribution)
}
val schedulingDelayQuantilesRow = {
Seq(
"Scheduling Delay",
formatDurationOption(lastCompletedBatch.flatMap(_.schedulingDelay))
) ++ getQuantiles(listener.schedulingDelayDistribution)
}
val totalDelayQuantilesRow = {
Seq(
"Total Delay",
formatDurationOption(lastCompletedBatch.flatMap(_.totalDelay))
) ++ getQuantiles(listener.totalDelayDistribution)
}
val headerRow = Seq("Metric", "Last batch", "Minimum", "25th percentile",
"Median", "75th percentile", "Maximum")
val dataRows: Seq[Seq[String]] = Seq(
processingDelayQuantilesRow,
schedulingDelayQuantilesRow,
totalDelayQuantilesRow
)
Some(listingTable(headerRow, dataRows))
} else {
None
}
val content =
<h5>Batch Processing Statistics</h5> ++
<div>
<ul class="unstyled">
{table.getOrElse("No statistics have been generated yet.")}
</ul>
</div>
content
}
/**
* Returns a human-readable string representing a duration such as "5 second 35 ms"
*/
private def formatDurationOption(msOption: Option[Long]): String = {
msOption.map(formatDurationVerbose).getOrElse(emptyCellTest)
}
/** Get quantiles for any time distribution */
private def getQuantiles(timeDistributionOption: Option[Distribution]) = {
timeDistributionOption.get.getQuantiles().map { ms => formatDurationVerbose(ms.toLong) }
}
/** Generate HTML table from string data */
private def listingTable(headers: Seq[String], data: Seq[Seq[String]]) = {
def generateDataRow(data: Seq[String]): Seq[Node] = {
<tr> {data.map(d => <td>{d}</td>)} </tr>
}
UIUtils.listingTable(headers, generateDataRow, data, fixedWidth = true)
}
}