为什么想到要用golang来编写metrics呢?这主要是我们的一个客户那里,k8s网络使用了ovs,并且做了bond,即bond0和bond1,每个bond下面2张网卡。在上了生产后,让我每天都要检查一下网卡是否正常,因为之前就有网卡DOWN了。而我呢,比较懒,不想手动去检查。想着通过prometheus最终展示到grafana,我就在grafana上看看有没有处...
metrics格式可以参考prometheus官网。 bond有两个,每个下面有两张网卡,每张网卡的状态只有enabled和disabled,因此用数字0-4来告诉用户有几张网卡disabled了,用数字5来表示命令执行有问题或没有bond,需要人工介入。可以通过命令去获取bond信息,因此还是采取命令方式去获取。 要对执行命令获取的输出结果进行处理并放到metrics...
package mainimport ("net/http""github.com/prometheus/client_golang/prometheus/promhttp")func main() {// Serve thedefaultPrometheus metrics registry over HTTPon/metrics.http.Handle("/metrics", promhttp.Handler())http.ListenAndServe(":8080", nil)} 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. ...
复制 // 命令执行正确则将对应的网卡、网卡状态以及处于异常的网卡数量注入到到metrics中去func(collector*ovsCollector)Collect(ch chan<-prometheus.Metric){varmetricValue float64varrm=make(map[string]string)rm=getBondStatus()if_,ok:=rm["msg"];ok{log.Error("command exec failed")metricValue=5ch<-pr...
其中METRICS_ROUTE作为监控服务的http路由路径,定义在kis-flow/common/const.go中: 如下: kis-flow/common/const.go // ... ... // metrics const ( METRICS_ROUTE string = "/metrics" ) // ... ... 接下来来简单说明下上述的代码,RunMetricsService() 是启动prometheus监控的http服务代码,为什么要...
prometheus/client_golang/prometheus")//Define a struct for you collector that contains pointers//to prometheus descriptors for each metric you wish to expose.//Note you can also include fields of other types if they provide utility//but we just won't be exposing them as metrics.typefoo...
custom registry的使用方式还有很多:可以使用NewPedanticRegistry来注册特殊的属性;可以避免由DefaultRegisterer限制的全局状态属性;也可以同时使用多个registry来暴露不同的metrics。 DefaultRegisterer注册了Go runtime metrics (通过NewGoCollector)和用于process metrics 的collector(通过NewProcessCollector)。通过custom registry...
Golang Application Runtime metrics A polish version ofhttps://grafana.com/grafana/dashboards/10826 Revisions RevisionDescriptionCreated Go Grafana Labs solution Easily monitor Go, the programming language designed at Google to make programmers more productive in applications with strong networking concurrenc...
创建metrics指标 给metrics指标赋值 注册metrics指标 通过http暴露metics指标 先来一个例子 packagemainimport("net/http""github.com/prometheus/client_golang/prometheus""github.com/prometheus/client_golang/prometheus/promhttp""log")// 定义自定义指标var( ...
Prometheus SDK(golang) 使用说明 写在前面 Prometheus官方提供了上报 metric 的Golang SDK, 用户可以自定义metric,然后采用 push 或 pull 的方式上报 metric 数据。 下面介绍下这两个方式的使用说明。 使用示例 数据埋点示例 Counter类型 // 创建 counter 对象...