<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                ## 一、自定義監控需求 ### 1.1 需求描述 希望能在go項目中,暴露 * 下單總次數的數據指標 * 下單總金額的數據指標 ### 1.2 實現步驟 go開發環境中,創建自定義監控器。創建專門的視圖方法/order/addOrder增加下單總次數和下單總金額數據 * application.yaml配置修改暴露指定數據 * 測試訪問/actuator/prometheus得到下單總次數和下單總金額數據 * Grafana中配置下單總次數和下單總金額數據 <br><hr><br> ## 二、go項目實現訂單數據監控 ### 2.1 testproject項目上創建自定義監控器 真實業務場景中,每次用戶創建一個訂單,就會訂單總數+1,訂單總金額加上當前金額此處定義兩個業務指標 指標名 | 參數名 下單總次數 | order_request_count 下單總金額 | order_amount_sum 編寫go代碼 package main import ( "fmt" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promhttp" "log" "net/http" "time" ) // 定義指標變量 var ( orderRequestCount = prometheus.NewCounter( prometheus.CounterOpts{ Name: "order_request_count", Help: "下單總次數", }, ) orderAmountSum = prometheus.NewCounter( prometheus.CounterOpts{ Name: "order_amount_sum", Help: "下單總金額", }, ) ) func init() { // 注冊指標到 Prometheus 默認注冊表 prometheus.MustRegister(orderRequestCount) prometheus.MustRegister(orderAmountSum) } func main() { // 創建一個 HTTP 處理器,它將暴露指標 http.Handle("/metrics", promhttp.Handler()) // 模擬下單處理 go func() { for { // 模擬下單 orderRequestCount.Inc() // 增加下單次數 amount := float64(100 + (time.Now().UnixNano()%1000)/10) // 生成一個隨機的訂單金額 orderAmountSum.Add(amount) // 增加訂單金額 // 模擬每秒鐘一個訂單 time.Sleep(1 * time.Second) } }() // 啟動 HTTP 服務器,監聽在端口 8182 fmt.Println("Starting server on :8182") log.Fatal(http.ListenAndServe(":8182", nil)) } 啟動go項目后訪問 http://192.168.100.141:8182/metrics 然后打開目標 go的項目 ,添加對應的監控指標 ![](https://img.kancloud.cn/e3/89/e389cd3731ef6875e576aed6dcbe773e_1864x798.png) ![](https://img.kancloud.cn/fe/a6/fea6ba8bcc66f1833f228bd8f8906aa6_1458x326.png) ![](https://img.kancloud.cn/87/8a/878aa994674b7cce76b600dfc33c0396_1920x890.png)
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看