[GoFrame (ZH)-v2.0] Pages Feed
Confluence Syndication Feed
https://goframe.org
框架介绍(最新版本)
海亮
tag:goframe.org,2009:page-1114119-149
2024-03-28T08:37:27Z
2020-12-21T06:18:53Z
<div class="feed"> <p>
Page
<b>edited</b> by
<a href=" https://goframe.org/display/~hailaz
">海亮</a>
</p>
<div style="border-top: 1px solid #ddd; border-bottom: 1px solid #ddd; padding: 10px;">
<div align="center"><span class="confluence-embedded-file-wrapper confluence-embedded-manual-size"><img class="confluence-embedded-image" draggable="false" height="250" src="https://goframe.org/download/attachments/1114119/logo2.png?version=1&modificationDate=1684158720965&api=v2" data-image-src="https://goframe.org/download/attachments/1114119/logo2.png?version=1&modificationDate=1684158720965&api=v2" data-unresolved-comment-count="0" data-linked-resource-id="88876369" data-linked-resource-version="1" data-linked-resource-type="attachment" data-linked-resource-default-alias="logo2.png" data-base-url="https://goframe.org" data-linked-resource-content-type="image/png" data-linked-resource-container-id="1114119" data-linked-resource-container-version="149" alt=""></span> <br/><p><a class="external-link" href="https://pkg.go.dev/github.com/gogf/gf/v2" rel="nofollow"> <img alt="Go Doc" src="https://godoc.org/github.com/gogf/gf?status.svg"/> </a> <a class="external-link" href="https://travis-ci.com/github/gogf/gf" rel="nofollow"> <img alt="Build Status" src="https://api.travis-ci.com/gogf/gf.svg?branch=master"/> </a> <a class="external-link" href="https://goreportcard.com/report/github.com/gogf/gf" rel="nofollow"> <img alt="Go Report" src="https://goreportcard.com/badge/github.com/gogf/gf"/> </a> <a class="external-link" href="https://codecov.io/gh/gogf/gf/branch/master" rel="nofollow"> <img alt="Code Coverage" src="https://codecov.io/gh/gogf/gf/branch/master/graph/badge.svg"/> </a> <a class="external-link" href="https://github.com/gogf/gf" rel="nofollow"> <img alt="Production Ready" src="https://img.shields.io/badge/production-ready-blue.svg"/> </a> <a class="external-link" href="https://github.com/gogf/gf" rel="nofollow"> <img alt="License" src="https://img.shields.io/github/license/gogf/gf.svg?style=flat"/> </a></p><p><a class="external-link" href="https://github.com/gogf/gf/releases" rel="nofollow"> <img alt="Release" src="https://img.shields.io/github/v/release/gogf/gf"/> </a> <a class="external-link" href="https://github.com/gogf/gf/pulls" rel="nofollow"> <img alt="GitHub pull requests" src="https://img.shields.io/github/issues-pr/gogf/gf"/> </a> <a class="external-link" href="https://github.com/gogf/gf/pulls?q=is%3Apr+is%3Aclosed" rel="nofollow"> <img alt="GitHub closed pull requests" src="https://img.shields.io/github/issues-pr-closed/gogf/gf"/> </a> <a class="external-link" href="https://github.com/gogf/gf/issues" rel="nofollow"> <img alt="GitHub issues" src="https://img.shields.io/github/issues/gogf/gf"/> </a> <a class="external-link" href="https://github.com/gogf/gf/issues?q=is%3Aissue+is%3Aclosed" rel="nofollow"> <img alt="GitHub closed issues" src="https://img.shields.io/github/issues-closed/gogf/gf"/> </a> <img alt="Stars" src="https://img.shields.io/github/stars/gogf/gf?style=flat"/> <img alt="Forks" src="https://img.shields.io/github/forks/gogf/gf?style=flat"/></p></div><p><code>GoFrame</code>是一款模块化、高性能、企业级的<code>Go</code>基础开发框架。<code>GoFrame</code>是一款通用性的基础开发框架,是<code>Golang</code>标准库的一个增强扩展级,包含通用核心的基础开发组件,优点是实战化、模块化、文档全面、模块丰富、易用性高、通用性强、面向团队。<code>GoFrame</code>既可用于开发完整的工程化项目,由于框架基础采用模块化解耦设计,因此也可以作为工具库使用。</p><p>如果您想使用<code>Golang</code>开发一个业务型项目,无论是小型还是中大型项目,<code>GoFrame</code>是您的不二之选。如果您想开发一个<code>Golang</code>组件库,<code>GoFrame</code>提供开箱即用、丰富强大的基础组件库也能助您的工作事半功倍。如果您是团队<code>Leader</code>,<code>GoFrame</code>丰富的资料文档、详尽的代码注释、活跃的社区成员将会极大降低您的指导成本,支持团队快速接入、语言转型与能力提升。</p><h1 id="id-框架介绍(最新版本)-特点">特点</h1><ul><li>业内领先、工程完备</li><li>模块化、松耦合设计</li><li>组件丰富、开箱即用</li><li>简洁易用、文档详尽</li><li>接口化、高扩展性设计</li><li>全链路跟踪特性</li><li>全错误堆栈特性</li><li>接口化的错误码支持</li><li>稳健的工程设计规范</li><li>更便捷强大的ORM组件</li><li>便捷的开发工具、自动化代码生成</li><li>支持<code>OpenTelemetry</code>可观测性标准</li><li>自动化的接口文档生成,支持<code>OpenAPIV3</code>标准</li><li>完善的本地中文化支持</li><li>设计为团队及企业使用</li></ul><h1 id="id-框架介绍(最新版本)-地址">地址</h1><ul><li><strong>主库</strong>:<a class="external-link" href="https://github.com/gogf/gf" rel="nofollow">https://github.com/gogf/gf</a></li><li><strong>码云</strong>:<a class="external-link" href="https://gitee.com/johng/gf" rel="nofollow">https://gitee.com/johng/gf</a></li></ul><h1 id="id-框架介绍(最新版本)-安装">安装</h1><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="syntaxhighlighter-pre" data-syntaxhighlighter-params="brush: xml; gutter: false; theme: Confluence" data-theme="Confluence">go get -u -v github.com/gogf/gf/v2</pre>
</div></div><p>推荐使用 <code>go.mod</code>:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="syntaxhighlighter-pre" data-syntaxhighlighter-params="brush: xml; gutter: false; theme: Confluence" data-theme="Confluence">require github.com/gogf/gf/v2 latest</pre>
</div></div><h1 id="id-框架介绍(最新版本)-限制">限制</h1><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="syntaxhighlighter-pre" data-syntaxhighlighter-params="brush: xml; gutter: false; theme: Confluence" data-theme="Confluence">golang版本 >= 1.18</pre>
</div></div><div align="center"><br/></div><h1 id="id-框架介绍(最新版本)-文档">文档</h1><ul><li>官网(中文):<a href="https://goframe.org" rel="nofollow">https://goframe.org</a></li><li>镜像(中文):<span class="nolink"><a class="external-link" href="https://pages.goframe.org" rel="nofollow">https://pages.goframe.org</a></span></li><li>离线文档:<a class="external-link" href="https://github.com/gogf/goframe.org-pdf" rel="nofollow">https://github.com/gogf/goframe.org-pdf</a></li></ul><h1 id="id-框架介绍(最新版本)-帮助">帮助</h1><ul><li><p class="auto-cursor-target"><strong>扣扣交流群</strong>:扫描或群号搜索添加</p><div class="table-wrap"><table class="wrapped relative-table confluenceTable" style="width: 29.7847%;"><colgroup> <col style="width: 45.2716%;"/> <col style="width: 54.7284%;"/> </colgroup><tbody><tr><th style="text-align: center;" class="confluenceTh"><div class="content-wrapper"><p>GoFrame实战1群</p></div></th><th style="text-align: center;" class="confluenceTh">GoFrame实战2群</th></tr><tr><td class="confluenceTd"><div class="content-wrapper"><p><br/></p><p style="text-align: center;"><br/></p><p style="text-align: center;">已满</p></div></td><td class="confluenceTd"><div class="content-wrapper"><p><span class="confluence-embedded-file-wrapper image-center-wrapper confluence-embedded-manual-size"><img class="confluence-embedded-image confluence-thumbnail image-center" draggable="false" height="150" src="https://goframe.org/download/thumbnails/1114119/1618482221516.png?version=1&modificationDate=1618482239045&api=v2" data-image-src="https://goframe.org/download/attachments/1114119/1618482221516.png?version=1&modificationDate=1618482239045&api=v2" data-unresolved-comment-count="0" data-linked-resource-id="7296918" data-linked-resource-version="1" data-linked-resource-type="attachment" data-linked-resource-default-alias="1618482221516.png" data-base-url="https://goframe.org" data-linked-resource-content-type="image/png" data-linked-resource-container-id="1114119" data-linked-resource-container-version="149" alt=""></span></p><p style="text-align: center;">74341849</p></div></td></tr></tbody></table></div></li><li><p class="auto-cursor-target"><strong>微信交流群</strong>:扫描或微信添加<code>389961817</code>备注<code>GF</code>加群</p><div class="table-wrap"><table class="wrapped relative-table confluenceTable" style="width: 29.9641%;"><colgroup> <col style="width: 100.0%;"/> </colgroup><tbody><tr><th style="text-align: center;" class="confluenceTh"><div class="content-wrapper"><p>添加后拉群</p></div></th></tr><tr><td class="confluenceTd"><div class="content-wrapper"><p><span class="confluence-embedded-file-wrapper image-center-wrapper confluence-embedded-manual-size"><img class="confluence-embedded-image confluence-thumbnail image-center" draggable="false" width="150" src="https://goframe.org/download/thumbnails/1114119/image2021-4-15_19-23-42.png?version=1&modificationDate=1618485986477&api=v2" data-image-src="https://goframe.org/download/attachments/1114119/image2021-4-15_19-23-42.png?version=1&modificationDate=1618485986477&api=v2" data-unresolved-comment-count="0" data-linked-resource-id="7296922" data-linked-resource-version="1" data-linked-resource-type="attachment" data-linked-resource-default-alias="image2021-4-15_19-23-42.png" data-base-url="https://goframe.org" data-linked-resource-content-type="image/png" data-linked-resource-container-id="1114119" data-linked-resource-container-version="149" alt=""></span></p></div></td></tr></tbody></table></div></li><li><strong>微信公众号</strong>:关注<code>GoFrame</code>的发展动态</li></ul><p style="margin-left: 40.0px;"><span class="confluence-embedded-file-wrapper confluence-embedded-manual-size"><img class="confluence-embedded-image confluence-thumbnail" draggable="false" height="250" src="https://goframe.org/download/thumbnails/1114119/qrcode_for_gh_f67013196297_258%20%281%29.jpg?version=2&modificationDate=1640963240154&api=v2" data-image-src="https://goframe.org/download/attachments/1114119/qrcode_for_gh_f67013196297_258%20%281%29.jpg?version=2&modificationDate=1640963240154&api=v2" data-unresolved-comment-count="0" data-linked-resource-id="30739334" data-linked-resource-version="2" data-linked-resource-type="attachment" data-linked-resource-default-alias="qrcode_for_gh_f67013196297_258 (1).jpg" data-base-url="https://goframe.org" data-linked-resource-content-type="image/jpeg" data-linked-resource-container-id="1114119" data-linked-resource-container-version="149" alt=""></span></p><ul><li>主库ISSUE:<a class="external-link" href="https://github.com/gogf/gf/issues" rel="nofollow">https://github.com/gogf/gf/issues</a></li></ul><blockquote><p>建议通过阅读<code>GoFrame</code>的源码以及API文档深度学习<code>GoFrame</code>,了解更多的精妙设计。</p></blockquote><h1 id="id-框架介绍(最新版本)-协议">协议</h1><p><code>GoFrame</code> 使用非常友好的 <code>MIT</code> 开源协议进行发布,永久<code>100%</code>开源免费。</p><h1 id="id-框架介绍(最新版本)-用户">用户</h1><ul><li><a class="external-link" href="https://www.tencent.com/" rel="nofollow">腾讯科技</a></li><li><a class="external-link" href="https://www.zte.com.cn/china/" rel="nofollow">中兴科技</a></li><li><a class="external-link" href="https://www.antfin.com/" rel="nofollow">蚂蚁金服</a></li><li><span style="color: rgb(51,51,51);"> <a class="external-link" href="https://www.vivo.com/" rel="nofollow">VIVO</a> </span></li><li><a class="external-link" href="https://www.medlinker.com/" rel="nofollow">医联科技</a></li><li><a class="external-link" href="https://www.kucoin.io/" rel="nofollow">库币科技</a></li><li><a class="external-link" href="https://www.leyoujia.com/" rel="nofollow">乐有家</a></li><li><a class="external-link" href="https://igg.com" rel="nofollow">IGG</a></li><li><a class="external-link" href="https://www.37.com/" rel="nofollow">三七互娱</a></li><li><a class="external-link" href="https://www.ximalaya.com" rel="nofollow">喜马拉雅</a></li><li><a class="external-link" href="https://www.zybang.com/" rel="nofollow">作业帮</a></li></ul><blockquote><p>在这里只列举了部分知名的用户,如果您的企业或者产品正在使用<code>GoFrame</code>,欢迎到 <a href="https://goframe.org/pages/viewpage.action?pageId=1114415" rel="nofollow">这里</a> 留言。</p></blockquote><h1 id="id-框架介绍(最新版本)-贡献">贡献</h1><p>感谢所有参与<code>GoFrame</code>开发的贡献者。 [<a class="external-link" href="https://github.com/gogf/gf/graphs/contributors" rel="nofollow">贡献者列表</a>].</p><p><a class="external-link" href="https://github.com/gogf/gf/graphs/contributors" rel="nofollow"> <img src="https://contributors-img.web.app/image?repo=gogf/gf"/> </a></p><h1 id="id-框架介绍(最新版本)-捐赠">捐赠</h1><p>如果您喜欢<code>GoFrame</code>,要不给开发者 <a href="https://goframe.org/pages/viewpage.action?pageId=1115633">来杯咖啡</a> 吧! 请在捐赠时备注您的<code>github</code>/<code>gitee</code>账号名称。</p><h1 id="id-框架介绍(最新版本)-赞助">赞助</h1><p>赞助支持<code>GoFrame</code>框架的快速研发,如果您感兴趣,请联系 微信 <code>389961817</code> / 邮件 <a class="external-link" href="mailto:john@goframe.org" rel="nofollow">john@goframe.org</a> 。</p><h1 id="id-框架介绍(最新版本)-感谢">感谢</h1><p><a class="external-link" href="https://www.jetbrains.com/?from=GoFrame" rel="nofollow"> <span class="confluence-embedded-file-wrapper confluence-embedded-manual-size"><img class="confluence-embedded-image confluence-thumbnail" draggable="false" height="150" src="https://goframe.org/download/thumbnails/1114119/jetbrains.png?version=1&modificationDate=1608649325806&api=v2" data-image-src="https://goframe.org/download/attachments/1114119/jetbrains.png?version=1&modificationDate=1608649325806&api=v2" data-unresolved-comment-count="0" data-linked-resource-id="1115399" data-linked-resource-version="1" data-linked-resource-type="attachment" data-linked-resource-default-alias="jetbrains.png" data-base-url="https://goframe.org" data-linked-resource-content-type="image/png" data-linked-resource-container-id="1114119" data-linked-resource-container-version="149" alt=""></span> </a> <a class="external-link" href="https://www.atlassian.com/?from=GoFrame" rel="nofollow"> <span class="confluence-embedded-file-wrapper confluence-embedded-manual-size"><img class="confluence-embedded-image confluence-thumbnail" draggable="false" height="150" src="https://goframe.org/download/thumbnails/1114119/atlassian.jpg?version=1&modificationDate=1612661946532&api=v2" data-image-src="https://goframe.org/download/attachments/1114119/atlassian.jpg?version=1&modificationDate=1612661946532&api=v2" data-unresolved-comment-count="0" data-linked-resource-id="1115400" data-linked-resource-version="1" data-linked-resource-type="attachment" data-linked-resource-default-alias="atlassian.jpg" data-base-url="https://goframe.org" data-linked-resource-content-type="image/jpeg" data-linked-resource-container-id="1114119" data-linked-resource-container-version="149" alt=""></span> </a></p><p><br/></p><p><br/></p>
</div>
<div style="padding: 10px 0;">
<a href="https://goframe.org/pages/viewpage.action?pageId=1114119">View Online</a>
·
<a href="https://goframe.org/pages/diffpagesbyversion.action?pageId=1114119&revisedVersion=149&originalVersion=148">View Changes Online</a>
</div>
</div>
海亮
2020-12-21T06:18:53Z
监控告警-异步指标
郭强
tag:goframe.org,2009:page-149880871-2
2024-03-25T13:36:01Z
2024-03-25T11:26:54Z
<div class="feed"> <p>
Page
<b>edited</b> by
<a href=" https://goframe.org/display/~john
">郭强</a>
</p>
<div style="border-top: 1px solid #ddd; border-bottom: 1px solid #ddd; padding: 10px;">
<div class="contentLayout2">
<div class="columnLayout two-right-sidebar" data-layout="two-right-sidebar">
<div class="cell normal" data-type="normal">
<div class="innerCell">
<h1 id="id-监控告警异步指标-基本介绍">基本介绍</h1><p><strong>异步类型</strong>的监控指标只有在<code>metrics reader</code>开始使用该监控指标时才会执行指标计算逻辑。异步类型的监控指标需要设置一个回调函数,该回调函数用于生成指标数值,并在<code>metrics reader</code>读取指标时才会触发回调函数。例如,机器CPU、内存、磁盘使用量的指标,如果没有目标端拉取或者使用该指标时,提前计算指标值毫无意义且浪费计算资源,适合作为异步指标来管理。</p><p><code>gmetric</code>提供的异步类型指标包含:<code>ObservableCounter, ObservableUpDownCounter, OvservableGauge</code>。异步指标类型均是使用<code>Observable</code>开头命名,三种异步指标的操作都差不多,均是在不同的业务场景下有不同的使用差异。</p><p>我们用一个简单的示例来演示异步指标的基本使用。</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="syntaxhighlighter-pre" data-syntaxhighlighter-params="brush: go; gutter: false; theme: Confluence" data-custom-language-resource="com.atlassian.confluence.ext.code.custom.Go.8921870917569589270:custom-code-syntax-resources" data-theme="Confluence">package main
import (
"context"
"github.com/prometheus/client_golang/prometheus/promhttp"
"go.opentelemetry.io/otel/exporters/prometheus"
"go.opentelemetry.io/otel/sdk/metric"
"github.com/gogf/gf/contrib/metric/otelmetric/v2"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/net/ghttp"
"github.com/gogf/gf/v2/os/gctx"
"github.com/gogf/gf/v2/os/gmetric"
)
var (
meter = gmetric.GetGlobalProvider().Meter(gmetric.MeterOption{
Instrument: "github.com/gogf/gf/example/metric/basic",
InstrumentVersion: "v1.0",
})
observableCounter = meter.MustObservableCounter(
"goframe.metric.demo.observable_counter",
gmetric.MetricOption{
Help: "This is a simple demo for ObservableCounter usage",
Unit: "%",
},
)
observableUpDownCounter = meter.MustObservableUpDownCounter(
"goframe.metric.demo.observable_updown_counter",
gmetric.MetricOption{
Help: "This is a simple demo for ObservableUpDownCounter usage",
Unit: "%",
},
)
observableGauge = meter.MustObservableGauge(
"goframe.metric.demo.observable_gauge",
gmetric.MetricOption{
Help: "This is a simple demo for ObservableGauge usage",
Unit: "%",
},
)
)
func main() {
var ctx = gctx.New()
// Callback for observable metrics.
meter.MustRegisterCallback(func(ctx context.Context, obs gmetric.Observer) error {
obs.Observe(observableCounter, 10)
obs.Observe(observableUpDownCounter, 20)
obs.Observe(observableGauge, 30)
return nil
}, observableCounter, observableUpDownCounter, observableGauge)
// Prometheus exporter to export metrics as Prometheus format.
exporter, err := prometheus.New(
prometheus.WithoutCounterSuffixes(),
prometheus.WithoutUnits(),
)
if err != nil {
g.Log().Fatal(ctx, err)
}
// OpenTelemetry provider.
provider := otelmetric.MustProvider(metric.WithReader(exporter))
provider.SetAsGlobal()
defer provider.Shutdown(ctx)
// HTTP Server for metrics exporting.
s := g.Server()
s.BindHandler("/metrics", ghttp.WrapH(promhttp.Handler()))
s.SetPort(8000)
s.Run()
}
</pre>
</div></div><h1 id="id-监控告警异步指标-MeterCallback">Meter Callback</h1><p>异步指标需要定义<code>Callback</code>函数来管理指标数值变化,只有在请求或使用该指标时才会执行该<code>Callback</code>函数。<code>Callback</code>函数中使用<code>Observe</code>函数来更新指标的数值,针对不同异步指标类型的<code>Observe</code>会产生不同的结果。</p><ul><li>针对<code>ObservableCounter/ObservableUpDownCounter</code>指标类型,使用<code>Observe</code>函数后将会在原有指标数值上进行增减。</li><li>针对<code>ObservableGauge</code>指标类型,使用<code>Observe</code>函数后,该指标的值更会更新为<code>Observe</code>给定的数值。</li></ul><h1 id="id-监控告警异步指标-MetricCallback">Metric Callback</h1><p>除了通过<code>Meter CallBack</code>来实现异步指标的数值更新,也可以在创建指标时通过<code>MetricOption</code>指定<code>Callback</code>函数。例如:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="syntaxhighlighter-pre" data-syntaxhighlighter-params="brush: go; gutter: false; theme: Confluence" data-custom-language-resource="com.atlassian.confluence.ext.code.custom.Go.8921870917569589270:custom-code-syntax-resources" data-theme="Confluence">observableCounter = meter.MustObservableCounter(
"goframe.metric.demo.observable_counter",
gmetric.MetricOption{
Help: "This is a simple demo for ObservableCounter usage",
Unit: "%",
Callback: func(ctx context.Context, obs gmetric.MetricObserver) error {
obs.Observe(10)
return nil
},
},
)</pre>
</div></div><h1 id="id-监控告警异步指标-PrimetheusExporter">Primetheus Exporter</h1><p>通过以下路由将指标通过<code>Prometheus</code>协议暴露:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="syntaxhighlighter-pre" data-syntaxhighlighter-params="brush: go; gutter: false; theme: Confluence" data-custom-language-resource="com.atlassian.confluence.ext.code.custom.Go.8921870917569589270:custom-code-syntax-resources" data-theme="Confluence">s.BindHandler("/metrics", ghttp.WrapH(promhttp.Handler()))</pre>
</div></div><p>执行后,访问 <a class="external-link" href="http://127.0.0.1:8000/metrics" rel="nofollow">http://127.0.0.1:8000/metrics</a> 查看暴露的指标:</p><p><span class="confluence-embedded-file-wrapper"><img class="confluence-embedded-image" draggable="false" src="https://goframe.org/download/attachments/149880871/image-2024-3-25_21-35-45.png?version=1&modificationDate=1711373746579&api=v2" data-image-src="https://goframe.org/download/attachments/149880871/image-2024-3-25_21-35-45.png?version=1&modificationDate=1711373746579&api=v2" data-unresolved-comment-count="0" data-linked-resource-id="149880877" data-linked-resource-version="1" data-linked-resource-type="attachment" data-linked-resource-default-alias="image-2024-3-25_21-35-45.png" data-base-url="https://goframe.org" data-linked-resource-content-type="image/png" data-linked-resource-container-id="149880871" data-linked-resource-container-version="2" alt=""></span></p><p>我们这里只关注本次示例中的指标,其他自动暴露的指标在后续章节介绍。</p><p><br/></p><p><br/></p></div>
</div>
<div class="cell aside" data-type="aside">
<div class="innerCell">
<div class="panel" style="border-width: 1px;"><div class="panelHeader" style="border-bottom-width: 1px;"><b>Content Menu</b></div><div class="panelContent">
<p><style type='text/css'>/*<![CDATA[*/
div.rbtoc1711679220028 {padding: 0px;}
div.rbtoc1711679220028 ul {margin-left: 0px;}
div.rbtoc1711679220028 li {margin-left: 0px;padding-left: 0px;}
/*]]>*/</style><div class='toc-macro rbtoc1711679220028'>
<ul class='toc-indentation'>
<li><a href='#id-监控告警异步指标-基本介绍'>基本介绍</a></li>
<li><a href='#id-监控告警异步指标-MeterCallback'>Meter Callback</a></li>
<li><a href='#id-监控告警异步指标-MetricCallback'>Metric Callback</a></li>
<li><a href='#id-监控告警异步指标-PrimetheusExporter'>Primetheus Exporter</a></li>
</ul>
</div></p>
</div></div></div>
</div>
</div>
</div>
</div>
<div style="padding: 10px 0;">
<a href="https://goframe.org/pages/viewpage.action?pageId=149880871">View Online</a>
·
<a href="https://goframe.org/pages/diffpagesbyversion.action?pageId=149880871&revisedVersion=2&originalVersion=1">View Changes Online</a>
</div>
</div>
郭强
2024-03-25T11:26:54Z
监控告警-同步指标
郭强
tag:goframe.org,2009:page-149880869-2
2024-03-25T12:53:53Z
2024-03-25T11:26:17Z
<div class="feed"> <p>
Page
<b>edited</b> by
<a href=" https://goframe.org/display/~john
">郭强</a>
</p>
<div style="border-top: 1px solid #ddd; border-bottom: 1px solid #ddd; padding: 10px;">
<div class="contentLayout2">
<div class="columnLayout two-right-sidebar" data-layout="two-right-sidebar">
<div class="cell normal" data-type="normal">
<div class="innerCell">
<h1 id="id-监控告警同步指标-基本介绍">基本介绍</h1><p><strong>同步类型</strong>用于快速暴露监控指标,无论<code>metrics reader</code>是否使用该监控指标,指标的计算结果已完成,待读取使用。例如,HTTP的请求总数、请求大小,这些数值必须在请求执行流程中记录到对应的监控指标数值中,适合作为同步指标来管理。</p><p><code>gmetric</code>提供的同步类型指标包含:<code>Counter, UpDownCounter, Histogram</code>。</p><p>我们用一个简单的示例来演示同步指标的基本使用。</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="syntaxhighlighter-pre" data-syntaxhighlighter-params="brush: go; gutter: false; theme: Confluence" data-custom-language-resource="com.atlassian.confluence.ext.code.custom.Go.8921870917569589270:custom-code-syntax-resources" data-theme="Confluence">package main
import (
"github.com/prometheus/client_golang/prometheus/promhttp"
"go.opentelemetry.io/otel/exporters/prometheus"
"go.opentelemetry.io/otel/sdk/metric"
"github.com/gogf/gf/contrib/metric/otelmetric/v2"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/net/ghttp"
"github.com/gogf/gf/v2/os/gctx"
"github.com/gogf/gf/v2/os/gmetric"
)
var (
meter = gmetric.GetGlobalProvider().Meter(gmetric.MeterOption{
Instrument: "github.com/gogf/gf/example/metric/basic",
InstrumentVersion: "v1.0",
})
counter = meter.MustCounter(
"goframe.metric.demo.counter",
gmetric.MetricOption{
Help: "This is a simple demo for Counter usage",
Unit: "bytes",
},
)
upDownCounter = meter.MustUpDownCounter(
"goframe.metric.demo.updown_counter",
gmetric.MetricOption{
Help: "This is a simple demo for UpDownCounter usage",
Unit: "%",
},
)
histogram = meter.MustHistogram(
"goframe.metric.demo.histogram",
gmetric.MetricOption{
Help: "This is a simple demo for histogram usage",
Unit: "ms",
Buckets: []float64{0, 10, 20, 50, 100, 500, 1000, 2000, 5000, 10000},
},
)
)
func main() {
var ctx = gctx.New()
// Prometheus exporter to export metrics as Prometheus format.
exporter, err := prometheus.New(
prometheus.WithoutCounterSuffixes(),
prometheus.WithoutUnits(),
)
if err != nil {
g.Log().Fatal(ctx, err)
}
// OpenTelemetry provider.
provider := otelmetric.MustProvider(metric.WithReader(exporter))
provider.SetAsGlobal()
defer provider.Shutdown(ctx)
// Counter.
counter.Inc(ctx)
counter.Add(ctx, 10)
// UpDownCounter.
upDownCounter.Inc(ctx)
upDownCounter.Add(ctx, 10)
upDownCounter.Dec(ctx)
// Record values for histogram.
histogram.Record(1)
histogram.Record(20)
histogram.Record(30)
histogram.Record(101)
histogram.Record(2000)
histogram.Record(9000)
histogram.Record(20000)
// HTTP Server for metrics exporting.
s := g.Server()
s.BindHandler("/metrics", ghttp.WrapH(promhttp.Handler()))
s.SetPort(8000)
s.Run()
}</pre>
</div></div><h1 id="id-监控告警同步指标-Counter&UpDownCounter">Counter&UpDownCounter</h1><p>其中的<code>Counter</code>和<code>UpDownCounter</code>比较简单,这里就不详细介绍了,需要注意的是<code>Counter</code>和<code>UpDownCounter</code>虽然看起来差不多,实际上也是如此,只是为了更严谨和精细化区分使用场景。如果将这两种数据类型映射到经典的<code>Prometheus</code>指标类型中,<code>Counter</code>对应的就是<code>Prometheus</code>的<code>Counter</code>指标类型,而<code>UpDownCounter</code>对应的是<code>Prometheus</code>的<code>Gauge</code>指标类型。</p><h1 id="id-监控告警同步指标-Histogram">Histogram</h1><p><code>Histogram</code>是一种统计类型,通过该指标可以快速统计出指标的<code>p95, p99</code>等百分位统计结果,例如时间开销、成功/失败率等指标。但需要注意该指标比较占内存和空间,不能为其添加过多的<strong>动态属性</strong>,因为不同的属性会衍生出同一种<code>Histogram</code>指标不同的存储数值。</p><h1 id="id-监控告警同步指标-PrimetheusExporter">Primetheus Exporter</h1><p>在该示例中,我们使用了比较常用的<code>Prometheus</code>协议输出指标内容,通常用于对外暴露指标供外部组件抓取。通过以下路由将指标通过<code>Prometheus</code>协议暴露:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="syntaxhighlighter-pre" data-syntaxhighlighter-params="brush: go; gutter: false; theme: Confluence" data-custom-language-resource="com.atlassian.confluence.ext.code.custom.Go.8921870917569589270:custom-code-syntax-resources" data-theme="Confluence">s.BindHandler("/metrics", ghttp.WrapH(promhttp.Handler()))</pre>
</div></div><p>执行后,访问 <a class="external-link" href="http://127.0.0.1:8000/metrics" rel="nofollow">http://127.0.0.1:8000/metrics</a> 查看暴露的指标:</p><p><span class="confluence-embedded-file-wrapper"><img class="confluence-embedded-image" draggable="false" src="https://goframe.org/download/attachments/149880869/image-2024-3-25_20-53-12.png?version=1&modificationDate=1711371193165&api=v2" data-image-src="https://goframe.org/download/attachments/149880869/image-2024-3-25_20-53-12.png?version=1&modificationDate=1711371193165&api=v2" data-unresolved-comment-count="0" data-linked-resource-id="149880875" data-linked-resource-version="1" data-linked-resource-type="attachment" data-linked-resource-default-alias="image-2024-3-25_20-53-12.png" data-base-url="https://goframe.org" data-linked-resource-content-type="image/png" data-linked-resource-container-id="149880869" data-linked-resource-container-version="2" alt=""></span></p><p>我们这里只关注本次示例中的指标,其他自动暴露的指标在后续章节介绍。</p><p><br/></p><p><br/></p></div>
</div>
<div class="cell aside" data-type="aside">
<div class="innerCell">
<div class="panel" style="border-width: 1px;"><div class="panelHeader" style="border-bottom-width: 1px;"><b>Content Menu</b></div><div class="panelContent">
<p><style type='text/css'>/*<![CDATA[*/
div.rbtoc1711679220054 {padding: 0px;}
div.rbtoc1711679220054 ul {margin-left: 0px;}
div.rbtoc1711679220054 li {margin-left: 0px;padding-left: 0px;}
/*]]>*/</style><div class='toc-macro rbtoc1711679220054'>
<ul class='toc-indentation'>
<li><a href='#id-监控告警同步指标-基本介绍'>基本介绍</a></li>
<li><a href='#id-监控告警同步指标-Counter&UpDownCounter'>Counter&UpDownCounter</a></li>
<li><a href='#id-监控告警同步指标-Histogram'>Histogram</a></li>
<li><a href='#id-监控告警同步指标-PrimetheusExporter'>Primetheus Exporter</a></li>
</ul>
</div></p>
</div></div></div>
</div>
</div>
</div>
</div>
<div style="padding: 10px 0;">
<a href="https://goframe.org/pages/viewpage.action?pageId=149880869">View Online</a>
·
<a href="https://goframe.org/pages/diffpagesbyversion.action?pageId=149880869&revisedVersion=2&originalVersion=1">View Changes Online</a>
</div>
</div>
郭强
2024-03-25T11:26:17Z
监控告警-基本使用
郭强
tag:goframe.org,2009:page-148537371-4
2024-03-25T12:12:47Z
2024-03-22T08:31:30Z
<div class="feed"> <p>
Page
<b>edited</b> by
<a href=" https://goframe.org/display/~john
">郭强</a>
</p>
<div style="border-top: 1px solid #ddd; border-bottom: 1px solid #ddd; padding: 10px;">
<div class="contentLayout2">
<div class="columnLayout two-right-sidebar" data-layout="two-right-sidebar">
<div class="cell normal" data-type="normal">
<div class="innerCell">
<h1 id="id-监控告警基本使用-基本介绍">基本介绍</h1><p>监控指标的代码开发直接使用框架主库的<code>gmetric</code>组件即可,但由于<code>gmetric</code>组件实际上只是定义了监控指标的相关接口,并且默认提供的<code>NoopPerformer</code>,默认监控指标特性是关闭的。因此需要引入具体的接口实现组件才能真正开启监控指标特性。框架社区提供了社区组件<code>github.com/gogf/gf/contrib/metric/otelmetric/v2</code>,使用了<code>OpenTelemetry</code>实现框架的监控指标接口,引入该社区组件并且执行监控指标管理对象创建即可开启监控指标特性。<code>otelmetric</code>组件源码地址:<a class="external-link" href="https://github.com/gogf/gf/tree/master/contrib/metric/otelmetric" rel="nofollow">https://github.com/gogf/gf/tree/master/contrib/metric/otelmetric</a></p><p>我们通过一个简单的监控指标实现示例来介绍一下监控指标组件的基本使用。</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="syntaxhighlighter-pre" data-syntaxhighlighter-params="brush: go; gutter: false; theme: Confluence" data-custom-language-resource="com.atlassian.confluence.ext.code.custom.Go.8921870917569589270:custom-code-syntax-resources" data-theme="Confluence">package main
import (
"go.opentelemetry.io/otel/sdk/metric"
"go.opentelemetry.io/otel/sdk/metric/metricdata"
"github.com/gogf/gf/contrib/metric/otelmetric/v2"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gctx"
"github.com/gogf/gf/v2/os/gmetric"
)
var (
meter = gmetric.GetGlobalProvider().Meter(gmetric.MeterOption{
Instrument: "github.com/gogf/gf/example/metric/basic",
InstrumentVersion: "v1.0",
})
counter = meter.MustCounter(
"goframe.metric.demo.counter",
gmetric.MetricOption{
Help: "This is a simple demo for Counter usage",
Unit: "bytes",
},
)
)
func main() {
var (
ctx = gctx.New()
reader = metric.NewManualReader()
)
provider := otelmetric.MustProvider(metric.WithReader(reader))
provider.SetAsGlobal()
defer provider.Shutdown(ctx)
counter.Inc(ctx)
counter.Add(ctx, 10)
var (
rm = metricdata.ResourceMetrics{}
err = reader.Collect(ctx, &rm)
)
if err != nil {
g.Log().Fatal(ctx, err)
}
g.DumpJson(rm)
}</pre>
</div></div><h1 id="id-监控告警基本使用-指标管理组件的创建">指标管理组件的创建</h1><p>通过<code>gmetric.GetGlobalProvider()</code>方法可以获取全局的监控<strong>指标管理对象</strong>,该对象是一个单例设计,全局只能有一个。并通过该对象的<code>Meter</code>方法可以创建/获取对应的<strong>组件对象</strong>。组件对象用于管理该组件下所有的监控指标。在创建组件对象时通常需要定义组件(<code>Instrument</code>)的名称以及版本(虽然也可以为空,但为了方便后续维护建议都设置上)。</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="syntaxhighlighter-pre" data-syntaxhighlighter-params="brush: go; gutter: false; theme: Confluence" data-custom-language-resource="com.atlassian.confluence.ext.code.custom.Go.8921870917569589270:custom-code-syntax-resources" data-theme="Confluence">meter = gmetric.GetGlobalProvider().Meter(gmetric.MeterOption{
Instrument: "github.com/gogf/gf/example/metric/basic",
InstrumentVersion: "v1.0",
})</pre>
</div></div><p>其中的<code>gmeter.MeterOption</code>数据结构如下:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="syntaxhighlighter-pre" data-syntaxhighlighter-params="brush: go; gutter: false; theme: Confluence" data-custom-language-resource="com.atlassian.confluence.ext.code.custom.Go.8921870917569589270:custom-code-syntax-resources" data-theme="Confluence">// MeterOption holds the creation option for a Meter.
type MeterOption struct {
// Instrument is the instrumentation name to bind this Metric to a global MeterProvider.
// This is an optional configuration for a metric.
Instrument string
// InstrumentVersion is the instrumentation version to bind this Metric to a global MeterProvider.
// This is an optional configuration for a metric.
InstrumentVersion string
// Attributes holds the constant key-value pair description metadata for all metrics of Meter.
// This is an optional configuration for a meter.
Attributes Attributes
}</pre>
</div></div><h1 id="id-监控告警基本使用-监控指标对象的创建">监控指标对象的创建</h1><p>通过<code>Meter</code>接口对象,我们可以在该组件下创建对应的各种指标。指标有各种数据类型,因此<code>Meter</code>接口的定义如下:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="syntaxhighlighter-pre" data-syntaxhighlighter-params="brush: go; gutter: false; theme: Confluence" data-custom-language-resource="com.atlassian.confluence.ext.code.custom.Go.8921870917569589270:custom-code-syntax-resources" data-theme="Confluence">// Meter hold the functions for kinds of Metric creating.
type Meter interface {
// Counter creates and returns a new Counter.
Counter(name string, option MetricOption) (Counter, error)
// UpDownCounter creates and returns a new UpDownCounter.
UpDownCounter(name string, option MetricOption) (UpDownCounter, error)
// Histogram creates and returns a new Histogram.
Histogram(name string, option MetricOption) (Histogram, error)
// ObservableCounter creates and returns a new ObservableCounter.
ObservableCounter(name string, option MetricOption) (ObservableCounter, error)
// ObservableUpDownCounter creates and returns a new ObservableUpDownCounter.
ObservableUpDownCounter(name string, option MetricOption) (ObservableUpDownCounter, error)
// ObservableGauge creates and returns a new ObservableGauge.
ObservableGauge(name string, option MetricOption) (ObservableGauge, error)
// MustCounter creates and returns a new Counter.
// It panics if any error occurs.
MustCounter(name string, option MetricOption) Counter
// MustUpDownCounter creates and returns a new UpDownCounter.
// It panics if any error occurs.
MustUpDownCounter(name string, option MetricOption) UpDownCounter
// MustHistogram creates and returns a new Histogram.
// It panics if any error occurs.
MustHistogram(name string, option MetricOption) Histogram
// MustObservableCounter creates and returns a new ObservableCounter.
// It panics if any error occurs.
MustObservableCounter(name string, option MetricOption) ObservableCounter
// MustObservableUpDownCounter creates and returns a new ObservableUpDownCounter.
// It panics if any error occurs.
MustObservableUpDownCounter(name string, option MetricOption) ObservableUpDownCounter
// MustObservableGauge creates and returns a new ObservableGauge.
// It panics if any error occurs.
MustObservableGauge(name string, option MetricOption) ObservableGauge
// RegisterCallback registers callback on certain metrics.
// A callback is bound to certain component and version, it is called when the associated metrics are read.
// Multiple callbacks on the same component and version will be called by their registered sequence.
RegisterCallback(callback Callback, canBeCallbackMetrics ...ObservableMetric) error
// MustRegisterCallback performs as RegisterCallback, but it panics if any error occurs.
MustRegisterCallback(callback Callback, canBeCallbackMetrics ...ObservableMetric)
}</pre>
</div></div><p>以本示例代码中使用的<code>meter.MustCounter</code>方法来介绍,该方法是创建一个<code>Counter</code>同步指标,同时由于我们偷懒这个使用了<code>Must*</code>方法,也就是说如果创建指标失败,那么这个方法会<code>panic</code>报错。</p><p>在创建指标对象时,指标名称<code>name</code>是必须参数,另外的<code>MetricOption</code>是可选项参数,用于进一步描述指标信息。<code>MetricOption</code>的数据结构定义如下:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="syntaxhighlighter-pre" data-syntaxhighlighter-params="brush: go; gutter: false; theme: Confluence" data-custom-language-resource="com.atlassian.confluence.ext.code.custom.Go.8921870917569589270:custom-code-syntax-resources" data-theme="Confluence">// MetricOption holds the basic options for creating a metric.
type MetricOption struct {
// Help provides information about this Histogram.
// This is an optional configuration for a metric.
Help string
// Unit is the unit for metric value.
// This is an optional configuration for a metric.
Unit string
// Attributes holds the constant key-value pair description metadata for this metric.
// This is an optional configuration for a metric.
Attributes Attributes
// Buckets defines the buckets into which observations are counted.
// For Histogram metric only.
// A histogram metric uses default buckets if no explicit buckets configured.
Buckets []float64
// Callback function for metric, which is called when metric value changes.
// For observable metric only.
// If an observable metric has either Callback attribute nor global callback configured, it does nothing.
Callback MetricCallback
}</pre>
</div></div><h1 id="id-监控告警基本使用-初始化监控指标实现">初始化监控指标实现</h1><p> 通过<code>otelmetric.MustProvider</code>创建方法即可创建并初始化监控指标管理对象。</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="syntaxhighlighter-pre" data-syntaxhighlighter-params="brush: go; gutter: false; theme: Confluence" data-custom-language-resource="com.atlassian.confluence.ext.code.custom.Go.8921870917569589270:custom-code-syntax-resources" data-theme="Confluence">provider := otelmetric.MustProvider(metric.WithReader(reader))
provider.SetAsGlobal()
defer provider.Shutdown(ctx)</pre>
</div></div><p>前面我们有介绍到,<code>GlobalProvider</code>其实是一个单例的指标管理对象,因此这里通过<code>provider.SetAsGlobal</code>方法调用可以将该对象设置为全局的指标管理对象,便于后续的指标创建均基于该对象创建。</p><p>我们在<code>main</code>函数中通过<code>defer provider.ShutDown</code>方法调用便于在程序结束时优雅结束指标管理对象,例如对象中的指标缓存及时输出到目标端。</p><h1 id="id-监控告警基本使用-监控指标对象的使用">监控指标对象的使用</h1><p>不同的指标对象有不同的操作方法用于实现指标数值的变化。以示例中的<code>Counter</code>指标类型为例,其接口定义如下:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="syntaxhighlighter-pre" data-syntaxhighlighter-params="brush: go; gutter: false; theme: Confluence" data-custom-language-resource="com.atlassian.confluence.ext.code.custom.Go.8921870917569589270:custom-code-syntax-resources" data-theme="Confluence">// Counter is a Metric that represents a single numerical value that can ever
// goes up.
type Counter interface {
Metric
CounterPerformer
}
// CounterPerformer performs operations for Counter metric.
type CounterPerformer interface {
// Inc increments the counter by 1. Use Add to increment it by arbitrary
// non-negative values.
Inc(ctx context.Context, option ...Option)
// Add adds the given value to the counter. It panics if the value is < 0.
Add(ctx context.Context, increment float64, option ...Option)
}</pre>
</div></div><p>可以看到,<code>Counter</code>指标主要可以执行<code>Inc</code>及<code>Add</code>两个操作方法。其中还有一个<code>Metric</code>的接口,所有的指标均实现了该接口用于获取当前指标的基础信息,其接口定义如下:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="syntaxhighlighter-pre" data-syntaxhighlighter-params="brush: go; gutter: false; theme: Confluence" data-custom-language-resource="com.atlassian.confluence.ext.code.custom.Go.8921870917569589270:custom-code-syntax-resources" data-theme="Confluence">// Metric models a single sample value with its metadata being exported.
type Metric interface {
// Info returns the basic information of a Metric.
Info() MetricInfo
}
// MetricInfo exports information of the Metric.
type MetricInfo interface {
Key() string // Key returns the unique string key of the metric.
Name() string // Name returns the name of the metric.
Help() string // Help returns the help description of the metric.
Unit() string // Unit returns the unit name of the metric.
Type() MetricType // Type returns the type of the metric.
Attributes() Attributes // Attributes returns the constant attribute slice of the metric.
Instrument() InstrumentInfo // InstrumentInfo returns the instrument info of the metric.
}
// InstrumentInfo exports the instrument information of a metric.
type InstrumentInfo interface {
Name() string // Name returns the instrument name of the metric.
Version() string // Version returns the instrument version of the metric.
}</pre>
</div></div><h1 id="id-监控告警基本使用-监控指标的数据读取">监控指标的数据读取</h1><p>通过上一章节介绍的<code>OpenTelemetry</code>组件关系我们知道,如果想要使用指标必须要通过<code>MetricReader</code>,因此在该示例代码中我们通过最常用的<code>ManualReader</code>来简单实现指标数据读取,<code>ManualReader</code>是<code>OpenTelemetry</code>官方社区提供的实现。</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="syntaxhighlighter-pre" data-syntaxhighlighter-params="brush: go; gutter: false; theme: Confluence" data-custom-language-resource="com.atlassian.confluence.ext.code.custom.Go.8921870917569589270:custom-code-syntax-resources" data-theme="Confluence">reader = metric.NewManualReader()</pre>
</div></div><p>并通过<code>WithReader</code>方法配置到<code>Provider</code>中:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="syntaxhighlighter-pre" data-syntaxhighlighter-params="brush: go; gutter: false; theme: Confluence" data-custom-language-resource="com.atlassian.confluence.ext.code.custom.Go.8921870917569589270:custom-code-syntax-resources" data-theme="Confluence">provider := otelmetric.MustProvider(metric.WithReader(reader))</pre>
</div></div><p>随后通过<code>Collect</code>方法可以获取当前所有的指标数据:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="syntaxhighlighter-pre" data-syntaxhighlighter-params="brush: go; gutter: false; theme: Confluence" data-custom-language-resource="com.atlassian.confluence.ext.code.custom.Go.8921870917569589270:custom-code-syntax-resources" data-theme="Confluence">var (
rm = metricdata.ResourceMetrics{}
err = reader.Collect(ctx, &rm)
)
if err != nil {
g.Log().Fatal(ctx, err)
}
g.DumpJson(rm)</pre>
</div></div><p> 执行后,终端输出:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="syntaxhighlighter-pre" data-syntaxhighlighter-params="brush: xml; gutter: false; theme: Confluence" data-theme="Confluence">...
"ScopeMetrics": [
{
"Scope": {
"Name": "github.com/gogf/gf/example/metric/basic",
"Version": "v1.0",
"SchemaURL": ""
},
"Metrics": [
{
"Name": "goframe.metric.demo.counter",
"Description": "This is a simple demo for Counter usage",
"Unit": "bytes",
"Data": {
"DataPoints": [
{
"Attributes": [],
"StartTime": "2024-03-25T10:13:19.326977+08:00",
"Time": "2024-03-25T10:13:19.327144+08:00",
"Value": 11
}
],
"Temporality": "CumulativeTemporality",
"IsMonotonic": true
}
}
]
},
...</pre>
</div></div><p> 为了简化示例介绍,我们在这里省略了一些输出内容,更详细的指标及输出介绍请参考后续章节。</p><p><br/></p><p><br/></p><p><br/></p><p><br/></p></div>
</div>
<div class="cell aside" data-type="aside">
<div class="innerCell">
<div class="panel" style="border-width: 1px;"><div class="panelHeader" style="border-bottom-width: 1px;"><b>Content Menu</b></div><div class="panelContent">
<p><style type='text/css'>/*<![CDATA[*/
div.rbtoc1711679220087 {padding: 0px;}
div.rbtoc1711679220087 ul {margin-left: 0px;}
div.rbtoc1711679220087 li {margin-left: 0px;padding-left: 0px;}
/*]]>*/</style><div class='toc-macro rbtoc1711679220087'>
<ul class='toc-indentation'>
<li><a href='#id-监控告警基本使用-基本介绍'>基本介绍</a></li>
<li><a href='#id-监控告警基本使用-指标管理组件的创建'>指标管理组件的创建</a></li>
<li><a href='#id-监控告警基本使用-监控指标对象的创建'>监控指标对象的创建</a></li>
<li><a href='#id-监控告警基本使用-初始化监控指标实现'>初始化监控指标实现</a></li>
<li><a href='#id-监控告警基本使用-监控指标对象的使用'>监控指标对象的使用</a></li>
<li><a href='#id-监控告警基本使用-监控指标的数据读取'>监控指标的数据读取</a></li>
</ul>
</div></p>
</div></div></div>
</div>
</div>
</div>
</div>
<div style="padding: 10px 0;">
<a href="https://goframe.org/pages/viewpage.action?pageId=148537371">View Online</a>
·
<a href="https://goframe.org/pages/diffpagesbyversion.action?pageId=148537371&revisedVersion=4&originalVersion=3">View Changes Online</a>
</div>
</div>
郭强
2024-03-22T08:31:30Z
监控告警-指标属性
郭强
tag:goframe.org,2009:page-148537373-1
2024-03-24T13:17:05Z
2024-03-22T08:32:34Z
<div class="feed"> <p>
Page
<b>added</b> by
<a href=" https://goframe.org/display/~john
">郭强</a>
</p>
<div style="border-top: 1px solid #ddd; border-bottom: 1px solid #ddd; padding: 10px;">
<div class="contentLayout2">
<div class="columnLayout two-right-sidebar" data-layout="two-right-sidebar">
<div class="cell normal" data-type="normal">
<div class="innerCell">
<p><br/></p><p><br/></p><p><br/></p><p><br/></p><p><br/></p></div>
</div>
<div class="cell aside" data-type="aside">
<div class="innerCell">
<div class="panel" style="border-width: 1px;"><div class="panelHeader" style="border-bottom-width: 1px;"><b>Content Menu</b></div><div class="panelContent">
<p><style type='text/css'>/*<![CDATA[*/
div.rbtoc1711679220100 {padding: 0px;}
div.rbtoc1711679220100 ul {margin-left: 0px;}
div.rbtoc1711679220100 li {margin-left: 0px;padding-left: 0px;}
/*]]>*/</style><div class='toc-macro rbtoc1711679220100'>
<ul class='toc-indentation'>
</ul>
</div></p>
</div></div></div>
</div>
</div>
</div>
</div>
<div style="padding: 10px 0;">
<a href="https://goframe.org/pages/viewpage.action?pageId=148537373">View Online</a>
</div>
</div>
郭强
2024-03-22T08:32:34Z
监控告警-基本介绍
郭强
tag:goframe.org,2009:page-148537358-8
2024-03-24T13:07:30Z
2024-03-22T06:27:08Z
<div class="feed"> <p>
Page
<b>edited</b> by
<a href=" https://goframe.org/display/~john
">郭强</a>
</p>
<div style="border-top: 1px solid #ddd; border-bottom: 1px solid #ddd; padding: 10px;">
<div class="contentLayout2">
<div class="columnLayout two-right-sidebar" data-layout="two-right-sidebar">
<div class="cell normal" data-type="normal">
<div class="innerCell">
在介绍框架的监控告警之前,我们离不开业内可观测性的标准介绍,<code>OpenTelemetry</code>关于监控告警这块的设计,以及相关规范。<code>OpenTelemetry</code>在这块的内容也比较多,我们选择一些重点来介绍一下。<h1 id="id-监控告警基本介绍-OpenTelemetry">OpenTelemetry</h1><h2 id="id-监控告警基本介绍-相关组件">相关组件</h2><p>我们来看一张<code>OpenTelemetry</code>组件的关系图,在<code>OpenTelemetry Metrics</code>标准的实现中,主要包含以下组件。</p><p><span class="confluence-embedded-file-wrapper"><img class="confluence-embedded-image" draggable="false" src="https://goframe.org/download/attachments/148537358/meter-provider-overview.png?version=1&modificationDate=1711090573081&api=v2" data-image-src="https://goframe.org/download/attachments/148537358/meter-provider-overview.png?version=1&modificationDate=1711090573081&api=v2" data-unresolved-comment-count="0" data-linked-resource-id="148537360" data-linked-resource-version="1" data-linked-resource-type="attachment" data-linked-resource-default-alias="meter-provider-overview.png" data-base-url="https://goframe.org" data-linked-resource-content-type="image/png" data-linked-resource-container-id="148537358" data-linked-resource-container-version="8" alt=""></span></p><p>在标准化文档的落地时,各个组件通常都是采用接口化设计,以提高可扩展性:</p><h3 id="id-监控告警基本介绍-MeterProvider">Meter Provider</h3><p>用于接口化管理全局的<code>Meter</code>创建,相当于全局的监控指标管理工厂。</p><h3 id="id-监控告警基本介绍-Meter">Meter</h3><p>用于接口化创建并管理全局的<code>Instrument</code>,不同的<code>Meter</code>可以看做是不同的程序组件。例如框架中的各个组件可以看做是不同的<code>Meter</code>,比如<code>gclient</code>和<code>ghttp</code>就是两个不同的<code>Meter</code>。</p><h3 id="id-监控告警基本介绍-Instrument">Instrument</h3><p>用于管理不同组件下的各个不同类型的指标,例如在<code>ghttp</code>下,就会有<code>http.server.request.duration</code>、<code>http.server.request.body_size</code>等指标。</p><h3 id="id-监控告警基本介绍-Measurements">Measurements</h3><p>对应指标上报的具体的<code>DataPoint</code>指标数据,是一系列的数值项。</p><h3 id="id-监控告警基本介绍-View">View</h3><p>实现对<code>Measurements</code>的计算、汇总、过滤、修改等操作,通常指标都是<strong>数值类型</strong>,所以这个通常都使用默认的<code>View</code>即可。</p><h3 id="id-监控告警基本介绍-MetricReader">Metric Reader</h3><p>用于实现对指标的数据流读取,内部定义了具体操作指标的数据结构。<code>OpenTelemetry</code>官方社区提供了多种灵活的<code>Reader</code>实现,例如<code>PeridRader</code>、<code>ManualReader</code>等。</p><h3 id="id-监控告警基本介绍-MetricExporter">Metric Exporter</h3><p><code>Exporter</code>用于暴露本地指标到对应的第三方厂商,定义了具体是<code>push</code>还是<code>pull</code>的数据传输方式。<code>Exporter</code>需要用到<code>Reader</code>,其中<code>Reader</code>只有几种方式,但是<code>Exporter</code>会根据厂商而定,会有很多,例如:<code>promtheus</code>、<code>zipkin</code>等。</p><p>一个<code>Instrument</code>多个<code>DataPoint</code>的数据流如下图所示:</p><p><span style="color: rgb(32,35,40);"><span class="confluence-embedded-file-wrapper"><img class="confluence-embedded-image" draggable="false" src="https://goframe.org/download/attachments/148537358/measurements-to-metrics.png?version=1&modificationDate=1711091523809&api=v2" data-image-src="https://goframe.org/download/attachments/148537358/measurements-to-metrics.png?version=1&modificationDate=1711091523809&api=v2" data-unresolved-comment-count="0" data-linked-resource-id="148537363" data-linked-resource-version="1" data-linked-resource-type="attachment" data-linked-resource-default-alias="measurements-to-metrics.png" data-base-url="https://goframe.org" data-linked-resource-content-type="image/png" data-linked-resource-container-id="148537358" data-linked-resource-container-version="8" alt=""></span></span></p><h2 id="id-监控告警基本介绍-相关类型">相关类型</h2><p><code>OpenTelemetry</code>的社区实现为了满足不同的使用场景,因此类型的设计粒度比较细,分为<code>int64</code>和<code>float64</code>数据类型,并且包含<strong>同步</strong>和<strong>异步</strong>指标类型。</p><h3 id="id-监控告警基本介绍-同步类型">同步类型</h3><p><strong>同步类型</strong>用于快速暴露监控指标,无论<code>metrics reader</code>是否使用该监控指标,指标的计算结果已完成,待读取使用。例如,HTTP的请求总数、请求大小,这些数值必须在请求执行流程中记录到对应的监控指标数值中,适合作为同步指标来管理。</p><div class="table-wrap"><table class="relative-table wrapped confluenceTable" style="width: 99.4845%;"><colgroup><col style="width: 32.6264%;"/><col style="width: 32.3604%;"/><col style="width: 35.0132%;"/></colgroup><tbody class=""><tr class=""><th style="text-align: left;vertical-align: top;" class="confluenceTh"><p class="paragraph"><strong>类型</strong></p></th><th style="text-align: left;vertical-align: top;" class="confluenceTh"><p class="paragraph"><strong>描述</strong></p></th><th style="text-align: left;vertical-align: top;" class="confluenceTh"><p class="paragraph"><strong>示例</strong></p></th></tr><tr class=""><td style="text-align: left;vertical-align: top;" class="confluenceTd"><p class="paragraph"><code>Int64Counter</code></p></td><td class="confluenceTd"><p class="paragraph"><code>int64</code>只增不减的指标。</p></td><td style="text-align: left;vertical-align: top;" class="confluenceTd"><p class="paragraph">请求总数、请求字节总大小</p></td></tr><tr class=""><td style="text-align: left;vertical-align: top;" class="confluenceTd"><p class="paragraph"><code>Int64UpDownCounter</code></p></td><td class="confluenceTd"><p class="paragraph"><code>int64</code>可增可减的指标。</p></td><td style="text-align: left;vertical-align: top;" class="confluenceTd"><p class="paragraph">当前活跃请求、执行队列大小</p></td></tr><tr class=""><td style="text-align: left;vertical-align: top;" class="confluenceTd"><p class="paragraph"><code>Float64Counter</code></p></td><td class="confluenceTd"><p class="paragraph"><code>float64</code>只增不减的指标。</p></td><td style="text-align: left;vertical-align: top;" class="confluenceTd"><p class="paragraph">请求总数、请求字节总大小</p></td></tr><tr class=""><td style="text-align: left;vertical-align: top;" class="confluenceTd"><p class="paragraph"><code>Float64UpDownCounter</code></p></td><td class="confluenceTd"><p class="paragraph"><code>float64</code>可增可减的指标。</p></td><td style="text-align: left;vertical-align: top;" class="confluenceTd"><p class="paragraph">请求总数、请求字节总大小</p></td></tr><tr><td style="text-align: left;vertical-align: top;" class="confluenceTd"><p class="paragraph"><code>Int64Histogram</code></p></td><td class="confluenceTd"><p class="paragraph"><code>int64</code>可分组的指标</p></td><td style="text-align: left;vertical-align: top;" class="confluenceTd"><p class="paragraph">请求执行时间<code>p99</code></p></td></tr><tr><td style="text-align: left;vertical-align: top;" class="confluenceTd"><p class="paragraph"><code>Float64Histogram</code></p></td><td class="confluenceTd"><p class="paragraph"><code>float64</code>可分组的指标</p></td><td style="text-align: left;vertical-align: top;" class="confluenceTd"><p class="paragraph">请求执行时间<code>p99</code></p></td></tr></tbody></table></div><h3 id="id-监控告警基本介绍-异步类型">异步类型</h3><p><strong>异步类型</strong>的监控指标只有在<code>metrics reader</code>开始使用该监控指标时才会执行指标计算逻辑。异步类型的监控指标需要设置一个回调函数,该回调函数用于生成指标数值,并在<code>metrics reader</code>读取指标时才会触发回调函数。例如,机器CPU、内存、磁盘使用量的指标,如果没有目标端拉取或者使用该指标时,提前计算指标值毫无意义且浪费计算资源,适合作为异步指标来管理。</p><div class="table-wrap"><table class="relative-table wrapped confluenceTable" style="width: 99.7489%;"><colgroup><col style="width: 32.4516%;"/><col style="width: 32.3632%;"/><col style="width: 35.1851%;"/></colgroup><tbody class=""><tr class=""><th style="text-align: left;vertical-align: top;" class="confluenceTh"><p class="paragraph"><strong>类型</strong></p></th><th style="text-align: left;vertical-align: top;" class="confluenceTh"><p class="paragraph"><strong>描述</strong></p></th><th style="text-align: left;vertical-align: top;" class="confluenceTh"><p class="paragraph"><strong>示例</strong></p></th></tr><tr class=""><td style="text-align: left;vertical-align: top;" class="confluenceTd"><p class="paragraph"><code>Int64ObservableCouter</code></p></td><td class="confluenceTd"><p class="paragraph"><code>int64</code>只增不减的指标。</p></td><td style="text-align: left;vertical-align: top;" class="confluenceTd"><p class="paragraph">CPU、内存、磁盘使用量</p></td></tr><tr class=""><td style="text-align: left;vertical-align: top;" class="confluenceTd"><p class="paragraph"><code>Int64ObservableUpDownCounter</code></p></td><td class="confluenceTd"><p class="paragraph"><code>int64</code>可增可减的指标。</p></td><td style="text-align: left;vertical-align: top;" class="confluenceTd"><p class="paragraph">CPU、内存、磁盘使用量</p></td></tr><tr class=""><td style="text-align: left;vertical-align: top;" class="confluenceTd"><p class="paragraph"><code>Float64ObservableCouter</code></p></td><td class="confluenceTd"><p class="paragraph"><code>float64</code>只增不减的指标。</p></td><td style="text-align: left;vertical-align: top;" class="confluenceTd"><p class="paragraph">CPU、内存、磁盘使用量</p></td></tr><tr class=""><td style="text-align: left;vertical-align: top;" class="confluenceTd"><p class="paragraph"><code>Float64ObservableUpDownCounter</code></p></td><td class="confluenceTd"><p class="paragraph"><code>float64</code>可增可减的指标。</p></td><td style="text-align: left;vertical-align: top;" class="confluenceTd"><p class="paragraph">当前活跃请求、执行队列大小</p></td></tr><tr class=""><td style="text-align: left;vertical-align: top;" class="confluenceTd"><p class="paragraph"><code>Int64ObservableGauge</code></p></td><td class="confluenceTd"><p class="paragraph"><code>int64</code>可增可减的指标。</p></td><td style="text-align: left;vertical-align: top;" class="confluenceTd"><p class="paragraph">CPU、内存、磁盘使用量</p></td></tr><tr class=""><td style="text-align: left;vertical-align: top;" class="confluenceTd"><p class="paragraph"><code>Float64ObservableGauge</code></p></td><td class="confluenceTd"><p class="paragraph"><code>float64</code>可增可减动态设置的指标。</p></td><td style="text-align: left;vertical-align: top;" class="confluenceTd"><p class="paragraph">CPU、内存、磁盘使用量</p></td></tr></tbody></table></div><h1 id="id-监控告警基本介绍-框架监控组件">框架监控组件</h1><h2 id="id-监控告警基本介绍-组件抽象">组件抽象</h2><p>框架通过<code>gmetric</code>组件来实现监控能力,<code>gmetric</code>组件内部设计的组件层级关系同<code>OpenTelemetry Metrics</code>类似:</p><p><span class="confluence-embedded-file-wrapper"><img class="confluence-embedded-image" draggable="false" src="https://goframe.org/download/attachments/148537358/image-2024-3-24_20-56-4.png?version=1&modificationDate=1711284965346&api=v2" data-image-src="https://goframe.org/download/attachments/148537358/image-2024-3-24_20-56-4.png?version=1&modificationDate=1711284965346&api=v2" data-unresolved-comment-count="0" data-linked-resource-id="149487618" data-linked-resource-version="1" data-linked-resource-type="attachment" data-linked-resource-default-alias="image-2024-3-24_20-56-4.png" data-base-url="https://goframe.org" data-linked-resource-content-type="image/png" data-linked-resource-container-id="148537358" data-linked-resource-container-version="8" alt=""></span></p><p><code>gmetric</code>组件使用了<strong>抽象解耦设计</strong>,一方面是因为框架设计需要减少外部依赖;另一方面是为了实现监控的自动开关能力。组件默认情况下使用了<code>NoopPerform</code>的实现对象,在默认情况下监控能力是关闭的,只有在真正引入监控接口实现时才会自动开启监控能力。</p><p><span class="confluence-embedded-file-wrapper"><img class="confluence-embedded-image" draggable="false" src="https://goframe.org/download/attachments/148537358/image-2024-3-24_21-1-39.png?version=1&modificationDate=1711285302315&api=v2" data-image-src="https://goframe.org/download/attachments/148537358/image-2024-3-24_21-1-39.png?version=1&modificationDate=1711285302315&api=v2" data-unresolved-comment-count="0" data-linked-resource-id="149487619" data-linked-resource-version="1" data-linked-resource-type="attachment" data-linked-resource-default-alias="image-2024-3-24_21-1-39.png" data-base-url="https://goframe.org" data-linked-resource-content-type="image/png" data-linked-resource-container-id="148537358" data-linked-resource-container-version="8" alt=""></span></p><h2 id="id-监控告警基本介绍-指标类型">指标类型</h2><p>框架提供的指标类型相比较<code>OpenTelmetry</code>社区实现去掉了<code>int64</code>数值类型,而是使用了统一的<code>float64</code>数值类型以简化使用。但同时需要注意,开发者在设计指标数值时<strong>尽可能避免小数设计,以避免数值计算的精度问题</strong>。特别是在<code>Histogram</code>类型的<code>Buckets</code>设计时,不建议使用小数。</p><h3 id="id-监控告警基本介绍-同步类型.1">同步类型</h3><div class="table-wrap"><table class="relative-table wrapped confluenceTable" style="width: 99.132%;"><colgroup class=""><col class="" style="width: 33.2737%;"/><col class="" style="width: 34.5192%;"/><col class="" style="width: 32.2071%;"/></colgroup><tbody class=""><tr class=""><th style="text-align: left;vertical-align: top;" class="confluenceTh"><p class="paragraph"><strong>类型</strong></p></th><th style="text-align: left;vertical-align: top;" class="confluenceTh"><p class="paragraph"><strong>描述</strong></p></th><th style="text-align: left;vertical-align: top;" class="confluenceTh"><p class="paragraph"><strong>示例</strong></p></th></tr><tr class=""><td style="text-align: left;vertical-align: top;" class="confluenceTd"><p class="paragraph"><code>Counter</code></p></td><td class="confluenceTd"><p class="paragraph"><code>float64</code>只增不减的指标。</p></td><td style="text-align: left;vertical-align: top;" class="confluenceTd"><p class="paragraph">请求总数、请求字节总大小</p></td></tr><tr class=""><td style="text-align: left;vertical-align: top;" class="confluenceTd"><p class="paragraph"><code>UpDownCounter</code></p></td><td class="confluenceTd"><p class="paragraph"><code>float64</code>可增可减的指标。</p></td><td style="text-align: left;vertical-align: top;" class="confluenceTd"><p class="paragraph">请求总数、请求字节总大小</p></td></tr><tr class=""><td style="text-align: left;vertical-align: top;" class="confluenceTd"><p class="paragraph"><code>Histogram</code></p></td><td class="confluenceTd"><p class="paragraph"><code>float64</code>可分组的指标</p></td><td style="text-align: left;vertical-align: top;" class="confluenceTd"><p class="paragraph">请求执行时间<code>p99</code></p></td></tr></tbody></table></div><h3 id="id-监控告警基本介绍-异步类型.1">异步类型 </h3><div class="table-wrap"><table class="relative-table wrapped confluenceTable" style="width: 99.132%;"><colgroup class=""><col class="" style="width: 32.7399%;"/><col class="" style="width: 34.7861%;"/><col class="" style="width: 32.4741%;"/></colgroup><tbody class=""><tr class=""><th style="text-align: left;vertical-align: top;" class="confluenceTh"><p class="paragraph"><strong>类型</strong></p></th><th style="text-align: left;vertical-align: top;" class="confluenceTh"><p class="paragraph"><strong>描述</strong></p></th><th style="text-align: left;vertical-align: top;" class="confluenceTh"><p class="paragraph"><strong>示例</strong></p></th></tr><tr class=""><td style="text-align: left;vertical-align: top;" class="confluenceTd"><p class="paragraph"><code>ObservableCounter</code></p></td><td class="confluenceTd"><p class="paragraph"><code>float64</code>只增不减的指标。</p></td><td style="text-align: left;vertical-align: top;" class="confluenceTd"><p class="paragraph">请求总数、请求字节总大小</p></td></tr><tr class=""><td style="text-align: left;vertical-align: top;" class="confluenceTd"><p class="paragraph"><code>ObservableUpDownCounter</code></p></td><td class="confluenceTd"><p class="paragraph"><code>float64</code>可增可减的指标。</p></td><td style="text-align: left;vertical-align: top;" class="confluenceTd"><p class="paragraph">请求总数、请求字节总大小</p></td></tr><tr class=""><td style="text-align: left;vertical-align: top;" class="confluenceTd"><p class="paragraph"><code>ObservableGauge</code></p></td><td class="confluenceTd"><p class="paragraph"><code>float64</code>可增可减动态设置的指标。</p></td><td style="text-align: left;vertical-align: top;" class="confluenceTd"><p class="paragraph">CPU、内存、磁盘使用量</p></td></tr></tbody></table></div><h1 id="id-监控告警基本介绍-参考资料">参考资料</h1><ul class="ak-ul"><li><p class="paragraph"><a class="external-link" href="https://github.com/prometheus/client_golang" rel="nofollow" style="text-decoration: none;" title="https://github.com/prometheus/client_golang">https://github.com/prometheus/client_golang</a></p></li><li><p class="paragraph"><a class="external-link" href="https://github.com/open-telemetry/opentelemetry-go-contrib" rel="nofollow" style="text-decoration: none;" title="https://github.com/open-telemetry/opentelemetry-go-contrib">https://github.com/open-telemetry/opentelemetry-go-contrib</a></p></li><li><p class="paragraph"><a class="external-link" href="https://opentelemetry.io/docs/specs/otel/metrics/api/" rel="nofollow" style="text-decoration: none;" title="https://opentelemetry.io/docs/specs/otel/metrics/api/">https://opentelemetry.io/docs/specs/otel/metrics/api/</a></p></li><li><p class="paragraph"><a class="external-link" href="https://opentelemetry.io/docs/specs/otel/metrics/data-model" rel="nofollow" style="text-decoration: none;" title="https://opentelemetry.io/docs/specs/otel/metrics/data-model">https://opentelemetry.io/docs/specs/otel/metrics/data-model</a></p></li></ul><p><br/></p><p><br/></p><p><br/></p><p><br/></p></div>
</div>
<div class="cell aside" data-type="aside">
<div class="innerCell">
<div class="panel" style="border-width: 1px;"><div class="panelHeader" style="border-bottom-width: 1px;"><b>Content Menu</b></div><div class="panelContent">
<p><style type='text/css'>/*<![CDATA[*/
div.rbtoc1711679220131 {padding: 0px;}
div.rbtoc1711679220131 ul {margin-left: 0px;}
div.rbtoc1711679220131 li {margin-left: 0px;padding-left: 0px;}
/*]]>*/</style><div class='toc-macro rbtoc1711679220131'>
<ul class='toc-indentation'>
<li><a href='#id-监控告警基本介绍-OpenTelemetry'>OpenTelemetry</a>
<ul class='toc-indentation'>
<li><a href='#id-监控告警基本介绍-相关组件'>相关组件</a>
<ul class='toc-indentation'>
<li><a href='#id-监控告警基本介绍-MeterProvider'>Meter Provider</a></li>
<li><a href='#id-监控告警基本介绍-Meter'>Meter</a></li>
<li><a href='#id-监控告警基本介绍-Instrument'>Instrument</a></li>
<li><a href='#id-监控告警基本介绍-Measurements'>Measurements</a></li>
<li><a href='#id-监控告警基本介绍-View'>View</a></li>
<li><a href='#id-监控告警基本介绍-MetricReader'>Metric Reader</a></li>
<li><a href='#id-监控告警基本介绍-MetricExporter'>Metric Exporter</a></li>
</ul>
</li>
<li><a href='#id-监控告警基本介绍-相关类型'>相关类型</a>
<ul class='toc-indentation'>
<li><a href='#id-监控告警基本介绍-同步类型'>同步类型</a></li>
<li><a href='#id-监控告警基本介绍-异步类型'>异步类型</a></li>
</ul>
</li>
</ul>
</li>
<li><a href='#id-监控告警基本介绍-框架监控组件'>框架监控组件</a>
<ul class='toc-indentation'>
<li><a href='#id-监控告警基本介绍-组件抽象'>组件抽象</a></li>
<li><a href='#id-监控告警基本介绍-指标类型'>指标类型</a>
<ul class='toc-indentation'>
<li><a href='#id-监控告警基本介绍-同步类型.1'>同步类型</a></li>
<li><a href='#id-监控告警基本介绍-异步类型.1'>异步类型</a></li>
</ul>
</li>
</ul>
</li>
<li><a href='#id-监控告警基本介绍-参考资料'>参考资料</a></li>
</ul>
</div></p>
</div></div></div>
</div>
</div>
</div>
</div>
<div style="padding: 10px 0;">
<a href="https://goframe.org/pages/viewpage.action?pageId=148537358">View Online</a>
·
<a href="https://goframe.org/pages/diffpagesbyversion.action?pageId=148537358&revisedVersion=8&originalVersion=7">View Changes Online</a>
</div>
</div>
郭强
2024-03-22T06:27:08Z
链路跟踪-背景知识
郭强
tag:goframe.org,2009:page-38575612-5
2024-03-22T08:23:41Z
2022-02-09T08:19:20Z
<div class="feed"> <p>
Page
<b>edited</b> by
<a href=" https://goframe.org/display/~john
">郭强</a>
</p>
<div style="border-top: 1px solid #ddd; border-bottom: 1px solid #ddd; padding: 10px;">
<div class="contentLayout2">
<div class="columnLayout two-right-sidebar" data-layout="two-right-sidebar">
<div class="cell normal" data-type="normal">
<div class="innerCell">
<h1 id="id-链路跟踪背景知识-OpenTelemetry">OpenTelemetry</h1><p>分布式链路跟踪(<code>
<span>Distributed Tracing</span>
</code>)的概念最早是由<code>Google</code>提出来的,发展至今技术已经比较成熟,也是有一些协议标准可以参考。目前在<code>Tracing</code>技术这块比较有影响力的是两大开源技术框架:<code>Netflix</code>公司开源的<code>OpenTracing</code>和<code>Google</code>开源的<code>OpenCensus</code>。两大框架都拥有比较高的开发者群体。为形成统一的技术标准,两大框架最终磨合成立了<code>OpenTelemetry</code>项目,简称<code>otel</code>。具体可以参考:</p><ol><li><a href="https://goframe.org/pages/viewpage.action?pageId=3673400" rel="nofollow">OpenTracing介绍</a></li><li><a href="https://goframe.org/pages/viewpage.action?pageId=3673499" rel="nofollow">OpenTelemetry介绍</a></li></ol><p>因此,我们的<code>Tracing</code>技术方案以<code>OpenTelemetry</code>为实施标准,协议标准的一些<code>Golang</code>实现开源项目:</p><ol><li><a class="external-link" href="https://github.com/open-telemetry/opentelemetry-go" rel="nofollow" style="text-decoration: none;">https://github.com/open-telemetry/opentelemetry-go</a></li><li><a class="external-link" href="https://github.com/open-telemetry/opentelemetry-go-contrib" rel="nofollow" style="text-decoration: none;">https://github.com/open-telemetry/opentelemetry-go-contrib</a></li></ol><p>其他第三方的框架和系统(如<code>Jaeger/Prometheus/Grafana</code>等)也会按照标准化的规范来对接<code>OpenTelemetry</code>,使得系统的开发和维护成本大大降低。</p><p><span class="confluence-embedded-file-wrapper image-center-wrapper"> <span class="confluence-embedded-file-wrapper image-center-wrapper"><img class="confluence-embedded-image image-center" draggable="false" src="https://goframe.org/download/attachments/38575612/OpenTelemetry_Collector.jpg?version=1&modificationDate=1644394795839&api=v2" data-image-src="https://goframe.org/download/attachments/38575612/OpenTelemetry_Collector.jpg?version=1&modificationDate=1644394795839&api=v2" data-unresolved-comment-count="0" data-linked-resource-id="38575613" data-linked-resource-version="1" data-linked-resource-type="attachment" data-linked-resource-default-alias="OpenTelemetry_Collector.jpg" data-base-url="https://goframe.org" data-linked-resource-content-type="image/jpeg" data-linked-resource-container-id="38575612" data-linked-resource-container-version="5" alt=""></span> </span></p><h1 id="id-链路跟踪背景知识-重要概念">重要概念</h1><p>我们先看看<code>OpenTelemetry</code>的架构图,我们这里不会完整介绍,只会介绍其中大家常用的几个概念。关于<code>OpenTelemetry</code>的内部技术架构设计介绍,可以参考 <a href="https://goframe.org/pages/viewpage.action?pageId=3673512">OpenTelemetry架构</a> ,关于语义约定请参考:<a class="external-link" href="https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/api.md" rel="nofollow">https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/api.md</a></p><p><span class="confluence-embedded-file-wrapper image-center-wrapper"><img class="confluence-embedded-image confluence-external-resource image-center" draggable="false" src="https://goframe.org/download/attachments/3673512/8fbc65f937aaac8c9b6947faa89a6964.png?version=1&modificationDate=1611217362937&api=v2" data-image-src="https://goframe.org/download/attachments/3673512/8fbc65f937aaac8c9b6947faa89a6964.png?version=1&modificationDate=1611217362937&api=v2"></span></p><h2 class="heading" id="id-链路跟踪背景知识-TracerProvider">TracerProvider</h2><p>主要负责创建<code>Tracer</code>,一般是需要第三方的分布式链路跟踪管理平台提供具体的实现。默认情况是一个空的<code>TracerProvider (<span>NoopTracerProvider</span>)</code>,虽然也能创建<code>Tracer</code>但是内部其实不会执行具体的数据流传输逻辑。</p><h2 class="heading" id="id-链路跟踪背景知识-Tracer">Tracer</h2><p><code>Tracer</code>表示一次完整的追踪链路,<code>tracer</code>由一个或多个<code>span</code>组成。下图示例表示了一个由<code>8</code>个<code>span</code>组成的<code>tracer</code>:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="syntaxhighlighter-pre" data-syntaxhighlighter-params="brush: xml; gutter: false; theme: Confluence" data-theme="Confluence"> [Span A] ←←←(the root span)
|
+------+------+
| |
[Span B] [Span C] ←←←(Span C is a `ChildOf` Span A)
| |
[Span D] +---+-------+
| |
[Span E] [Span F] >>> [Span G] >>> [Span H]
↑
↑
↑
(Span G `FollowsFrom` Span F)</pre>
</div></div><p>时间轴的展现方式会更容易理解:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="syntaxhighlighter-pre" data-syntaxhighlighter-params="brush: xml; gutter: false; theme: Confluence" data-theme="Confluence">––|–––––––|–––––––|–––––––|–––––––|–––––––|–––––––|–––––––|–> time
[Span A···················································]
[Span B··············································]
[Span D··········································]
[Span C········································]
[Span E·······] [Span F··] [Span G··] [Span H··]</pre>
</div></div><p class="heading">我们通常通过以下方式创建一个<code>Tracer</code>:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="syntaxhighlighter-pre" data-syntaxhighlighter-params="brush: go; gutter: false; theme: Confluence" data-custom-language-resource="com.atlassian.confluence.ext.code.custom.Go.8921870917569589270:custom-code-syntax-resources" data-theme="Confluence">gtrace.NewTracer(tracerName)</pre>
</div></div><h2 class="heading" id="id-链路跟踪背景知识-Span">Span</h2><p><code>Span</code>是一条追踪链路中的基本组成要素,一个<code>span</code>表示一个独立的工作单元,比如可以表示一次函数调用,一次<code>http</code>请求等等。<code>span</code>会记录如下基本要素:</p><ul><li style="list-style-type: disc;">服务名称(<code>operation name</code>)</li><li style="list-style-type: disc;">服务的开始时间和结束时间</li><li style="list-style-type: disc;"><code>K/V</code>形式的<code>Tags</code></li><li style="list-style-type: disc;"><code>K/V</code>形式的<code>Logs</code></li><li style="list-style-type: disc;"><code>SpanContext</code></li></ul><p><code>Span</code>是这么多对象中使用频率最高的,因此创建<code>Span</code>也非常简便,例如:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="syntaxhighlighter-pre" data-syntaxhighlighter-params="brush: go; gutter: false; theme: Confluence" data-custom-language-resource="com.atlassian.confluence.ext.code.custom.Go.8921870917569589270:custom-code-syntax-resources" data-theme="Confluence">gtrace.NewSpan(ctx, spanName, opts...)</pre>
</div></div><h2 class="heading" id="id-链路跟踪背景知识-Attributes">Attributes</h2><p><code>Attributes</code>以<code>K/V</code>键值对的形式保存用户自定义标签,主要用于链路追踪结果的查询过滤。例如:<span> </span> <code>http.method="GET",http.status_code=200</code>。其中<code>key</code>值必须为字符串,<code>value</code>必须是字符串,布尔型或者数值型。<span> </span> <code>span</code>中的<code>Attributes</code>仅自己可见,不会随着<span> </span> <code>SpanContext</code>传递给后续<code>span</code>。 设置<code>Attributes</code>方式例如:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="syntaxhighlighter-pre" data-syntaxhighlighter-params="brush: go; gutter: false; theme: Confluence" data-custom-language-resource="com.atlassian.confluence.ext.code.custom.Go.8921870917569589270:custom-code-syntax-resources" data-theme="Confluence">span.SetAttributes(
label.String("http.remote", conn.RemoteAddr().String()),
label.String("http.local", conn.LocalAddr().String()),
)</pre>
</div></div><h2 class="heading" id="id-链路跟踪背景知识-Events">Events</h2><p><code>Events</code>与<code>Attributes</code>类似,也是<code>K/V</code>键值对形式。与<code>Attributes</code>不同的是,<code>Events</code>还会记录写入<code>Events</code>的时间,因此<code>Events</code>主要用于记录某些事件发生的时间。<code>Events</code>的<code>key</code>值同样必须为字符串,但对<code>value</code>类型则没有限制。例如:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="syntaxhighlighter-pre" data-syntaxhighlighter-params="brush: go; gutter: false; theme: Confluence" data-custom-language-resource="com.atlassian.confluence.ext.code.custom.Go.8921870917569589270:custom-code-syntax-resources" data-theme="Confluence">span.AddEvent("http.request", trace.WithAttributes(
label.Any("http.request.header", headers),
label.Any("http.request.baggage", gtrace.GetBaggageMap(ctx)),
label.String("http.request.body", bodyContent),
))</pre>
</div></div><h2 class="heading" id="id-链路跟踪背景知识-SpanContext">SpanContext</h2><p><code>SpanContext</code>携带着一些用于<strong>跨服务通信的(跨进程)</strong>数据,主要包含:</p><ul><li style="list-style-type: disc;">足够在系统中标识该<code>span</code>的信息,比如:<code>span_id, trace_id</code>。</li><li style="list-style-type: disc;"><code>Baggage</code> - 为整条追踪连保存跨服务(跨进程)的<code>K/V</code>格式的用户自定义数据。<code>Baggage</code> <span>与</span> <code>Attributes</code> <span>类似,也是</span> <code>K/V</code> <span>键值对。与</span> <code>Attributes</code> <span>不同的是:</span></li></ul><ul><li style="list-style-type: none;"><ul><li style="list-style-type: disc;">其<code>key</code>跟<code>value</code>都只能是字符串格式</li><li style="list-style-type: disc;"><code>Baggage</code>不仅当前<code>span</code>可见,其会随着<code>SpanContext</code>传递给后续所有的子<code>span</code>。要小心谨慎的使用<code>Baggage</code> - 因为在所有的<code>span</code>中传递这些<code>K,V</code>会带来不小的网络和<code>CPU</code>开销。</li></ul></li></ul><h2 id="id-链路跟踪背景知识-Propagator">Propagator</h2><p><code>Propagator</code>传播器用于端对端的数据编码/解码,例如:<code>Client</code>到<code>Server</code>端的数据传输,<code>TraceId</code>、<code>SpanId</code>和<code>Baggage</code>也是需要通过传播器来管理数据传输。业务端开发者往往对<code>Propagator</code>无感知,只有中间件/拦截器的开发者需要知道它的作用。<code>OpenTelemetry</code>的标准协议实现库提供了常用的<code>TextMapPropagator</code>,用于常见的文本数据端到端传输。此外,为保证<code>TextMapPropagator</code>中的传输数据兼容性,不应当带有特殊字符,具体请参考:<a class="external-link" href="https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/context/api-propagators.md" rel="nofollow">https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/context/api-propagators.md</a></p><p><code>GoFrame</code>框架通过<code>gtrace</code>模块使用了以下传播器对象,并全局设置到了<code>OpenTelemetry</code>中:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
<pre class="syntaxhighlighter-pre" data-syntaxhighlighter-params="brush: go; gutter: false; theme: Confluence" data-custom-language-resource="com.atlassian.confluence.ext.code.custom.Go.8921870917569589270:custom-code-syntax-resources" data-theme="Confluence">// defaultTextMapPropagator is the default propagator for context propagation between peers.
defaultTextMapPropagator = propagation.NewCompositeTextMapPropagator(
propagation.TraceContext{},
propagation.Baggage{},
)</pre>
</div></div><h1 id="id-链路跟踪背景知识-支持组件">支持组件</h1><div class="confluence-information-macro confluence-information-macro-tip"><span class="aui-icon aui-icon-small aui-iconfont-approve confluence-information-macro-icon"></span><div class="confluence-information-macro-body"><p><code>GoFrame</code>的核心组件都已经全面支持<code>OpenTelemetry</code>标准,并且<strong>自动开启</strong>了链路跟踪特性,开发者无需显示调用、使用无感知。在没有注入外部<code>TracerProvider</code>的情况下,框架会使用默认的<code>TracerProvider</code>,该<code>TracerProvider</code>只会自动创建<code>TraceID</code>及<code>SpanID</code>,以便打通请求日志的链路,并不会执行复杂逻辑。</p></div></div><p>包括但不限于以下核心组件:</p><div class="table-wrap"><table class="relative-table wrapped confluenceTable" style="width: 100.0%;"><colgroup><col style="width: 30.5533%;"/><col style="width: 21.3916%;"/><col style="width: 48.0283%;"/></colgroup><tbody><tr><th class="confluenceTh">自动支持链路跟踪特性的组件</th><th colspan="1" class="confluenceTh">组件名</th><th class="confluenceTh">描述</th></tr><tr><td class="confluenceTd"><code>HTTP Client</code></td><td colspan="1" class="confluenceTd"><code>gclient</code></td><td class="confluenceTd"><code>HTTP</code>客户端自动启用了链路跟踪特性,具体使用示例请参考后续示例章节。</td></tr><tr><td class="confluenceTd"><p><code>Http Server</code></p></td><td colspan="1" class="confluenceTd"><code>ghttp</code></td><td class="confluenceTd"><code>HTTP</code>服务端自动启用了链路跟踪特性,具体使用示例请参考后续示例章节。</td></tr><tr><td class="confluenceTd"><p><code>gRPC Client</code></p></td><td colspan="1" class="confluenceTd"><code>contrib/rpc/grpcx</code></td><td class="confluenceTd"><code>gRPC</code>客户端自动启用了链路跟踪特性,具体使用示例请参考后续示例章节。</td></tr><tr><td colspan="1" class="confluenceTd"><p><code>gRPC Server</code></p></td><td colspan="1" class="confluenceTd"><code>contrib/rpc/grpcx</code></td><td colspan="1" class="confluenceTd"><code>gRPC</code>服务端自动启用了链路跟踪特性,具体使用示例请参考后续示例章节。</td></tr><tr><td colspan="1" class="confluenceTd"><code>Logging</code></td><td colspan="1" class="confluenceTd"><code>glog</code></td><td colspan="1" class="confluenceTd">日志内容中需要注入当前请求的<code>TraceId</code>,以方便通过日志快速查找定位问题点。该特性是由<code>glog</code>组件实现,这需要开发者在输出日志的时候调用<code>Ctx</code>链式操作方法将<code>context.Context</code>上下文变量传递到当前输出日志操作链路中,没有传递<code>context.Context</code>上下文变量,就会丢失日志内容中的<code>TraceId</code>。</td></tr><tr><td colspan="1" class="confluenceTd"><code>ORM</code></td><td colspan="1" class="confluenceTd"><code>gdb</code></td><td colspan="1" class="confluenceTd">数据库的执行是很重要的链路环节,<code>Orm</code>组件需要将自身的执行情况投递到链路中,作为执行链路的一部分。</td></tr><tr><td colspan="1" class="confluenceTd"><code>NoSQL Redis</code></td><td colspan="1" class="confluenceTd"><code>gredis</code></td><td colspan="1" class="confluenceTd"><code>Redis</code>的执行也是很重要的链路环节,<code>Redis</code>需要将自身的执行情况投递到链路中,作为执行链路的一部分。</td></tr><tr><td colspan="1" class="confluenceTd"><code>Utils</code></td><td colspan="1" class="confluenceTd"><code>gtrace</code></td><td colspan="1" class="confluenceTd">对于<code>Tracing</code>特性的管理需要做一定的封装,主要考虑的是可扩展性和易用性两方面。该封装由<code>gtrace</code>模块实现,文档地址:<a class="external-link" href="https://pkg.go.dev/github.com/gogf/gf/v2/net/gtrace" rel="nofollow">https://pkg.go.dev/github.com/gogf/gf/v2/net/gtrace</a></td></tr></tbody></table></div><h1 id="id-链路跟踪背景知识-参考资料">参考资料</h1><ul><li><span class="nolink"> <a class="external-link" href="https://opentracing.io/" rel="nofollow" style="text-decoration: none;">https://opentracing.io</a> </span></li><li><a class="external-link" href="https://opencensus.io/" rel="nofollow" style="text-decoration: none;">https://opencensus.io</a></li><li><a class="external-link" href="https://opentelemetry.io/" rel="nofollow" style="text-decoration: none;">https://opentelemetry.io</a></li><li><a class="external-link" href="https://github.com/open-telemetry/opentelemetry-specification/tree/main/specification" rel="nofollow" style="text-decoration: none;">https://github.com/open-telemetry/opentelemetry-specification/tree/main/specification</a></li></ul><p><br/></p><p><br/></p></div>
</div>
<div class="cell aside" data-type="aside">
<div class="innerCell">
<div class="panel" style="border-width: 1px;"><div class="panelHeader" style="border-bottom-width: 1px;"><b>Content Menu</b></div><div class="panelContent">
<p><style type='text/css'>/*<![CDATA[*/
div.rbtoc1711679220174 {padding: 0px;}
div.rbtoc1711679220174 ul {margin-left: 0px;}
div.rbtoc1711679220174 li {margin-left: 0px;padding-left: 0px;}
/*]]>*/</style><div class='toc-macro rbtoc1711679220174'>
<ul class='toc-indentation'>
<li><a href='#id-链路跟踪背景知识-OpenTelemetry'>OpenTelemetry</a></li>
<li><a href='#id-链路跟踪背景知识-重要概念'>重要概念</a>
<ul class='toc-indentation'>
<li><a href='#id-链路跟踪背景知识-TracerProvider'>TracerProvider</a></li>
<li><a href='#id-链路跟踪背景知识-Tracer'>Tracer</a></li>
<li><a href='#id-链路跟踪背景知识-Span'>Span</a></li>
<li><a href='#id-链路跟踪背景知识-Attributes'>Attributes</a></li>
<li><a href='#id-链路跟踪背景知识-Events'>Events</a></li>
<li><a href='#id-链路跟踪背景知识-SpanContext'>SpanContext</a></li>
<li><a href='#id-链路跟踪背景知识-Propagator'>Propagator</a></li>
</ul>
</li>
<li><a href='#id-链路跟踪背景知识-支持组件'>支持组件</a></li>
<li><a href='#id-链路跟踪背景知识-参考资料'>参考资料</a></li>
</ul>
</div></p>
</div></div></div>
</div>
</div>
</div>
</div>
<div style="padding: 10px 0;">
<a href="https://goframe.org/pages/viewpage.action?pageId=38575612">View Online</a>
·
<a href="https://goframe.org/pages/diffpagesbyversion.action?pageId=38575612&revisedVersion=5&originalVersion=4">View Changes Online</a>
</div>
</div>
郭强
2022-02-09T08:19:20Z
服务监控告警(完善中)
郭强
tag:goframe.org,2009:page-148537354-3
2024-03-22T07:09:32Z
2024-03-22T06:23:16Z
<div class="feed"> <p>
Page
<b>edited</b> by
<a href=" https://goframe.org/display/~john
">郭强</a>
</p>
<div style="border-top: 1px solid #ddd; border-bottom: 1px solid #ddd; padding: 10px;">
<div class="contentLayout2">
<div class="columnLayout two-right-sidebar" data-layout="two-right-sidebar">
<div class="cell normal" data-type="normal">
<div class="innerCell">
<div class="confluence-information-macro confluence-information-macro-note"><span class="aui-icon aui-icon-small aui-iconfont-warning confluence-information-macro-icon"></span><div class="confluence-information-macro-body"><p>监控告警特性从框架<code>v2.7</code>版本开始提供。</p></div></div><h1 id="id-服务监控告警(完善中)-基本介绍">基本介绍</h1><p>开发者通过<code>GoFrame</code>框架可以快速地实现监控指标及指标暴露。</p><h1 id="id-服务监控告警(完善中)-相关文档">相关文档</h1><p><ul class='childpages-macro'><li><a href="https://goframe.org/pages/viewpage.action?pageId=148537358">监控告警-基本介绍</a></li><li><a href="https://goframe.org/pages/viewpage.action?pageId=148537371">监控告警-基本使用</a></li><li><a href="https://goframe.org/pages/viewpage.action?pageId=149880869">监控告警-同步指标</a></li><li><a href="https://goframe.org/pages/viewpage.action?pageId=149880871">监控告警-异步指标</a></li><li><a href="https://goframe.org/pages/viewpage.action?pageId=148537373">监控告警-指标属性</a></li></ul></p><p><br/></p><p><br/></p><p><br/></p><p><br/></p><p><br/></p><p><br/></p><p><br/></p></div>
</div>
<div class="cell aside" data-type="aside">
<div class="innerCell">
<div class="panel" style="border-width: 1px;"><div class="panelHeader" style="border-bottom-width: 1px;"><b>Content Menu</b></div><div class="panelContent">
<p><style type='text/css'>/*<![CDATA[*/
div.rbtoc1711679220204 {padding: 0px;}
div.rbtoc1711679220204 ul {margin-left: 0px;}
div.rbtoc1711679220204 li {margin-left: 0px;padding-left: 0px;}
/*]]>*/</style><div class='toc-macro rbtoc1711679220204'>
<ul class='toc-indentation'>
<li><a href='#id-服务监控告警(完善中)-基本介绍'>基本介绍</a></li>
<li><a href='#id-服务监控告警(完善中)-相关文档'>相关文档</a></li>
</ul>
</div></p>
</div></div></div>
</div>
</div>
</div>
</div>
<div style="padding: 10px 0;">
<a href="https://goframe.org/pages/viewpage.action?pageId=148537354">View Online</a>
·
<a href="https://goframe.org/pages/diffpagesbyversion.action?pageId=148537354&revisedVersion=3&originalVersion=2">View Changes Online</a>
</div>
</div>
郭强
2024-03-22T06:23:16Z
服务可观测性
郭强
tag:goframe.org,2009:page-148537351-2
2024-03-22T06:25:29Z
2024-03-22T06:17:37Z
<div class="feed"> <p>
Page
<b>edited</b> by
<a href=" https://goframe.org/display/~john
">郭强</a>
</p>
<div style="border-top: 1px solid #ddd; border-bottom: 1px solid #ddd; padding: 10px;">
<div class="contentLayout2">
<div class="columnLayout two-right-sidebar" data-layout="two-right-sidebar">
<div class="cell normal" data-type="normal">
<div class="innerCell">
<h1 id="id-服务可观测性-基本介绍">基本介绍</h1><p>作为一款工程完备的开发框架,开发者通过<code>GoFrame</code>可以非常简便地实现服务的可观测特性。</p><h1 id="id-服务可观测性-相关文档">相关文档</h1><p><ul class='childpages-macro'><li><a href="https://goframe.org/pages/viewpage.action?pageId=3673684">服务链路跟踪</a><ul class='childpages-macro'><li><a href="https://goframe.org/pages/viewpage.action?pageId=38575612">链路跟踪-背景知识</a></li><li><a href="https://goframe.org/pages/viewpage.action?pageId=38575567">链路跟踪-准备工作</a></li><li><a href="https://goframe.org/pages/viewpage.action?pageId=3673727">链路跟踪-基本示例</a></li><li><a href="https://goframe.org/pages/viewpage.action?pageId=3673713">链路跟踪-HTTP示例</a></li><li><a href="https://goframe.org/pages/viewpage.action?pageId=3673718">链路跟踪-GRPC示例</a></li><li><a href="https://goframe.org/pages/viewpage.action?pageId=49745254">链路跟踪-最佳实践</a></li></ul></li><li><a href="https://goframe.org/pages/viewpage.action?pageId=148537354">服务监控告警(完善中)</a><ul class='childpages-macro'><li><a href="https://goframe.org/pages/viewpage.action?pageId=148537358">监控告警-基本介绍</a></li><li><a href="https://goframe.org/pages/viewpage.action?pageId=148537371">监控告警-基本使用</a></li><li><a href="https://goframe.org/pages/viewpage.action?pageId=149880869">监控告警-同步指标</a></li><li><a href="https://goframe.org/pages/viewpage.action?pageId=149880871">监控告警-异步指标</a></li><li><a href="https://goframe.org/pages/viewpage.action?pageId=148537373">监控告警-指标属性</a></li></ul></li></ul></p><p><br/></p><p><br/></p></div>
</div>
<div class="cell aside" data-type="aside">
<div class="innerCell">
<div class="panel" style="border-width: 1px;"><div class="panelHeader" style="border-bottom-width: 1px;"><b>Content Menu</b></div><div class="panelContent">
<p><style type='text/css'>/*<![CDATA[*/
div.rbtoc1711679220264 {padding: 0px;}
div.rbtoc1711679220264 ul {margin-left: 0px;}
div.rbtoc1711679220264 li {margin-left: 0px;padding-left: 0px;}
/*]]>*/</style><div class='toc-macro rbtoc1711679220264'>
<ul class='toc-indentation'>
<li><a href='#id-服务可观测性-基本介绍'>基本介绍</a></li>
<li><a href='#id-服务可观测性-相关文档'>相关文档</a></li>
</ul>
</div></p>
</div></div></div>
</div>
</div>
</div>
</div>
<div style="padding: 10px 0;">
<a href="https://goframe.org/pages/viewpage.action?pageId=148537351">View Online</a>
·
<a href="https://goframe.org/pages/diffpagesbyversion.action?pageId=148537351&revisedVersion=2&originalVersion=1">View Changes Online</a>
</div>
</div>
郭强
2024-03-22T06:17:37Z
服务链路跟踪
郭强
tag:goframe.org,2009:page-3673684-57
2024-03-22T06:22:28Z
2021-01-28T10:44:21Z
<div class="feed"> <p>
Page
<b>edited</b> by
<a href=" https://goframe.org/display/~john
">郭强</a>
</p>
<div style="border-top: 1px solid #ddd; border-bottom: 1px solid #ddd; padding: 10px;">
<div class="contentLayout2">
<div class="columnLayout two-right-sidebar" data-layout="two-right-sidebar">
<div class="cell normal" data-type="normal">
<div class="innerCell">
<h1 id="id-服务链路跟踪-基本介绍">基本介绍</h1><p><code>GoFrame</code>实现了标准化的分布式链路跟踪<span style="color: rgb(23,43,77);">(</span> <code>Distributed Tracing</code> <span style="color: rgb(23,43,77);">)</span>特性。</p><h1 id="id-服务链路跟踪-相关文档">相关文档</h1><p><ul class='childpages-macro'><li><a href="https://goframe.org/pages/viewpage.action?pageId=38575612">链路跟踪-背景知识</a></li><li><a href="https://goframe.org/pages/viewpage.action?pageId=38575567">链路跟踪-准备工作</a></li><li><a href="https://goframe.org/pages/viewpage.action?pageId=3673727">链路跟踪-基本示例</a></li><li><a href="https://goframe.org/pages/viewpage.action?pageId=3673713">链路跟踪-HTTP示例</a><ul class='childpages-macro'><li><a href="https://goframe.org/pages/viewpage.action?pageId=38575579">链路跟踪-HTTP示例-Baggage</a></li><li><a href="https://goframe.org/pages/viewpage.action?pageId=38575588">链路跟踪-HTTP示例-数据操作</a></li></ul></li><li><a href="https://goframe.org/pages/viewpage.action?pageId=3673718">链路跟踪-GRPC示例</a></li><li><a href="https://goframe.org/pages/viewpage.action?pageId=49745254">链路跟踪-最佳实践</a><ul class='childpages-macro'><li><a href="https://goframe.org/pages/viewpage.action?pageId=49745257">链路跟踪-TraceID注入和获取</a></li></ul></li></ul></p><p><br/></p></div>
</div>
<div class="cell aside" data-type="aside">
<div class="innerCell">
<div class="panel" style="border-width: 1px;"><div class="panelHeader" style="border-bottom-width: 1px;"><b>Content Menu</b></div><div class="panelContent">
<p><style type='text/css'>/*<![CDATA[*/
div.rbtoc1711679220305 {padding: 0px;}
div.rbtoc1711679220305 ul {margin-left: 0px;}
div.rbtoc1711679220305 li {margin-left: 0px;padding-left: 0px;}
/*]]>*/</style><div class='toc-macro rbtoc1711679220305'>
<ul class='toc-indentation'>
<li><a href='#id-服务链路跟踪-基本介绍'>基本介绍</a></li>
<li><a href='#id-服务链路跟踪-相关文档'>相关文档</a></li>
</ul>
</div></p>
</div></div></div>
</div>
</div>
</div>
</div>
<div style="padding: 10px 0;">
<a href="https://goframe.org/pages/viewpage.action?pageId=3673684">View Online</a>
·
<a href="https://goframe.org/pages/diffpagesbyversion.action?pageId=3673684&revisedVersion=57&originalVersion=56">View Changes Online</a>
</div>
</div>
郭强
2021-01-28T10:44:21Z