Raw
1 import { InlineIcon, Note, Table } from "docs-ui"
2 import { ArrowPath } from "@medusajs/icons"
3
4 export const metadata = {
5 title: `Worker Monitoring`,
6 }
7
8 # {metadata.title}
9
10 In this guide, you'll learn how to monitor your environment's workers performance in Cloud.
11
12 <Note>
13
14 The Workers monitoring page covers the performance of your environment's worker instances, which handle background jobs. To monitor the performance of your environment's server instances, check the [Servers monitoring page](../servers/page.mdx).
15
16 </Note>
17
18 ## Worker Metrics Overview
19
20 For your [long-lived environments](../../environments/long-lived/page.mdx), Medusa hosts server and worker instances. Worker instances handle background jobs, such as subscribers and scheduled jobs.
21
22 The Workers monitoring dashboard provides insights into the performance of your worker instances, allowing you to track key metrics such as CPU usage, memory usage, and restarts.
23
24 By monitoring these metrics, you ensure that your workers are performing optimally or identify potential issues in your background jobs' implementation.
25
26 ---
27
28 ## Troubleshooting Common Worker Issues
29
30 The following table outlines common worker performance issues, their potential causes, and the specific metrics you can monitor to identify and troubleshoot these issues effectively.
31
32 <Table>
33 <Table.Header>
34 <Table.Row>
35 <Table.HeaderCell>
36 Issue
37 </Table.HeaderCell>
38 <Table.HeaderCell>
39 Potential Cause
40 </Table.HeaderCell>
41 <Table.HeaderCell>
42 Metric to Check
43 </Table.HeaderCell>
44 </Table.Row>
45 </Table.Header>
46 <Table.Body>
47 <Table.Row>
48 <Table.Cell>
49 Background jobs slow or not executing
50 </Table.Cell>
51 <Table.Cell>
52 High CPU usage in worker instances due to inefficient background job implementation.
53 </Table.Cell>
54 <Table.Cell>
55 [Total CPU](#monitor-total-cpu) and [Summary of CPU Usage Across Workers](#monitor-summary-of-cpu-usage-across-workers)
56 </Table.Cell>
57 </Table.Row>
58 <Table.Row>
59 <Table.Cell>
60 Background jobs failing intermittently
61 </Table.Cell>
62 <Table.Cell>
63 Memory leaks or insufficient memory causing workers to become unstable.
64 </Table.Cell>
65 <Table.Cell>
66 [Summary of Memory Usage Across Workers](#monitor-summary-of-memory-usage-across-workers)
67 </Table.Cell>
68 </Table.Row>
69 <Table.Row>
70 <Table.Cell>
71 Frequent worker restarts
72 </Table.Cell>
73 <Table.Cell>
74 Crashes caused by unhandled exceptions or out-of-memory conditions in background jobs.
75 </Table.Cell>
76 <Table.Cell>
77 [Worker Restarts](#monitor-worker-restarts) and [Summary of Memory Usage Across Workers](#monitor-summary-of-memory-usage-across-workers)
78 </Table.Cell>
79 </Table.Row>
80 <Table.Row>
81 <Table.Cell>
82 Uneven load distribution across worker instances
83 </Table.Cell>
84 <Table.Cell>
85 Specific worker instances handling more jobs than others.
86 </Table.Cell>
87 <Table.Cell>
88 [Summary of CPU Usage Across Workers](#monitor-summary-of-cpu-usage-across-workers) and [Summary of Memory Usage Across Workers](#monitor-summary-of-memory-usage-across-workers)
89 </Table.Cell>
90 </Table.Row>
91 <Table.Row>
92 <Table.Cell>
93 High [Flex Usage](../../usage/page.mdx#what-is-flex-usage)
94 </Table.Cell>
95 <Table.Cell>
96 Excessive CPU or memory consumption in worker instances due to inefficient background job code.
97 </Table.Cell>
98 <Table.Cell>
99 [Total CPU](#monitor-total-cpu) and [Summary of Memory Usage Across Workers](#monitor-summary-of-memory-usage-across-workers)
100 </Table.Cell>
101 </Table.Row>
102 </Table.Body>
103 </Table>
104
105 <Note>
106
107 If the metrics don't show a cause related to your application, [check the Cloud status page](../../status/page.mdx) for ongoing Cloud incidents that may be affecting your environment.
108
109 </Note>
110
111 ---
112
113 ## View Worker Metrics
114
115 To view your project environment's worker performance:
116
117 1. Go to the [environment's dashboard](../../environments/long-lived/page.mdx#open-environment-dashboard).
118 2. Click **Monitoring** > **Workers** in the sidebar.
119
120 This opens the Workers monitoring dashboard, where you can analyze your environment's worker performance across any time range.
121
122 ### Change Time Range
123
124 By default, the dashboard shows metrics for the last hour. To change the time range:
125
126 1. Click on the time range selector at the top right of the dashboard.
127 2. Either choose a preset time range (for example, last 24 hours) or set a custom time range.
128
129 The charts will update to show metrics for the selected time range, allowing you to analyze performance trends and patterns over different periods.
130
131 ### Refresh Metrics
132
133 To refresh the metrics displayed on the dashboard, click the <InlineIcon Icon={ArrowPath} alt="refresh" /> button.
134
135 The metrics will refresh to show the most up-to-date performance data for your environment's workers in the selected time range.
136
137 ---
138
139 ## Monitor Total CPU
140
141 The Total CPU usage of your environment shows combined CPU allocation and usage across all worker replicas of your environment. It's useful to understand their overall CPU resource consumption and identify trends or spikes in usage.
142
143 In the [Workers monitoring dashboard](#view-worker-metrics), the Total CPU chart shows:
144
145 - **Allocated CPU** (blue): The total CPU resources allocated to your workers.
146 - **Used CPU** (green): The actual CPU resources being consumed by your workers.
147
148 If your environment's background jobs are slow or not executing, check if the Used CPU is consistently close to or exceeding the Allocated CPU, which may indicate the need for performance improvements in your background jobs' implementation.
149
150 ---
151
152 ## Monitor Summary of CPU Usage Across Workers
153
154 The Summary of CPU usage across Workers of your environment shows CPU usage patterns across individual worker instances.
155
156 In the [Workers monitoring dashboard](#view-worker-metrics), the Summary of CPU chart shows:
157
158 - **Minimum CPU**: The lowest CPU percentage used by a worker instance at a given time.
159 - **Maximum CPU**: The highest CPU percentage used by a worker instance at a given time.
160 - **Average CPU**: The mean CPU usage across all worker instances at a given time.
161
162 This breakdown helps you identify peaks in CPU usage across your worker instances and determine if specific instances are under heavy load or if CPU usage is evenly distributed across your infrastructure.
163
164 ---
165
166 ## Monitor Summary of Memory Usage Across Workers
167
168 The Summary of Memory usage across Workers of your environment shows memory consumption patterns across individual worker instances.
169
170 In the [Workers monitoring dashboard](#view-worker-metrics), the Summary of Memory chart shows:
171
172 - **Minimum Memory**: The lowest memory percentage used across instances at a given time.
173 - **Maximum Memory**: The highest memory percentage used across instances at a given time.
174 - **Average Memory**: The mean memory usage across all instances at a given time.
175
176 This breakdown helps you identify if specific worker instances are consuming excessive memory or if memory usage is consistent across your infrastructure.
177
178 ---
179
180 ## Monitor Worker Restarts
181
182 The Worker Restarts section helps you track the frequency and patterns of unexpected worker restarts in your environment. Frequent or unexpected restarts can indicate underlying issues with your application's background jobs, such as crashes and memory leaks.
183
184 In the [Workers monitoring dashboard](#view-worker-metrics), the Worker Restarts chart shows the number of restarts across your worker instances over time.
185
186 You can also correlate restart patterns with CPU and memory usage to identify potential causes of instability in your environment.