[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"academy-blogs-en-1-1-all-websocket-monitoring-metrics-production-all--*":3,"academy-blog-translations-42pwzlod5lq9vxp":94},{"data":4,"page":82,"perPage":82,"totalItems":82,"totalPages":82},[5],{"alt":6,"collectionId":7,"collectionName":8,"content":9,"cover_image":10,"cover_image_path":11,"created":12,"created_by":13,"expand":14,"id":89,"keywords":90,"locale":64,"published_at":91,"scheduled_at":13,"school_blog":86,"short_description":92,"status":84,"title":6,"updated":93,"updated_by":13,"slug":87,"views":88},"EP.106 Monitoring & Metrics for WebSocket Production","sclblg987654321","school_blog_translations","\u003Cp>When your WebSocket Server enters the production level, looking at logs alone is no longer enough you need Monitoring &amp; Metrics to view your system’s “health” in real time.\u003C\u002Fp>\u003Cp>&nbsp;\u003C\u002Fp>\u003Cp>✅ Number of active connections\u003Cbr>✅ Volume of sent\u002Freceived messages\u003Cbr>✅ CPU, Memory, and Bandwidth usage\u003Cbr>✅ Disconnection rate\u003C\u002Fp>\u003Cp>&nbsp;\u003C\u002Fp>\u003Cp>The most popular tools for this job are Prometheus + Grafana, which help you:\u003C\u002Fp>\u003Cul>\u003Cli>Visualize the system overview in real time\u003C\u002Fli>\u003Cli>Detect bottlenecks before users notice\u003Cbr>🚀 And confidently prepare for system scaling\u003C\u002Fli>\u003C\u002Ful>\u003Cp>&nbsp;\u003C\u002Fp>\u003Ch2>🔹 1. Why is Monitoring important for WebSocket?\u003C\u002Fh2>\u003Cp>&nbsp;\u003C\u002Fp>\u003Cp>WebSocket is different from traditional HTTP — it’s a persistent connection.\u003Cbr>Without proper monitoring, you may never know:\u003C\u002Fp>\u003Cul>\u003Cli>Which connections are still “alive”\u003C\u002Fli>\u003Cli>Whether resources are being overused\u003C\u002Fli>\u003Cli>If the system is about to crash from unexpected traffic spikes\u003C\u002Fli>\u003C\u002Ful>\u003Cp>&nbsp;\u003C\u002Fp>\u003Cp>🔍 Examples of key metrics:\u003C\u002Fp>\u003Cfigure class=\"table\">\u003Ctable>\u003Cthead>\u003Ctr>\u003Cth>Metric\u003C\u002Fth>\u003Cth>Meaning\u003C\u002Fth>\u003C\u002Ftr>\u003C\u002Fthead>\u003Ctbody>\u003Ctr>\u003Ctd>Active Connections\u003C\u002Ftd>\u003Ctd>Number of currently open connections\u003C\u002Ftd>\u003C\u002Ftr>\u003Ctr>\u003Ctd>Message Rate\u003C\u002Ftd>\u003Ctd>Sent\u002Freceived messages per second\u003C\u002Ftd>\u003C\u002Ftr>\u003Ctr>\u003Ctd>Error Rate\u003C\u002Ftd>\u003Ctd>Number of occurred errors\u003C\u002Ftd>\u003C\u002Ftr>\u003Ctr>\u003Ctd>Connection Lifetime\u003C\u002Ftd>\u003Ctd>Duration of each connection\u003C\u002Ftd>\u003C\u002Ftr>\u003Ctr>\u003Ctd>CPU \u002F Memory Usage\u003C\u002Ftd>\u003Ctd>Resource usage of the server\u003C\u002Ftd>\u003C\u002Ftr>\u003C\u002Ftbody>\u003C\u002Ftable>\u003C\u002Ffigure>\u003Cp>&nbsp;\u003C\u002Fp>\u003Ch2>🧩 2. Installing Prometheus to Collect WebSocket Metrics\u003C\u002Fh2>\u003Cp>&nbsp;\u003C\u002Fp>\u003Cp>Prometheus pulls metrics data from endpoints like \u003Ccode inline=\"\">\u002Fmetrics\u003C\u002Fcode> via HTTP GET.\u003C\u002Fp>\u003Cp>&nbsp;\u003C\u002Fp>\u003Cp>🔧 Sample Go Code:\u003C\u002Fp>\u003Cpre>\u003Ccode class=\"language-plaintext language-go\">import (\n\t\"net\u002Fhttp\"\n\t\"github.com\u002Fgorilla\u002Fwebsocket\"\n\t\"github.com\u002Fprometheus\u002Fclient_golang\u002Fprometheus\"\n\t\"github.com\u002Fprometheus\u002Fclient_golang\u002Fprometheus\u002Fpromhttp\"\n)\n\nvar upgrader = websocket.Upgrader{CheckOrigin: func(r *http.Request) bool { return true }}\n\nvar (\n\tactiveConnections = prometheus.NewGauge(prometheus.GaugeOpts{\n\t\tName: \"websocket_active_connections\",\n\t\tHelp: \"Number of active WebSocket connections\",\n\t})\n\tmessageCounter = prometheus.NewCounter(prometheus.CounterOpts{\n\t\tName: \"websocket_message_total\",\n\t\tHelp: \"Total messages received\",\n\t})\n)\n\nfunc init() {\n\tprometheus.MustRegister(activeConnections)\n\tprometheus.MustRegister(messageCounter)\n}\n\nfunc handleConnection(w http.ResponseWriter, r *http.Request) {\n\tconn, _ := upgrader.Upgrade(w, r, nil)\n\tdefer conn.Close()\n\n\tactiveConnections.Inc()\n\tdefer activeConnections.Dec()\n\n\tfor {\n\t\t_, msg, err := conn.ReadMessage()\n\t\tif err != nil {\n\t\t\tbreak\n\t\t}\n\t\tmessageCounter.Inc()\n\t}\n}\n\nfunc main() {\n\thttp.HandleFunc(\"\u002Fws\", handleConnection)\n\thttp.Handle(\"\u002Fmetrics\", promhttp.Handler())\n\thttp.ListenAndServe(\":8080\", nil)\n}\n\u003C\u002Fcode>\u003C\u002Fpre>\u003Cp>&nbsp;\u003C\u002Fp>\u003Ch2>🧭 3. Visualizing Metrics with Grafana\u003C\u002Fh2>\u003Cp>&nbsp;\u003C\u002Fp>\u003Cp>Grafana is a powerful visualization tool that easily connects to Prometheus.\u003C\u002Fp>\u003Cp>&nbsp;\u003C\u002Fp>\u003Cp>🔍 Recommended Dashboards:\u003C\u002Fp>\u003Cul>\u003Cli>📊 Active Connections (Real-time Graph)\u003C\u002Fli>\u003Cli>🔄 Message Rate (sent\u002Freceived per second)\u003C\u002Fli>\u003Cli>⚠️ Error Rate (Pie Chart)\u003C\u002Fli>\u003Cli>💻 CPU \u002F Memory Usage (Stacked Graph)\u003C\u002Fli>\u003C\u002Ful>\u003Cp>&nbsp;\u003C\u002Fp>\u003Cp>📈 These dashboards help you:\u003C\u002Fp>\u003Cul>\u003Cli>Instantly spot bottlenecks\u003C\u002Fli>\u003Cli>Make accurate scaling decisions\u003C\u002Fli>\u003C\u002Ful>\u003Cp>&nbsp;\u003C\u002Fp>\u003Ch2>⚙️ 4. Key Metrics for Production Systems\u003C\u002Fh2>\u003Cp>&nbsp;\u003C\u002Fp>\u003Cfigure class=\"table\">\u003Ctable>\u003Cthead>\u003Ctr>\u003Cth>Category\u003C\u002Fth>\u003Cth>Metric\u003C\u002Fth>\u003Cth>Purpose\u003C\u002Fth>\u003C\u002Ftr>\u003C\u002Fthead>\u003Ctbody>\u003Ctr>\u003Ctd>Performance\u003C\u002Ftd>\u003Ctd>Message rate\u003C\u002Ftd>\u003Ctd>Detect latency\u002Fload issues\u003C\u002Ftd>\u003C\u002Ftr>\u003Ctr>\u003Ctd>Reliability\u003C\u002Ftd>\u003Ctd>Connection errors\u003C\u002Ftd>\u003Ctd>Prevent crashes\u003C\u002Ftd>\u003C\u002Ftr>\u003Ctr>\u003Ctd>Resource\u003C\u002Ftd>\u003Ctd>CPU\u002FMemory usage\u003C\u002Ftd>\u003Ctd>Control resource consumption\u003C\u002Ftd>\u003C\u002Ftr>\u003Ctr>\u003Ctd>Scalability\u003C\u002Ftd>\u003Ctd>Connection count\u003C\u002Ftd>\u003Ctd>Plan for scaling\u003C\u002Ftd>\u003C\u002Ftr>\u003Ctr>\u003Ctd>Stability\u003C\u002Ftd>\u003Ctd>Uptime \u002F Reconnect\u003C\u002Ftd>\u003Ctd>Indicate system stability\u003C\u002Ftd>\u003C\u002Ftr>\u003C\u002Ftbody>\u003C\u002Ftable>\u003C\u002Ffigure>\u003Cp>&nbsp;\u003C\u002Fp>\u003Ch2>🧠 5. Best Practices for Monitoring in Production\u003C\u002Fh2>\u003Cp>&nbsp;\u003C\u002Fp>\u003Cp>✅ Separate metrics by instance \u002F region → for accurate load analysis\u003Cbr>✅ Set alert rules (e.g., Active Conn. &gt; 10,000)\u003Cbr>✅ Track daily trends → to prevent silent system failure\u003Cbr>✅ Store logs alongside metrics → for precise cross-analysis\u003C\u002Fp>\u003Cp>&nbsp;\u003C\u002Fp>\u003Ch2>🚀 Challenge!\u003C\u002Fh2>\u003Cp>&nbsp;\u003C\u002Fp>\u003Cp>Just by adding a \u003Ccode inline=\"\">\u002Fmetrics\u003C\u002Fcode> endpoint and connecting Grafana, you’ll instantly see every behavior of your WebSocket Server in real-time — helping you:\u003C\u002Fp>\u003Cul>\u003Cli>Troubleshoot faster\u003C\u002Fli>\u003Cli>Confidently scale your system\u003C\u002Fli>\u003Cli>Build a production-ready system 🔧\u003C\u002Fli>\u003C\u002Ful>\u003Cp>&nbsp;\u003C\u002Fp>\u003Chr>\u003Cp>&nbsp;\u003C\u002Fp>\u003Ch2>🌟 Next EP:\u003C\u002Fh2>\u003Cp>&nbsp;\u003C\u002Fp>\u003Cp>📘 EP.107: Profiling and Benchmarking WebSocket Server\u003Cbr>A deep dive into measuring WebSocket performance using \u003Ccode inline=\"\">pprof\u003C\u002Fcode>, \u003Ccode inline=\"\">wrk\u003C\u002Fcode>, and \u003Ccode inline=\"\">hey\u003C\u002Fcode>, along with real-world optimization techniques for production systems! ⚡\u003C\u002Fp>\u003Cp>&nbsp;\u003C\u002Fp>\u003Cp data-start=\"498\" data-end=\"834\">\u003Cstrong>Read more\u003C\u002Fstrong>\u003C\u002Fp>\u003Cul>\u003Cli>\u003Cp data-start=\"498\" data-end=\"834\">\u003Ca target=\"_blank\" rel=\"noopener noreferrer\" href=\"https:\u002F\u002Fwww.superdev.school\u002Fblogs\u002Fcategories\u002FGolang\">\u003Cstrong>Golang The Series\u003C\u002Fstrong>\u003C\u002Fa>\u003C\u002Fp>\u003C\u002Fli>\u003Cli>\u003Cp data-start=\"498\" data-end=\"834\">\u003Ca target=\"_blank\" rel=\"noopener noreferrer\" href=\"https:\u002F\u002Fwww.superdev.school\u002Fblogs\u002Fcategories\u002FJS2GO\">\u003Cstrong>JS2GO\u003C\u002Fstrong>\u003C\u002Fa>\u003C\u002Fp>\u003C\u002Fli>\u003Cli>\u003Cp data-start=\"498\" data-end=\"834\">\u003Ca target=\"_blank\" rel=\"noopener noreferrer\" href=\"https:\u002F\u002Fwww.superdev.school\u002Fen\u002Fblogs\u002Fcategories\u002FTailwind%20CSS\">\u003Cstrong>10 Eps That Will Make You a Pro Tailwind CSS Overnight\u003C\u002Fstrong>\u003C\u002Fa>\u003C\u002Fp>\u003C\u002Fli>\u003C\u002Ful>\u003Cp>\u003Cstrong>🔵 Facebook: \u003C\u002Fstrong>\u003Ca target=\"_blank\" rel=\"noopener noreferrer\" href=\"https:\u002F\u002Fwww.facebook.com\u002Fsuperdev.academy.th\">\u003Cstrong>Superdev Academy\u003C\u002Fstrong>\u003C\u002Fa>\u003C\u002Fp>\u003Cp>\u003Cstrong>🔴 YouTube: \u003C\u002Fstrong>\u003Ca target=\"_blank\" rel=\"noopener noreferrer\" href=\"https:\u002F\u002Fwww.youtube.com\u002Fchannel\u002FUC2eI2RxcA2zbTqZyHyWIfRg\">\u003Cstrong>Superdev Academy\u003C\u002Fstrong>\u003C\u002Fa>\u003C\u002Fp>\u003Cp>\u003Cstrong>📸 Instagram: \u003C\u002Fstrong>\u003Ca target=\"_blank\" rel=\"noopener noreferrer\" href=\"https:\u002F\u002Fwww.instagram.com\u002Fsuperdevschool\u002F\">\u003Cstrong>Superdev Academy\u003C\u002Fstrong>\u003C\u002Fa>\u003C\u002Fp>\u003Cp>\u003Cstrong>🎬 TikTok: \u003C\u002Fstrong>\u003Ca target=\"_blank\" rel=\"noopener noreferrer\" href=\"https:\u002F\u002Fwww.tiktok.com\u002F@superdevacademy?lang=th-TH\">\u003Cstrong>https:\u002F\u002Fwww.tiktok.com\u002F@superdevacademy?lang=th-TH\u003C\u002Fstrong>\u003C\u002Fa>\u003C\u002Fp>\u003Cp>\u003Cstrong>🌐 Website: \u003C\u002Fstrong>\u003Ca target=\"_blank\" rel=\"noopener noreferrer\" href=\"https:\u002F\u002Fwww.superdevacademy.com\u002Fen\">\u003Cstrong>https:\u002F\u002Fwww.superdevacademy.com\u002Fen\u003C\u002Fstrong>\u003C\u002Fa>\u003Cstrong>&nbsp;\u003C\u002Fstrong>\u003C\u002Fp>","184_11zon_a9hh891s7p.webp","https:\u002F\u002Ftwsme-r2.tumwebsme.com\u002Fsclblg987654321\u002Fce0u0llzfr8ef1e\u002F184_11zon_a9hh891s7p.webp","2026-03-04 08:45:38.620Z","",{"keywords":15,"locale":58,"school_blog":68},[16,23,28,33,38,43,48,53],{"collectionId":17,"collectionName":18,"created":19,"created_by":13,"id":20,"name":21,"updated":22,"updated_by":13},"sclkey987654321","school_keywords","2026-03-04 08:44:49.054Z","vbjgbr5ah0kh43p","Real-time System","2026-04-10 16:12:50.311Z",{"collectionId":17,"collectionName":18,"created":24,"created_by":13,"id":25,"name":26,"updated":27,"updated_by":13},"2026-03-04 08:45:37.661Z","xjf08drjt5em75b","Metrics","2026-04-10 16:13:00.679Z",{"collectionId":17,"collectionName":18,"created":29,"created_by":13,"id":30,"name":31,"updated":32,"updated_by":13},"2026-03-04 08:44:47.385Z","li4cs2v3atd0wds","Production","2026-04-10 16:12:49.890Z",{"collectionId":17,"collectionName":18,"created":34,"created_by":13,"id":35,"name":36,"updated":37,"updated_by":13},"2026-03-04 08:20:11.547Z","ey3puyme01a9bsw","Go","2026-04-10 16:07:25.893Z",{"collectionId":17,"collectionName":18,"created":39,"created_by":13,"id":40,"name":41,"updated":42,"updated_by":13},"2026-03-04 08:45:37.995Z","1v2heky8yo3cwww","Grafana","2026-04-10 16:13:00.771Z",{"collectionId":17,"collectionName":18,"created":44,"created_by":13,"id":45,"name":46,"updated":47,"updated_by":13},"2026-03-04 08:45:38.382Z","8uz7io97gj0jusq","Prometheus","2026-04-10 16:13:00.871Z",{"collectionId":17,"collectionName":18,"created":49,"created_by":13,"id":50,"name":51,"updated":52,"updated_by":13},"2026-03-04 08:44:34.571Z","fiybaq65m7oymtd","Monitoring","2026-04-10 16:12:46.904Z",{"collectionId":17,"collectionName":18,"created":54,"created_by":13,"id":55,"name":56,"updated":57,"updated_by":13},"2026-03-04 08:34:00.920Z","ecac9y661or1xka","WebSocket","2026-04-10 16:08:05.227Z",{"code":59,"collectionId":60,"collectionName":61,"created":62,"flag":63,"id":64,"is_default":65,"label":66,"updated":67},"en","pbc_1989393366","locales","2026-01-22 11:00:02.726Z","twemoji:flag-united-states","qv9c1llfov2d88z",false,"English","2026-04-10 15:42:46.825Z",{"category":69,"collectionId":70,"collectionName":71,"created":13,"expand":72,"id":86,"slug":87,"updated":13,"views":88},"wqxt7ag2gn7xcmk","pbc_2105096300","school_blogs",{"category":73},{"blogIds":74,"collectionId":75,"collectionName":76,"created":77,"created_by":13,"id":69,"image":78,"image_alt":13,"image_path":79,"label":80,"name":81,"priority":82,"publish_at":83,"scheduled_at":13,"status":84,"updated":85,"updated_by":13},[],"sclcatblg987654321","school_category_blogs","2026-03-04 08:33:53.210Z","59ty92ns80w_15oc1implw.png","https:\u002F\u002Ftwsme-r2.tumwebsme.com\u002Fsclcatblg987654321\u002Fwqxt7ag2gn7xcmk\u002F59ty92ns80w_15oc1implw.png",{"en":81,"th":81},"Golang The Series",1,"2026-03-16 04:39:38.440Z","published","2026-04-25 02:32:15.470Z","42pwzlod5lq9vxp","websocket-monitoring-metrics-production",228,"ce0u0llzfr8ef1e",[20,25,30,35,40,45,50,55],"2025-11-10 02:39:41.391Z","When your WebSocket Server goes into production, logs alone aren't enough! Learn how to use Prometheus and Grafana to monitor your system health in real-time, with real Go code examples.","2026-05-06 08:38:03.580Z",{"th":87,"en":87}]