Skip to content

High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.

feat: add memory metrics to monitoring dashboard

Boschef5e216f4254
diff --git a/dashboard/src/components/molecules/InstanceListItem.tsx b/dashboard/src/components/molecules/InstanceListItem.tsx
index ff511843..3649798d 100644
--- a/dashboard/src/components/molecules/InstanceListItem.tsx
+++ b/dashboard/src/components/molecules/InstanceListItem.tsx
@@ -4,6 +4,7 @@ import type { Instance } from "../../generated/types";
interface Props {
instance: Instance;
tabCount: number;
+ memoryMB?: number;
selected: boolean;
onClick: () => void;
}
@@ -11,6 +12,7 @@ interface Props {
export default function InstanceListItem({
instance,
tabCount,
+ memoryMB,
selected,
onClick,
}: Props) {
@@ -44,6 +46,7 @@ export default function InstanceListItem({
</div>
<div className="text-xs text-text-muted">
:{instance.port} · {tabCount} tabs
+ {memoryMB !== undefined && ` · ${memoryMB.toFixed(0)}MB`}
</div>
</div>
<Badge variant={badgeVariant}>{instance.status}</Badge>
diff --git a/dashboard/src/components/molecules/TabsChart.tsx b/dashboard/src/components/molecules/TabsChart.tsx
index e5b3f2b1..240168df 100644
--- a/dashboard/src/components/molecules/TabsChart.tsx
+++ b/dashboard/src/components/molecules/TabsChart.tsx
@@ -7,10 +7,11 @@ import {
Tooltip,
ResponsiveContainer,
} from "recharts";
-import type { TabDataPoint } from "../../stores/useAppStore";
+import type { TabDataPoint, MemoryDataPoint } from "../../stores/useAppStore";
interface Props {
data: TabDataPoint[];
+ memoryData?: MemoryDataPoint[];
instances: { id: string; profileName: string }[];
selectedInstanceId: string | null;
onSelectInstance: (id: string) => void;
@@ -37,6 +38,7 @@ function formatTime(timestamp: number): string {
export default function TabsChart({
data,
+ memoryData,
instances,
selectedInstanceId,
onSelectInstance,
@@ -49,6 +51,25 @@ export default function TabsChart({
return colors;
}, [instances]);
+ // Merge tab and memory data by timestamp
+ const mergedData = useMemo(() => {
+ if (!memoryData || memoryData.length === 0) return data;
+
+ const memByTime = new Map(memoryData.map((m) => [m.timestamp, m]));
+ return data.map((d) => {
+ const mem = memByTime.get(d.timestamp);
+ if (!mem) return d;
+ // Add memory keys with _mem suffix
+ const merged: Record<string, number> = { ...d };
+ for (const [key, val] of Object.entries(mem)) {
+ if (key !== "timestamp") {
+ merged[`${key}_mem`] = val;
+ }
+ }
+ return merged;
+ });
+ }, [data, memoryData]);
+
if (data.length === 0 || instances.length === 0) {
return (
<div className="flex h-[200px] items-center justify-center rounded-lg border border-border-subtle bg-bg-surface text-sm text-text-muted">
@@ -57,12 +78,14 @@ export default function TabsChart({
);
}
+ const hasMemory = memoryData && memoryData.length > 0;
+
return (
<div className="rounded-lg border border-border-subtle bg-bg-surface">
<ResponsiveContainer width="100%" height={200}>
<LineChart
- data={data}
- margin={{ top: 16, right: 16, bottom: 8, left: 8 }}
+ data={mergedData}
+ margin={{ top: 16, right: hasMemory ? 50 : 16, bottom: 8, left: 8 }}
>
<XAxis
dataKey="timestamp"
@@ -73,6 +96,7 @@ export default function TabsChart({
axisLine={false}
/>
<YAxis
+ yAxisId="tabs"
stroke="#666"
fontSize={11}
allowDecimals={false}
@@ -81,6 +105,20 @@ export default function TabsChart({
axisLine={false}
width={30}
/>
+ {hasMemory && (
+ <YAxis
+ yAxisId="memory"
+ orientation="right"
+ stroke="#888"
+ fontSize={11}
+ allowDecimals={false}
+ domain={[0, "auto"]}
+ tickLine={false}
+ axisLine={false}
+ width={40}
+ tickFormatter={(v) => `${v}MB`}
+ />
+ )}
<Tooltip
contentStyle={{
background: "#1a1a1a",
@@ -90,13 +128,23 @@ export default function TabsChart({
}}
labelFormatter={(label) => formatTime(label as number)}
formatter={(value, name) => {
- const inst = instances.find((i) => i.id === name);
- return [value ?? 0, inst?.profileName || name];
+ const isMemory = String(name).endsWith("_mem");
+ const instId = isMemory
+ ? String(name).replace("_mem", "")
+ : String(name);
+ const inst = instances.find((i) => i.id === instId);
+ const label = inst?.profileName || instId;
+ return [
+ isMemory ? `${value}MB` : value,
+ isMemory ? `${label} (mem)` : `${label} (tabs)`,
+ ];
}}
/>
+ {/* Tab count lines (solid) */}
{instances.map((inst) => (
<Line
key={inst.id}
+ yAxisId="tabs"
type="monotone"
dataKey={inst.id}
name={inst.id}
@@ -113,6 +161,26 @@ export default function TabsChart({
}}
/>
))}
+ {/* Memory lines (dashed) */}
+ {hasMemory &&
+ instances.map((inst) => (
+ <Line
+ key={`${inst.id}_mem`}
+ yAxisId="memory"
+ type="monotone"
+ dataKey={`${inst.id}_mem`}
+ name={`${inst.id}_mem`}
+ stroke={instanceColors[inst.id]}
+ strokeWidth={selectedInstanceId === inst.id ? 2 : 1}
+ strokeOpacity={
+ selectedInstanceId && selectedInstanceId !== inst.id
+ ? 0.2
+ : 0.6
+ }
+ strokeDasharray="4 2"
+ dot={false}
+ />
+ ))}
</LineChart>
</ResponsiveContainer>
</div>
diff --git a/dashboard/src/generated/types.ts b/dashboard/src/generated/types.ts
index 29a77ae7..6b8b9ff4 100644
--- a/dashboard/src/generated/types.ts
+++ b/dashboard/src/generated/types.ts
@@ -64,7 +64,7 @@ export interface ActivityEvent {
method: string;
path: string;
timestamp: string;
- details?: { [key: string]: any };
+ details?: { [key: string]: any};
}
/**
* ScreencastSettings configures live tab previews.
@@ -125,6 +125,19 @@ export interface InstanceTab {
url: string;
title: string;
}
+/**
+ * InstanceMetrics represents memory metrics for an instance.
+ */
+export interface InstanceMetrics {
+ instanceId: string;
+ profileName: string;
+ jsHeapUsedMB: number /* float64 */;
+ jsHeapTotalMB: number /* float64 */;
+ documents: number /* int64 */;
+ frames: number /* int64 */;
+ nodes: number /* int64 */;
+ listeners: number /* int64 */;
+}
/**
* LaunchInstanceRequest is the request body for launching an instance.
*/
diff --git a/dashboard/src/pages/MonitoringPage.tsx b/dashboard/src/pages/MonitoringPage.tsx
index 90c73546..6e873c68 100644
--- a/dashboard/src/pages/MonitoringPage.tsx
+++ b/dashboard/src/pages/MonitoringPage.tsx
@@ -13,9 +13,13 @@ export default function MonitoringPage() {
setInstances,
setInstancesLoading,
tabsChartData,
+ memoryChartData,
currentTabs,
+ currentMemory,
addChartDataPoint,
+ addMemoryDataPoint,
setCurrentTabs,
+ setCurrentMemory,
} = useAppStore();
const [selectedId, setSelectedId] = useState<string | null>(null);
const pollRef = useRef<ReturnType<typeof setInterval> | null>(null);
@@ -32,33 +36,59 @@ export default function MonitoringPage() {
}
};
- // Fetch tabs for all running instances
- const fetchAllInstanceTabs = useCallback(async () => {
+ // Fetch tabs and memory for all running instances
+ const fetchAllInstanceData = useCallback(async () => {
const runningInstances = instances.filter((i) => i.status === "running");
if (runningInstances.length === 0) return;
try {
- // Use aggregated endpoint that returns proper format
- const allTabs = await api.fetchAllTabs();
+ // Fetch tabs and metrics in parallel
+ const [allTabs, allMetrics] = await Promise.all([
+ api.fetchAllTabs().catch(() => []),
+ api.fetchAllMetrics().catch(() => []),
+ ]);
+
const tabsArray = Array.isArray(allTabs) ? allTabs : [];
+ const metricsArray = Array.isArray(allMetrics) ? allMetrics : [];
const timestamp = Date.now();
- const dataPoint: Record<string, number> = { timestamp };
+ const tabDataPoint: Record<string, number> = { timestamp };
+ const memDataPoint: Record<string, number> = { timestamp };
const tabsByInstance: Record<string, InstanceTab[]> = {};
+ const memoryByInstance: Record<string, number> = {};
// Group tabs by instance
for (const inst of runningInstances) {
const instTabs = tabsArray.filter((t) => t.instanceId === inst.id);
- dataPoint[inst.id] = instTabs.length;
+ tabDataPoint[inst.id] = instTabs.length;
tabsByInstance[inst.id] = instTabs;
+
+ // Find memory for this instance
+ const instMem = metricsArray.find((m) => m.instanceId === inst.id);
+ if (instMem) {
+ memDataPoint[inst.id] = instMem.jsHeapUsedMB;
+ memoryByInstance[inst.id] = instMem.jsHeapUsedMB;
+ }
}
- addChartDataPoint(dataPoint as Parameters<typeof addChartDataPoint>[0]);
+ addChartDataPoint(
+ tabDataPoint as Parameters<typeof addChartDataPoint>[0],
+ );
+ addMemoryDataPoint(
+ memDataPoint as Parameters<typeof addMemoryDataPoint>[0],
+ );
setCurrentTabs(tabsByInstance);
+ setCurrentMemory(memoryByInstance);
} catch (e) {
- console.error("Failed to fetch tabs:", e);
+ console.error("Failed to fetch instance data:", e);
}
- }, [instances, addChartDataPoint, setCurrentTabs]);
+ }, [
+ instances,
+ addChartDataPoint,
+ addMemoryDataPoint,
+ setCurrentTabs,
+ setCurrentMemory,
+ ]);
// Load once on mount if empty — intentionally omitting deps to avoid refetch loops
useEffect(() => {
@@ -70,12 +100,12 @@ export default function MonitoringPage() {
// Poll tabs
useEffect(() => {
- fetchAllInstanceTabs();
- pollRef.current = setInterval(fetchAllInstanceTabs, POLL_INTERVAL);
+ fetchAllInstanceData();
+ pollRef.current = setInterval(fetchAllInstanceData, POLL_INTERVAL);
return () => {
if (pollRef.current) clearInterval(pollRef.current);
};
- }, [fetchAllInstanceTabs]);
+ }, [fetchAllInstanceData]);
// Auto-select first running instance
useEffect(() => {
@@ -110,6 +140,7 @@ export default function MonitoringPage() {
{/* Chart */}
<TabsChart
data={tabsChartData}
+ memoryData={memoryChartData}
instances={runningInstances.map((i) => ({
id: i.id,
profileName: i.profileName,
@@ -133,6 +164,7 @@ export default function MonitoringPage() {
key={inst.id}
instance={inst}
tabCount={currentTabs[inst.id]?.length ?? 0}
+ memoryMB={currentMemory[inst.id]}
selected={selectedId === inst.id}
onClick={() => setSelectedId(inst.id)}
/>
diff --git a/dashboard/src/services/api.ts b/dashboard/src/services/api.ts
index 25cee471..afd6c10e 100644
--- a/dashboard/src/services/api.ts
+++ b/dashboard/src/services/api.ts
@@ -2,6 +2,7 @@ import type {
Profile,
Instance,
InstanceTab,
+ InstanceMetrics,
Agent,
Settings,
ServerInfo,
@@ -71,6 +72,10 @@ export async function fetchAllTabs(): Promise<InstanceTab[]> {
return request<InstanceTab[]>("/instances/tabs");
}
+export async function fetchAllMetrics(): Promise<InstanceMetrics[]> {
+ return request<InstanceMetrics[]>("/instances/metrics");
+}
+
// Agents — endpoint is /api/agents (dashboard API)
export async function fetchAgents(): Promise<Agent[]> {
return request<Agent[]>("/api/agents");
diff --git a/dashboard/src/stores/useAppStore.ts b/dashboard/src/stores/useAppStore.ts
index 33ea57f0..d552d719 100644
--- a/dashboard/src/stores/useAppStore.ts
+++ b/dashboard/src/stores/useAppStore.ts
@@ -14,6 +14,11 @@ export interface TabDataPoint {
[instanceId: string]: number;
}
+export interface MemoryDataPoint {
+ timestamp: number;
+ [instanceId: string]: number; // jsHeapUsedMB
+}
+
interface AppState {
// Profiles
profiles: Profile[];
@@ -29,9 +34,13 @@ interface AppState {
// Chart data (persists across navigation)
tabsChartData: TabDataPoint[];
+ memoryChartData: MemoryDataPoint[];
currentTabs: Record<string, InstanceTab[]>;
+ currentMemory: Record<string, number>; // instanceId -> jsHeapUsedMB
addChartDataPoint: (point: TabDataPoint) => void;
+ addMemoryDataPoint: (point: MemoryDataPoint) => void;
setCurrentTabs: (tabs: Record<string, InstanceTab[]>) => void;
+ setCurrentMemory: (memory: Record<string, number>) => void;
// Agents
agents: Agent[];
@@ -76,12 +85,19 @@ export const useAppStore = create<AppState>((set) => ({
// Chart data
tabsChartData: [],
+ memoryChartData: [],
currentTabs: {},
+ currentMemory: {},
addChartDataPoint: (point) =>
set((state) => ({
tabsChartData: [...state.tabsChartData.slice(-59), point], // Keep last 60 points
})),
+ addMemoryDataPoint: (point) =>
+ set((state) => ({
+ memoryChartData: [...state.memoryChartData.slice(-59), point], // Keep last 60 points
+ })),
setCurrentTabs: (currentTabs) => set({ currentTabs }),
+ setCurrentMemory: (currentMemory) => set({ currentMemory }),
// Agents
agents: [],
diff --git a/internal/api/types/types.go b/internal/api/types/types.go
index 7daab655..09d98461 100644
--- a/internal/api/types/types.go
+++ b/internal/api/types/types.go
@@ -111,6 +111,18 @@ type InstanceTab struct {
Title string `json:"title"`
}
+// InstanceMetrics represents memory metrics for an instance.
+type InstanceMetrics struct {
+ InstanceID string `json:"instanceId"`
+ ProfileName string `json:"profileName"`
+ JSHeapUsedMB float64 `json:"jsHeapUsedMB"`
+ JSHeapTotalMB float64 `json:"jsHeapTotalMB"`
+ Documents int64 `json:"documents"`
+ Frames int64 `json:"frames"`
+ Nodes int64 `json:"nodes"`
+ Listeners int64 `json:"listeners"`
+}
+
// LaunchInstanceRequest is the request body for launching an instance.
type LaunchInstanceRequest struct {
ProfileID string `json:"profileId,omitempty"` // profile ID (prof_XXXXXXXX)
diff --git a/internal/bridge/api.go b/internal/bridge/api.go
index ee9f4afe..25161d17 100644
--- a/internal/bridge/api.go
+++ b/internal/bridge/api.go
@@ -31,6 +31,10 @@ type BridgeAPI interface {
Unlock(tabID, owner string) error
EnsureChrome(cfg *config.RuntimeConfig) error
+
+ // Memory metrics
+ GetMemoryMetrics(tabID string) (*MemoryMetrics, error)
+ GetBrowserMemoryMetrics() (*MemoryMetrics, error)
}
type LockInfo struct {
diff --git a/internal/bridge/metrics.go b/internal/bridge/metrics.go
new file mode 100644
index 00000000..4d204053
--- /dev/null
+++ b/internal/bridge/metrics.go
@@ -0,0 +1,72 @@
+package bridge
+
+import (
+ "context"
+
+ "github.com/chromedp/cdproto/performance"
+ "github.com/chromedp/chromedp"
+)
+
+// MemoryMetrics holds Chrome memory statistics
+type MemoryMetrics struct {
+ JSHeapUsedMB float64 `json:"jsHeapUsedMB"`
+ JSHeapTotalMB float64 `json:"jsHeapTotalMB"`
+ Documents int64 `json:"documents"`
+ Frames int64 `json:"frames"`
+ Nodes int64 `json:"nodes"`
+ Listeners int64 `json:"listeners"`
+}
+
+// GetMemoryMetrics retrieves memory metrics for a specific tab
+func (b *Bridge) GetMemoryMetrics(tabID string) (*MemoryMetrics, error) {
+ ctx, _, err := b.TabContext(tabID)
+ if err != nil {
+ return nil, err
+ }
+
+ return getMetricsFromContext(ctx)
+}
+
+// GetBrowserMemoryMetrics retrieves memory metrics for the entire browser
+func (b *Bridge) GetBrowserMemoryMetrics() (*MemoryMetrics, error) {
+ if b.BrowserCtx == nil {
+ return nil, nil
+ }
+ return getMetricsFromContext(b.BrowserCtx)
+}
+
+func getMetricsFromContext(ctx context.Context) (*MemoryMetrics, error) {
+ // Enable performance metrics collection
+ if err := chromedp.Run(ctx, performance.Enable()); err != nil {
+ return nil, err
+ }
+
+ var metrics []*performance.Metric
+ if err := chromedp.Run(ctx, chromedp.ActionFunc(func(ctx context.Context) error {
+ var err error
+ metrics, err = performance.GetMetrics().Do(ctx)
+ return err
+ })); err != nil {
+ return nil, err
+ }
+
+ result := &MemoryMetrics{}
+ for _, m := range metrics {
+ switch m.Name {
+ case "JSHeapUsedSize":
+ result.JSHeapUsedMB = m.Value / (1024 * 1024)
+ case "JSHeapTotalSize":
+ result.JSHeapTotalMB = m.Value / (1024 * 1024)
+ case "Documents":
+ result.Documents = int64(m.Value)
+ case "Frames":
+ result.Frames = int64(m.Value)
+ case "Nodes":
+ result.Nodes = int64(m.Value)
+ case "JSEventListeners":
+ result.Listeners = int64(m.Value)
+ }
+ }
+
+ return result, nil
+}
diff --git a/internal/handlers/handlers.go b/internal/handlers/handlers.go
index 108b6200..521654e9 100644
--- a/internal/handlers/handlers.go
+++ b/internal/handlers/handlers.go
@@ -47,6 +47,7 @@ func (h *Handlers) RegisterRoutes(mux *http.ServeMux, doShutdown func()) {
mux.HandleFunc("POST /tabs/{id}/actions", h.HandleTabActions)
mux.HandleFunc("GET /tabs/{id}/text", h.HandleTabText)
mux.HandleFunc("POST /tabs/{id}/evaluate", h.HandleTabEvaluate)
+ mux.HandleFunc("GET /tabs/{id}/metrics", h.HandleTabMetrics)
mux.HandleFunc("GET /metrics", h.HandleMetrics)
mux.HandleFunc("GET /snapshot", h.HandleSnapshot)
mux.HandleFunc("GET /screenshot", h.HandleScreenshot)
diff --git a/internal/handlers/health_tabs.go b/internal/handlers/health_tabs.go
index 92302685..90b54be6 100644
--- a/internal/handlers/health_tabs.go
+++ b/internal/handlers/health_tabs.go
@@ -39,7 +39,37 @@ func (h *Handlers) HandleEnsureChrome(w http.ResponseWriter, r *http.Request) {
}
func (h *Handlers) HandleMetrics(w http.ResponseWriter, r *http.Request) {
- web.JSON(w, 200, map[string]any{"metrics": snapshotMetrics()})
+ result := map[string]any{"metrics": snapshotMetrics()}
+
+ // Add browser memory metrics if available
+ if h.Bridge != nil {
+ if mem, err := h.Bridge.GetBrowserMemoryMetrics(); err == nil && mem != nil {
+ result["memory"] = mem
+ }
+ }
+
+ web.JSON(w, 200, result)
+}
+
+func (h *Handlers) HandleTabMetrics(w http.ResponseWriter, r *http.Request) {
+ tabID := r.PathValue("id")
+ if tabID == "" {
+ web.Error(w, 400, fmt.Errorf("missing tab id"))
+ return
+ }
+
+ if h.Bridge == nil {
+ web.Error(w, 503, fmt.Errorf("bridge not initialized"))
+ return
+ }
+
+ mem, err := h.Bridge.GetMemoryMetrics(tabID)
+ if err != nil {
+ web.Error(w, 500, fmt.Errorf("failed to get metrics: %w", err))
+ return
+ }
+
+ web.JSON(w, 200, mem)
}
func (h *Handlers) HandleTabs(w http.ResponseWriter, r *http.Request) {
diff --git a/internal/orchestrator/handlers.go b/internal/orchestrator/handlers.go
index e012fa2d..6fea182f 100644
--- a/internal/orchestrator/handlers.go
+++ b/internal/orchestrator/handlers.go
@@ -16,6 +16,7 @@ func (o *Orchestrator) RegisterHandlers(mux *http.ServeMux) {
mux.HandleFunc("GET /instances", o.handleList)
mux.HandleFunc("GET /instances/{id}", o.handleGetInstance)
mux.HandleFunc("GET /instances/tabs", o.handleAllTabs)
+ mux.HandleFunc("GET /instances/metrics", o.handleAllMetrics)
mux.HandleFunc("POST /instances/start", o.handleStartInstance)
mux.HandleFunc("POST /instances/launch", o.handleLaunchByName)
mux.HandleFunc("POST /instances/{id}/start", o.handleStartByInstanceID)
@@ -60,3 +61,7 @@ func (o *Orchestrator) handleList(w http.ResponseWriter, r *http.Request) {
func (o *Orchestrator) handleAllTabs(w http.ResponseWriter, r *http.Request) {
web.JSON(w, 200, o.AllTabs())
}
+
+func (o *Orchestrator) handleAllMetrics(w http.ResponseWriter, r *http.Request) {
+ web.JSON(w, 200, o.AllMetrics())
+}
diff --git a/internal/orchestrator/health.go b/internal/orchestrator/health.go
index 21501e29..595e8d82 100644
--- a/internal/orchestrator/health.go
+++ b/internal/orchestrator/health.go
@@ -129,6 +129,19 @@ type remoteTab struct {
Title string `json:"title"`
}
+type remoteMetrics struct {
+ Memory *memoryMetrics `json:"memory,omitempty"`
+}
+
+type memoryMetrics struct {
+ JSHeapUsedMB float64 `json:"jsHeapUsedMB"`
+ JSHeapTotalMB float64 `json:"jsHeapTotalMB"`
+ Documents int64 `json:"documents"`
+ Frames int64 `json:"frames"`
+ Nodes int64 `json:"nodes"`
+ Listeners int64 `json:"listeners"`
+}
+
func (o *Orchestrator) fetchTabs(baseURL string) ([]remoteTab, error) {
req, err := http.NewRequest(http.MethodGet, baseURL+"/screencast/tabs", nil)
if err != nil {
@@ -151,6 +164,32 @@ func (o *Orchestrator) fetchTabs(baseURL string) ([]remoteTab, error) {
return tabs, nil
}
+func (o *Orchestrator) fetchMetrics(baseURL string) (*memoryMetrics, error) {
+ req, err := http.NewRequest(http.MethodGet, baseURL+"/metrics", nil)
+ if err != nil {
+ return nil, err
+ }
+ if o.childAuthToken != "" {
+ req.Header.Set("Authorization", "Bearer "+o.childAuthToken)
+ }
+
+ resp, err := o.client.Do(req)
+ if err != nil {
+ return nil, err
+ }
+ defer func() { _ = resp.Body.Close() }()
+
+ if resp.StatusCode != 200 {
+ return nil, nil
+ }
+
+ var result remoteMetrics
+ if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
+ return nil, err
+ }
+ return result.Memory, nil
+}
+
func isInstanceHealthyStatus(code int) bool {
return code > 0 && code < http.StatusInternalServerError
}
diff --git a/internal/orchestrator/orchestrator.go b/internal/orchestrator/orchestrator.go
index b468053c..07c2b5d3 100644
--- a/internal/orchestrator/orchestrator.go
+++ b/internal/orchestrator/orchestrator.go
@@ -14,6 +14,7 @@ import (
"sync"
"time"
+ "github.com/pinchtab/pinchtab/internal/api/types"
"github.com/pinchtab/pinchtab/internal/bridge"
"github.com/pinchtab/pinchtab/internal/idutil"
"github.com/pinchtab/pinchtab/internal/profiles"
@@ -469,6 +470,36 @@ func (o *Orchestrator) AllTabs() []bridge.InstanceTab {
return all
}
+func (o *Orchestrator) AllMetrics() []types.InstanceMetrics {
+ o.mu.RLock()
+ instances := make([]*InstanceInternal, 0)
+ for _, inst := range o.instances {
+ if inst.Status == "running" && instanceIsActive(inst) {
+ instances = append(instances, inst)
+ }
+ }
+ o.mu.RUnlock()
+
+ var all []types.InstanceMetrics
+ for _, inst := range instances {
+ mem, err := o.fetchMetrics(inst.URL)
+ if err != nil || mem == nil {
+ continue
+ }
+ all = append(all, types.InstanceMetrics{
+ InstanceID: inst.ID,
+ ProfileName: inst.ProfileName,
+ JSHeapUsedMB: mem.JSHeapUsedMB,
+ JSHeapTotalMB: mem.JSHeapTotalMB,
+ Documents: mem.Documents,
+ Frames: mem.Frames,
+ Nodes: mem.Nodes,
+ Listeners: mem.Listeners,
+ })
+ }
+ return all
+}
+
func (o *Orchestrator) ScreencastURL(instanceID, tabID string) string {
o.mu.RLock()
defer o.mu.RUnlock()