栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Go语言

prometheus连续查询

Go语言 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

prometheus连续查询

1.项目中需要使用prometheus监控每个请求的耗时情况和响应结果(http.StatusCode)

2.看了prometheus的文档,依旧不是很明白

3.下面是一段示例demo,我应该使用哪种metric和方式来进行监控呢?package main

import (

"github.com/prometheus/client_golang/prometheus"

"io/ioutil"

"net/http"

"fmt"

"time"

)

var (

respTime = prometheus.NewSummaryVec(

prometheus.SummaryOpts{

Name: "response_time",

Help: "cost time per request",

},

[]string{"costTime"},

)

)

func main() {

urls := []string{"http://www.google.com","http://www.google.com"}

for _,url := range urls {

request(url)

}

}

func request(url string){

startTime := time.Now()

response,_ := http.Get(url)

defer response.Body.Close()

_,err := ioutil.ReadAll(response.Body)

if err != nil {

fmt.Println(err)

}

costTime := time.Since(startTime)

respTime.WithLabelValues(fmt.Sprintf("%d", costTime)).Observe(costTime.Seconds())

}

求指教

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/945703.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号