{"id":247845,"date":"2022-07-27T10:34:26","date_gmt":"2022-07-27T02:34:26","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=247845"},"modified":"2022-07-22T10:39:07","modified_gmt":"2022-07-22T02:39:07","slug":"microservice-monitoring","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/microservice-monitoring.html","title":{"rendered":"\u600e\u6837\u76d1\u6d4b\u5fae\u578b\u7684\u7f51\u7ad9\u670d\u52a1"},"content":{"rendered":"
\u5bfc\u8bfb<\/td>\n | \u6700\u7ec8\u6211\u610f\u8bc6\u5230\uff0c\u6211\u6240\u8981\u5199\u7684\u4efb\u4f55\u670d\u52a1\u5668\u7684\u98ce\u9669\u90fd\u5f88\u4f4e\uff0c\u5982\u679c\u5b83\u4eec\u5076\u5c14\u5b95\u673a 2 \u5c0f\u65f6\u4e5f\u6ca1\u4ec0\u4e48\u5927\u4e0d\u4e86\u7684\uff0c\u6211\u53ea\u9700\u8bbe\u7f6e\u4e00\u4e9b\u975e\u5e38\u7b80\u5355\u7684\u76d1\u63a7\u6765\u5e2e\u52a9\u5b83\u4eec\u4fdd\u6301\u8fd0\u884c\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n \u4f60\u597d! \u6211\u6700\u8fd1\u53c8\u5f00\u59cb\u8fd0\u884c\u4e00\u4e9b\u670d\u52a1\u5668\uff08\u200b\u200bnginx playground\u200b\u200b\u200b\u3001\u200b\u200bmess with dns\u200b\u200b\u200b\u3001\u200b\u200bdns lookup\u200b\u200b\uff09\uff0c\u6240\u4ee5\u6211\u4e00\u76f4\u5728\u8003\u8651\u76d1\u63a7\u95ee\u9898\u3002<\/p>\n \u6700\u521d\u6211\u5e76\u4e0d\u5b8c\u5168\u6e05\u695a\u5982\u4f55\u76d1\u63a7\u8fd9\u4e9b\u7f51\u7ad9\uff0c\u6240\u4ee5\u6211\u60f3\u5feb\u901f\u5199\u4e0b\u6211\u662f\u5982\u4f55\u505a\u5230\u7684\u3002<\/p>\n \u6211\u6839\u672c\u4e0d\u6253\u7b97\u8c08\u5982\u4f55\u76d1\u63a7\u5927\u578b\u7684\u3001\u4e25\u8083\u7684\u5173\u952e\u4efb\u52a1\u7f51\u7ad9\uff0c\u53ea\u8c08\u5fae\u578b\u7684\u4e0d\u91cd\u8981\u7684\u7f51\u7ad9\u3002<\/p>\n <\/p>\n \u76ee\u6807\uff1a\u5728\u64cd\u4f5c\u4e0a\u51e0\u4e4e\u4e0d\u82b1\u65f6\u95f4<\/strong><\/div>\n \u6211\u5e0c\u671b\u7f51\u7ad9\u5927\u90e8\u5206\u65f6\u95f4\u90fd\u80fd\u6b63\u5e38\u5de5\u4f5c\uff0c\u4f46\u6211\u4e5f\u5e0c\u671b\u4e0d\u7528\u5728\u6301\u7eed\u7684\u8fd0\u8425\u4e0a\u82b1\u8d39\u65f6\u95f4\u3002<\/p>\n \u6211\u6700\u521d\u5bf9\u8fd0\u884c\u670d\u52a1\u5668\u975e\u5e38\u8b66\u60d5\uff0c\u56e0\u4e3a\u5728\u6211\u7684\u4e0a\u4e00\u4efd\u5de5\u4f5c\u4e2d\uff0c\u6211\u662f 24\/7 \u8f6e\u6d41\u503c\u73ed\uff0c\u8d1f\u8d23\u4e00\u4e9b\u5173\u952e\u7684\u670d\u52a1\uff0c\u5728\u6211\u7684\u5370\u8c61\u4e2d\uff0c\u201c\u8d1f\u8d23\u670d\u52a1\u5668\u201d\u610f\u5473\u7740\u201c\u5728\u51cc\u6668 2 \u70b9\u88ab\u53eb\u8d77\u6765\u4fee\u7406\u670d\u52a1\u5668\u201d\u548c\u201c\u6709\u5f88\u591a\u590d\u6742\u7684\u4eea\u8868\u76d8\u201d\u3002<\/p>\n \u6240\u4ee5\u6709\u4e00\u6bb5\u65f6\u95f4\u6211\u53ea\u505a\u9759\u6001\u7f51\u7ad9\uff0c\u8fd9\u6837\u6211\u5c31\u4e0d\u7528\u8003\u8651\u670d\u52a1\u5668\u7684\u95ee\u9898\u3002<\/p>\n \u4f46\u6700\u7ec8\u6211\u610f\u8bc6\u5230\uff0c\u6211\u6240\u8981\u5199\u7684\u4efb\u4f55\u670d\u52a1\u5668\u7684\u98ce\u9669\u90fd\u5f88\u4f4e\uff0c\u5982\u679c\u5b83\u4eec\u5076\u5c14\u5b95\u673a 2 \u5c0f\u65f6\u4e5f\u6ca1\u4ec0\u4e48\u5927\u4e0d\u4e86\u7684\uff0c\u6211\u53ea\u9700\u8bbe\u7f6e\u4e00\u4e9b\u975e\u5e38\u7b80\u5355\u7684\u76d1\u63a7\u6765\u5e2e\u52a9\u5b83\u4eec\u4fdd\u6301\u8fd0\u884c\u3002<\/p>\n \u6ca1\u6709\u76d1\u63a7\u5f88\u7cdf\u7cd5<\/strong><\/div>\n \u8d77\u521d\uff0c\u6211\u6839\u672c\u6ca1\u6709\u4e3a\u6211\u7684\u670d\u52a1\u5668\u8bbe\u7f6e\u4efb\u4f55\u76d1\u63a7\u3002\u8fd9\u6837\u505a\u7684\u7ed3\u679c\u662f\u975e\u5e38\u53ef\u9884\u89c1\u7684\uff1a\u6709\u65f6\u7f51\u7ad9\u574f\u4e86\uff0c\u800c\u6211\u5374\u6ca1\u6709\u53d1\u73b0\uff0c\u76f4\u5230\u6709\u4eba\u544a\u8bc9\u6211\uff01<\/p>\n \u6b65\u9aa4 1\uff1auptime \u68c0\u67e5\u5668<\/strong><\/span><\/div>\n \u7b2c\u4e00\u6b65\u662f\u5efa\u7acb\u4e00\u4e2a uptime \u68c0\u67e5\u5668\u3002\u5916\u9762\u6709\u5f88\u591a\u8fd9\u6837\u7684\u4e1c\u897f\uff0c\u6211\u73b0\u5728\u4f7f\u7528\u7684\u662f \u200b\u200bupdown.io\u200b\u200b \u548c \u200b\u200buptime robot\u200b\u200b\u3002\u6211\u66f4\u559c\u6b22 updown \u7684\u7528\u6237\u754c\u9762\u548c \u200b\u200b\u5b9a\u4ef7\u200b\u200b \u7ed3\u6784\uff08\u5b83\u662f\u6309\u8bf7\u6c42\u800c\u4e0d\u662f\u6309\u6708\u6536\u8d39\uff09\uff0c\u4f46 uptime \u673a\u5668\u4eba\u6709\u4e00\u4e2a\u66f4\u6177\u6168\u7684\u514d\u8d39\u5957\u9910\u3002<\/p>\n \u5b83\u4eec\u4f1a\uff1a<\/p>\n
\n\u5982\u679c\u51fa\u73b0\u6545\u969c\uff0c\u5b83\u4f1a\u7ed9\u6211\u53d1\u7535\u5b50\u90ae\u4ef6\n<\/ol>\n \u6211\u53d1\u73b0\u7535\u5b50\u90ae\u4ef6\u901a\u77e5\u5bf9\u6211\u6765\u8bf4\u662f\u4e00\u4e2a\u5f88\u597d\u7684\u901a\u77e5\u7ea7\u522b\uff0c\u5982\u679c\u7f51\u7ad9\u5b95\u673a\uff0c\u6211\u4f1a\u5f88\u5feb\u53d1\u73b0\uff0c\u4f46\u5b83\u4e0d\u4f1a\u5435\u9192\u6211\u6216\u505a\u5176\u5b83\u7684\u4ec0\u4e48\u6253\u6270\u3002<\/p>\n \u6b65\u9aa4 2\uff1a\u7aef\u5230\u7aef\u7684\u5065\u5eb7\u68c0\u67e5<\/strong><\/span><\/div>\n \u63a5\u4e0b\u6765\uff0c\u8ba9\u6211\u4eec\u8c08\u8c08\u201c\u68c0\u67e5\u7f51\u7ad9\u662f\u5426\u6b63\u5e38\u201d\u5230\u5e95\u662f\u4ec0\u4e48\u610f\u601d\u3002<\/p>\n \u8d77\u521d\uff0c\u6211\u53ea\u662f\u628a\u6211\u7684\u5065\u5eb7\u68c0\u67e5\u7aef\u70b9\u4e4b\u4e00\u53d8\u6210\u4e00\u4e2a\u51fd\u6570\uff0c\u65e0\u8bba\u5982\u4f55\u90fd\u4f1a\u8fd4\u56de \u200b\u200b200 OK\u200b\u200b\u3002<\/p>\n \u8fd9\u5012\u662f\u633a\u6709\u7528\u7684 \u2013 \u5b83\u544a\u8bc9\u6211\u670d\u52a1\u5668\u662f\u542f\u52a8\u7740\u7684\uff01<\/p>\n \u4f46\u4e0d\u51fa\u6240\u6599\uff0c\u6211\u9047\u5230\u4e86\u95ee\u9898\uff0c\u56e0\u4e3a\u5b83\u6ca1\u6709\u68c0\u67e5 API \u662f\u5426\u771f\u7684\u5728 \u5de5\u4f5c \u2013 \u6709\u65f6\u5065\u5eb7\u68c0\u67e5\u6210\u529f\u4e86\uff0c\u5c3d\u7ba1\u670d\u52a1\u7684\u5176\u4ed6\u90e8\u5206\u5b9e\u9645\u4e0a\u5df2\u7ecf\u8fdb\u5165\u4e86\u4e00\u4e2a\u7cdf\u7cd5\u7684\u72b6\u6001\u3002<\/p>\n \u6240\u4ee5\u6211\u66f4\u65b0\u4e86\u5b83\uff0c\u8ba9\u5b83\u771f\u6b63\u5730\u53d1\u51fa API \u8bf7\u6c42\uff0c\u5e76\u786e\u4fdd\u5b83\u6210\u529f\u4e86\u3002<\/p>\n \u6211\u6240\u6709\u7684\u670d\u52a1\u90fd\u53ea\u505a\u4e86\u5f88\u5c11\u7684\u4e8b\u60c5\uff08nginx playground \u53ea\u6709\u4e00\u4e2a\u7aef\u70b9\uff09\uff0c\u6240\u4ee5\u8bbe\u7f6e\u4e00\u4e2a\u5065\u5eb7\u68c0\u67e5\u662f\u975e\u5e38\u5bb9\u6613\u7684\uff0c\u5b83\u5b9e\u9645\u4e0a\u8d2f\u7a7f\u4e86\u670d\u52a1\u5e94\u8be5\u505a\u7684\u5927\u90e8\u5206\u52a8\u4f5c\u3002<\/p>\n \u4e0b\u9762\u662f nginx playground \u7684\u7aef\u5230\u7aef\u5065\u5eb7\u68c0\u67e5\u5904\u7406\u7a0b\u5e8f\u7684\u6837\u5b50\u3002\u5b83\u975e\u5e38\u57fa\u672c\uff1a\u5b83\u53ea\u662f\u53d1\u51fa\u4e00\u4e2a POST \u8bf7\u6c42\uff08\u7ed9\u81ea\u5df1\uff09\uff0c\u5e76\u68c0\u67e5\u8be5\u8bf7\u6c42\u662f\u6210\u529f\u8fd8\u662f\u5931\u8d25\u3002<\/p>\n \r\n func healthHandler(w http.ResponseWriter, r *http.Request) {\r\n \/\/ make a request to localhost:8080 with `healthcheckJSON` as the body\r\n \/\/ if it works, return 200\r\n \/\/ if it doesn't, return 500\r\n client := http.Client{}\r\n resp, err := client.Post(\"http:\/\/localhost:8080\/\", \"application\/json\", strings.NewReader(healthcheckJSON))\r\n if err != nil {\r\n log.Println(err)\r\n w.WriteHeader(http.StatusInternalServerError)\r\n return\r\n }\r\n if resp.StatusCode != http.StatusOK {\r\n log.Println(resp.StatusCode)\r\n w.WriteHeader(http.StatusInternalServerError)\r\n return\r\n }\r\n w.WriteHeader(http.StatusOK)\r\n }\r\n\r\n<\/pre>\n |