Skip to content

Commit a6a7f7b

Browse files
committed
Add status bar widget
1 parent 9b574a9 commit a6a7f7b

File tree

3 files changed

+83
-0
lines changed

3 files changed

+83
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright (c) 2025 Gitpod GmbH. All rights reserved.
2+
// Licensed under the GNU Affero General Public License (AGPL).
3+
// See License.AGPL.txt in the project root for license information.
4+
5+
package io.gitpod.jetbrains.remote
6+
7+
import com.intellij.openapi.project.Project
8+
import com.intellij.openapi.wm.StatusBarWidget
9+
import com.intellij.openapi.wm.StatusBarWidgetFactory
10+
11+
class GitpodSystemMetricsFactory : StatusBarWidgetFactory {
12+
override fun getId(): String = "GitpodSystemMetricsWidget"
13+
14+
override fun getDisplayName(): String = "Gitpod System Metrics"
15+
16+
override fun isAvailable(project: Project): Boolean = true
17+
18+
override fun createWidget(project: Project): StatusBarWidget =
19+
GitpodSystemMetricsWidget(project)
20+
21+
override fun disposeWidget(widget: StatusBarWidget) {
22+
widget.dispose()
23+
}
24+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// Copyright (c) 2025 Gitpod GmbH. All rights reserved.
2+
// Licensed under the GNU Affero General Public License (AGPL).
3+
// See License.AGPL.txt in the project root for license information.
4+
5+
package io.gitpod.jetbrains.remote
6+
7+
import com.intellij.openapi.project.Project
8+
import com.intellij.openapi.wm.StatusBar
9+
import com.intellij.openapi.wm.StatusBarWidget
10+
import com.intellij.openapi.wm.impl.status.MemoryUsagePanel
11+
import java.awt.event.ActionListener
12+
import java.lang.management.ManagementFactory
13+
import javax.swing.Timer
14+
15+
class GitpodSystemMetricsWidget(private val project: Project) : StatusBarWidget {
16+
private var updateTimer: Timer? = null
17+
private val memoryPanel = MemoryUsagePanel()
18+
19+
init {
20+
startUpdates()
21+
}
22+
23+
private fun startUpdates() {
24+
updateTimer = Timer(1000, ActionListener {
25+
if (project.isDisposed) {
26+
stopUpdates()
27+
return@ActionListener
28+
}
29+
updateMetrics()
30+
}).apply { start() }
31+
}
32+
33+
private fun stopUpdates() {
34+
updateTimer?.stop()
35+
updateTimer = null
36+
}
37+
38+
private fun updateMetrics() {
39+
val memoryBean = ManagementFactory.getMemoryMXBean()
40+
val usedMemory = memoryBean.heapMemoryUsage.used / (1024 * 1024)
41+
val maxMemory = memoryBean.heapMemoryUsage.max / (1024 * 1024)
42+
val cpuLoad = ManagementFactory.getOperatingSystemMXBean().systemLoadAverage
43+
44+
val metrics = "Mem: ${usedMemory}M/${maxMemory}M | CPU: %.1f%%".format(cpuLoad * 100)
45+
memoryPanel.text = metrics
46+
memoryPanel.parent?.repaint()
47+
}
48+
49+
override fun install(statusBar: StatusBar) {
50+
statusBar.addWidget(memoryPanel)
51+
}
52+
53+
override fun dispose() {
54+
stopUpdates()
55+
}
56+
57+
override fun ID(): String = "GitpodSystemMetricsWidget"
58+
}

components/ide/jetbrains/backend-plugin/src/main/resources/META-INF/plugin.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
client="controller" preload="true"/>
6262
<gateway.customization.performance id="gitpodMetricsControl" order="before cpuControl"
6363
implementation="io.gitpod.jetbrains.remote.GitpodMetricControlProvider"/>
64+
<statusBarWidgetFactory implementation="io.gitpod.jetbrains.remote.GitpodSystemMetricsFactory"/>
6465
</extensions>
6566

6667
<actions>

0 commit comments

Comments
 (0)