-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[JetBrains] Show Workspace CPU/Memory resources in control center #12053
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
roboquat
merged 1 commit into
main
from
afalz/10580-show-workspace-metrics-in-jb-control-centre
Aug 12, 2022
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
...d-plugin/src/main/kotlin/io/gitpod/jetbrains/remote/latest/GitpodMetricControlProvider.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// Copyright (c) 2022 Gitpod GmbH. All rights reserved. | ||
// Licensed under the GNU Affero General Public License (AGPL). | ||
// See License-AGPL.txt in the project root for license information. | ||
|
||
package io.gitpod.jetbrains.remote.latest | ||
|
||
import com.jetbrains.ide.model.uiautomation.BeControl | ||
import com.jetbrains.rd.ui.bedsl.dsl.VerticalGridBuilder | ||
import com.jetbrains.rd.ui.bedsl.dsl.verticalGrid | ||
import com.jetbrains.rd.util.lifetime.Lifetime | ||
import com.jetbrains.rd.util.reactive.Property | ||
import com.jetbrains.rdserver.diagnostics.BackendDiagnosticsService | ||
import com.jetbrains.rdserver.unattendedHost.customization.controlCenter.performance.MetricControlProvider | ||
import com.jetbrains.rdserver.unattendedHost.customization.controlCenter.performance.createProgressBar | ||
import com.jetbrains.rdserver.unattendedHost.customization.controlCenter.performance.createProgressRow | ||
|
||
class GitpodMetricControlProvider : MetricControlProvider { | ||
override val id: String = "gitpodMetricsControl" | ||
override fun getControl(lifetime: Lifetime): BeControl { | ||
return verticalGrid { | ||
val backendDiagnosticsService = BackendDiagnosticsService.Companion.getInstance() | ||
createCpuControl(this, backendDiagnosticsService, lifetime) | ||
createMemoryControl(this, backendDiagnosticsService, lifetime) | ||
} | ||
} | ||
|
||
private fun createCpuControl(ctx: VerticalGridBuilder, backendDiagnosticsService: BackendDiagnosticsService, lifetime: Lifetime) { | ||
val cpuUsed = backendDiagnosticsService.getMetric("gitpod_workspace_cpu_used") | ||
val cpuTotal = backendDiagnosticsService.getMetric("gitpod_workspace_cpu_total") | ||
val cpuPercentage = backendDiagnosticsService.getMetric("gitpod_workspace_cpu_percentage") | ||
val cpuPercentageProperty = Property("$cpuPercentage %") | ||
val label = "Workspace CPU" | ||
val progressBar = createProgressBar(lifetime, cpuPercentage.valueProperty, cpuPercentageProperty) | ||
val labelProperty = Property("") | ||
|
||
fun updateLabel() { | ||
labelProperty.set("${cpuUsed}m / ${cpuTotal}m") | ||
} | ||
updateLabel() | ||
cpuUsed.valueProperty.change.advise(lifetime) { | ||
updateLabel() | ||
} | ||
cpuTotal.valueProperty.change.advise(lifetime) { | ||
updateLabel() | ||
} | ||
createProgressRow(ctx, lifetime, label, cpuPercentage.statusProperty, labelProperty, cpuPercentageProperty, progressBar) | ||
} | ||
|
||
private fun createMemoryControl(ctx: VerticalGridBuilder, backendDiagnosticsService: BackendDiagnosticsService, lifetime: Lifetime) { | ||
val memoryUsed = backendDiagnosticsService.getMetric("gitpod_workspace_memory_used") | ||
val memoryTotal = backendDiagnosticsService.getMetric("gitpod_workspace_memory_total") | ||
val memoryPercentage = backendDiagnosticsService.getMetric("gitpod_workspace_memory_percentage") | ||
val memoryPercentageProperty = Property("$memoryPercentage %") | ||
val label = "Workspace Memory" | ||
val progressBar = createProgressBar(lifetime, memoryPercentage.valueProperty, memoryPercentageProperty) | ||
val labelProperty = Property("") | ||
|
||
fun updateLabel() { | ||
labelProperty.set("${memoryUsed}GB / ${memoryTotal}GB") | ||
} | ||
updateLabel() | ||
memoryUsed.valueProperty.change.advise(lifetime) { | ||
updateLabel() | ||
} | ||
memoryTotal.valueProperty.change.advise(lifetime) { | ||
updateLabel() | ||
} | ||
|
||
createProgressRow(ctx, lifetime, label, memoryPercentage.statusProperty, labelProperty, memoryPercentageProperty, progressBar) | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
.../backend-plugin/src/main/kotlin/io/gitpod/jetbrains/remote/latest/GitpodMetricProvider.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// Copyright (c) 2022 Gitpod GmbH. All rights reserved. | ||
// Licensed under the GNU Affero General Public License (AGPL). | ||
// See License-AGPL.txt in the project root for license information. | ||
|
||
package io.gitpod.jetbrains.remote.latest | ||
|
||
import com.intellij.openapi.components.service | ||
import com.jetbrains.rd.platform.codeWithMe.unattendedHost.metrics.Metric | ||
import com.jetbrains.rd.platform.codeWithMe.unattendedHost.metrics.MetricType | ||
import com.jetbrains.rd.platform.codeWithMe.unattendedHost.metrics.MetricsStatus | ||
import com.jetbrains.rd.platform.codeWithMe.unattendedHost.metrics.providers.MetricProvider | ||
import io.gitpod.jetbrains.remote.GitpodManager | ||
import kotlin.math.roundToInt | ||
|
||
class GitpodMetricProvider: MetricProvider { | ||
private val manager = service<GitpodManager>() | ||
|
||
override val id: String = "gitpodMetricsProvider" | ||
override fun getMetrics(): Map<String, Metric> { | ||
val resourceStatus = manager.resourceStatus | ||
|
||
val cpuUsed = resourceStatus?.cpu?.used?.toDouble() ?: 0.0 | ||
val cpuTotal = resourceStatus?.cpu?.limit?.toDouble() ?: 0.0 | ||
val cpuPercentage = (cpuUsed / cpuTotal) * 100 | ||
|
||
// TODO: retrieve thresholds from supervisor once we implement this: https://github.com/gitpod-io/gitpod/issues/12075 | ||
val cpuStatus = if (cpuPercentage >= 95) { | ||
MetricsStatus.DANGER | ||
} else if (cpuPercentage >= 80) { | ||
MetricsStatus.WARNING | ||
} else { | ||
MetricsStatus.NORMAL | ||
} | ||
|
||
val memoryUsed = convertBytesToGB(resourceStatus?.memory?.used ?: 0) | ||
val memoryTotal = convertBytesToGB(resourceStatus?.memory?.limit ?: 0) | ||
val memoryPercentage = (memoryUsed / memoryTotal) * 100 | ||
|
||
// TODO: retrieve thresholds from supervisor once we implement this: https://github.com/gitpod-io/gitpod/issues/12075 | ||
val memoryStatus = if (memoryPercentage >= 95) { | ||
MetricsStatus.DANGER | ||
} else if (memoryPercentage >= 80) { | ||
MetricsStatus.WARNING | ||
} else { | ||
MetricsStatus.NORMAL | ||
} | ||
|
||
return mapOf( | ||
"gitpod_workspace_cpu_used" to Metric(MetricType.PERFORMANCE, MetricsStatus.NORMAL, roundTo(cpuUsed, 0)), | ||
"gitpod_workspace_cpu_total" to Metric(MetricType.PERFORMANCE, MetricsStatus.NORMAL, roundTo(cpuTotal, 0)), | ||
"gitpod_workspace_cpu_percentage" to Metric(MetricType.PERFORMANCE, cpuStatus, (cpuPercentage * 1000.0).roundToInt() / 1000.0), | ||
"gitpod_workspace_memory_used" to Metric(MetricType.PERFORMANCE, MetricsStatus.NORMAL, roundTo(memoryUsed, 2)), | ||
"gitpod_workspace_memory_total" to Metric(MetricType.PERFORMANCE, MetricsStatus.NORMAL, roundTo(memoryTotal, 2)), | ||
"gitpod_workspace_memory_percentage" to Metric(MetricType.PERFORMANCE, memoryStatus, (memoryPercentage * 1000.0).roundToInt() / 1000.0) | ||
) | ||
} | ||
|
||
private fun convertBytesToGB(bytes: Long) : Double { | ||
return bytes.div(1073741824.0) | ||
} | ||
|
||
private fun roundTo(number: Double, decimals: Int) : String { | ||
return String.format("%.${decimals}f", number) | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.