安徽网站建设,城乡村建设规划许可证网站,成功的网络营销案例有哪些,江油网站制作eBPF 的发展如火如荼#xff0c;在可观测性领域大放异彩#xff0c;Grafana 近期也发布了一款 eBPF 采集器#xff0c;可以采集服务的 RED 指标#xff0c;本文做一个尝鲜介绍#xff0c;让读者有个大概了解。 eBPF 基础介绍可以参考我之前的文章《eBPF Hello world》。理… eBPF 的发展如火如荼在可观测性领域大放异彩Grafana 近期也发布了一款 eBPF 采集器可以采集服务的 RED 指标本文做一个尝鲜介绍让读者有个大概了解。 eBPF 基础介绍可以参考我之前的文章《eBPF Hello world》。理论上eBPF 可以拿到服务收到的请求信息比如QPS、延迟、成功率等这些数据对于应用级监控至关重要Grafana Beyla 就是为此而生的。
要测试使用 Beyla 采集服务的 REDRate-Errors-Duration 指标那首先得有个服务这里我用的是 answer https://answer.flashcat.cloud 论坛你也可以自己搞一个简单的 http 服务比如
package mainimport (net/httpstrconvtime
)func handleRequest(rw http.ResponseWriter, req *http.Request) {status : 200for k, v : range req.URL.Query() {if len(v) 0 {continue}switch k {case status:if s, err : strconv.Atoi(v[0]); err nil {status s}case delay:if d, err : time.ParseDuration(v[0]); err nil {time.Sleep(d)}}}rw.WriteHeader(status)
}func main() {http.ListenAndServe(:8080,http.HandlerFunc(handleRequest))
}上面这个代码保存成 server.go然后用 go run server.go 即可运行当然前提是你机器上有 go 开发环境。这个小服务可以接收两个参数一个是 status用来指定返回的 http 状态码另一个是 delay用来指定延迟多久返回比如
curl -v http://localhost:8080/foo?status404上面的命令会返回 404 状态码如果想延迟 1 秒返回可以这样
curl -v http://localhost:8080/foo?delay1s接下来我们就可以使用 Beyla 采集这个服务的 RED 指标了。
下载 Beyla
我的机器上有 go 开发环境所以我直接使用 go install 安装了你也可以去 Beyla 的 release 页面下载二进制包然后解压缩使用。
go install github.com/grafana/beyla/cmd/beylalatest运行 Beyla
使用下面的命令运行 Beyla
$ BEYLA_PROMETHEUS_PORT8999 PRINT_TRACEStrue OPEN_PORT8080 sudo -E beyla或者直接使用 root 账号运行比如我是这么跑的
$ BEYLA_PROMETHEUS_PORT8999 PRINT_TRACEStrue OPEN_PORT8080 beyla解释一下这几个参数
BEYLA_PROMETHEUS_PORT: Beyla 要监听的端口通过这个端口暴露 metrics 指标数据PRINT_TRACES: 是否打印 trace 日志OPEN_PORT: Beyla 采集的目标服务监听的端口这里是 8080上面给出的那段 go server 的代码就是监听在 8080我的机器上 answer 论坛程序也是监听在 8080你要监控的程序如果不是监听在 8080可以在换成你自己的端口
查看指标
运行之后可以通过 curl 查看指标
curl http://localhost:8999/metrics返回的内容如下
# HELP http_client_duration_seconds duration of HTTP service calls from the client side, in seconds
# TYPE http_client_duration_seconds histogram
http_client_duration_seconds_bucket{http_methodGET,http_status_code200,service_nameanswer,le0} 0
http_client_duration_seconds_bucket{http_methodGET,http_status_code200,service_nameanswer,le0.005} 0
http_client_duration_seconds_bucket{http_methodGET,http_status_code200,service_nameanswer,le0.01} 0
http_client_duration_seconds_bucket{http_methodGET,http_status_code200,service_nameanswer,le0.025} 0
http_client_duration_seconds_bucket{http_methodGET,http_status_code200,service_nameanswer,le0.05} 0
http_client_duration_seconds_bucket{http_methodGET,http_status_code200,service_nameanswer,le0.075} 0
http_client_duration_seconds_bucket{http_methodGET,http_status_code200,service_nameanswer,le0.1} 0
http_client_duration_seconds_bucket{http_methodGET,http_status_code200,service_nameanswer,le0.25} 0
http_client_duration_seconds_bucket{http_methodGET,http_status_code200,service_nameanswer,le0.5} 0
http_client_duration_seconds_bucket{http_methodGET,http_status_code200,service_nameanswer,le0.75} 0
http_client_duration_seconds_bucket{http_methodGET,http_status_code200,service_nameanswer,le1} 0
http_client_duration_seconds_bucket{http_methodGET,http_status_code200,service_nameanswer,le2.5} 1
http_client_duration_seconds_bucket{http_methodGET,http_status_code200,service_nameanswer,le5} 1
http_client_duration_seconds_bucket{http_methodGET,http_status_code200,service_nameanswer,le7.5} 1
http_client_duration_seconds_bucket{http_methodGET,http_status_code200,service_nameanswer,le10} 1
http_client_duration_seconds_bucket{http_methodGET,http_status_code200,service_nameanswer,leInf} 1
http_client_duration_seconds_sum{http_methodGET,http_status_code200,service_nameanswer} 1.668771575
http_client_duration_seconds_count{http_methodGET,http_status_code200,service_nameanswer} 1
# HELP http_client_request_size_bytes size, in bytes, of the HTTP request body as sent from the client side
# TYPE http_client_request_size_bytes histogram
http_client_request_size_bytes_bucket{http_methodGET,http_status_code200,service_nameanswer,le0} 1
http_client_request_size_bytes_bucket{http_methodGET,http_status_code200,service_nameanswer,le32} 1
http_client_request_size_bytes_bucket{http_methodGET,http_status_code200,service_nameanswer,le64} 1
http_client_request_size_bytes_bucket{http_methodGET,http_status_code200,service_nameanswer,le128} 1
http_client_request_size_bytes_bucket{http_methodGET,http_status_code200,service_nameanswer,le256} 1
http_client_request_size_bytes_bucket{http_methodGET,http_status_code200,service_nameanswer,le512} 1
http_client_request_size_bytes_bucket{http_methodGET,http_status_code200,service_nameanswer,le1024} 1
http_client_request_size_bytes_bucket{http_methodGET,http_status_code200,service_nameanswer,le2048} 1
http_client_request_size_bytes_bucket{http_methodGET,http_status_code200,service_nameanswer,le4096} 1
http_client_request_size_bytes_bucket{http_methodGET,http_status_code200,service_nameanswer,le8192} 1
http_client_request_size_bytes_bucket{http_methodGET,http_status_code200,service_nameanswer,leInf} 1
http_client_request_size_bytes_sum{http_methodGET,http_status_code200,service_nameanswer} 0
http_client_request_size_bytes_count{http_methodGET,http_status_code200,service_nameanswer} 1
# HELP http_server_duration_seconds duration of HTTP service calls from the server side, in seconds
# TYPE http_server_duration_seconds histogram
http_server_duration_seconds_bucket{http_methodGET,http_status_code200,service_nameanswer,le0} 0
http_server_duration_seconds_bucket{http_methodGET,http_status_code200,service_nameanswer,le0.005} 201
http_server_duration_seconds_bucket{http_methodGET,http_status_code200,service_nameanswer,le0.01} 789
http_server_duration_seconds_bucket{http_methodGET,http_status_code200,service_nameanswer,le0.025} 799
http_server_duration_seconds_bucket{http_methodGET,http_status_code200,service_nameanswer,le0.05} 799
http_server_duration_seconds_bucket{http_methodGET,http_status_code200,service_nameanswer,le0.075} 799
http_server_duration_seconds_bucket{http_methodGET,http_status_code200,service_nameanswer,le0.1} 799
http_server_duration_seconds_bucket{http_methodGET,http_status_code200,service_nameanswer,le0.25} 799
http_server_duration_seconds_bucket{http_methodGET,http_status_code200,service_nameanswer,le0.5} 799
http_server_duration_seconds_bucket{http_methodGET,http_status_code200,service_nameanswer,le0.75} 799
http_server_duration_seconds_bucket{http_methodGET,http_status_code200,service_nameanswer,le1} 799
http_server_duration_seconds_bucket{http_methodGET,http_status_code200,service_nameanswer,le2.5} 800
http_server_duration_seconds_bucket{http_methodGET,http_status_code200,service_nameanswer,le5} 800
http_server_duration_seconds_bucket{http_methodGET,http_status_code200,service_nameanswer,le7.5} 800
http_server_duration_seconds_bucket{http_methodGET,http_status_code200,service_nameanswer,le10} 800
http_server_duration_seconds_bucket{http_methodGET,http_status_code200,service_nameanswer,leInf} 800
http_server_duration_seconds_sum{http_methodGET,http_status_code200,service_nameanswer} 5.752096697000003
http_server_duration_seconds_count{http_methodGET,http_status_code200,service_nameanswer} 800
http_server_duration_seconds_bucket{http_methodGET,http_status_code302,service_nameanswer,le0} 0
http_server_duration_seconds_bucket{http_methodGET,http_status_code302,service_nameanswer,le0.005} 1
http_server_duration_seconds_bucket{http_methodGET,http_status_code302,service_nameanswer,le0.01} 1
http_server_duration_seconds_bucket{http_methodGET,http_status_code302,service_nameanswer,le0.025} 1
http_server_duration_seconds_bucket{http_methodGET,http_status_code302,service_nameanswer,le0.05} 1
http_server_duration_seconds_bucket{http_methodGET,http_status_code302,service_nameanswer,le0.075} 1
http_server_duration_seconds_bucket{http_methodGET,http_status_code302,service_nameanswer,le0.1} 1
http_server_duration_seconds_bucket{http_methodGET,http_status_code302,service_nameanswer,le0.25} 1
http_server_duration_seconds_bucket{http_methodGET,http_status_code302,service_nameanswer,le0.5} 1
http_server_duration_seconds_bucket{http_methodGET,http_status_code302,service_nameanswer,le0.75} 1
http_server_duration_seconds_bucket{http_methodGET,http_status_code302,service_nameanswer,le1} 1
http_server_duration_seconds_bucket{http_methodGET,http_status_code302,service_nameanswer,le2.5} 1
http_server_duration_seconds_bucket{http_methodGET,http_status_code302,service_nameanswer,le5} 1
http_server_duration_seconds_bucket{http_methodGET,http_status_code302,service_nameanswer,le7.5} 1
http_server_duration_seconds_bucket{http_methodGET,http_status_code302,service_nameanswer,le10} 1
http_server_duration_seconds_bucket{http_methodGET,http_status_code302,service_nameanswer,leInf} 1
http_server_duration_seconds_sum{http_methodGET,http_status_code302,service_nameanswer} 0.001523002
http_server_duration_seconds_count{http_methodGET,http_status_code302,service_nameanswer} 1
# HELP http_server_request_size_bytes size, in bytes, of the HTTP request body as received at the server side
# TYPE http_server_request_size_bytes histogram
http_server_request_size_bytes_bucket{http_methodGET,http_status_code200,service_nameanswer,le0} 800
http_server_request_size_bytes_bucket{http_methodGET,http_status_code200,service_nameanswer,le32} 800
http_server_request_size_bytes_bucket{http_methodGET,http_status_code200,service_nameanswer,le64} 800
http_server_request_size_bytes_bucket{http_methodGET,http_status_code200,service_nameanswer,le128} 800
http_server_request_size_bytes_bucket{http_methodGET,http_status_code200,service_nameanswer,le256} 800
http_server_request_size_bytes_bucket{http_methodGET,http_status_code200,service_nameanswer,le512} 800
http_server_request_size_bytes_bucket{http_methodGET,http_status_code200,service_nameanswer,le1024} 800
http_server_request_size_bytes_bucket{http_methodGET,http_status_code200,service_nameanswer,le2048} 800
http_server_request_size_bytes_bucket{http_methodGET,http_status_code200,service_nameanswer,le4096} 800
http_server_request_size_bytes_bucket{http_methodGET,http_status_code200,service_nameanswer,le8192} 800
http_server_request_size_bytes_bucket{http_methodGET,http_status_code200,service_nameanswer,leInf} 800
http_server_request_size_bytes_sum{http_methodGET,http_status_code200,service_nameanswer} 0
http_server_request_size_bytes_count{http_methodGET,http_status_code200,service_nameanswer} 800
http_server_request_size_bytes_bucket{http_methodGET,http_status_code302,service_nameanswer,le0} 1
http_server_request_size_bytes_bucket{http_methodGET,http_status_code302,service_nameanswer,le32} 1
http_server_request_size_bytes_bucket{http_methodGET,http_status_code302,service_nameanswer,le64} 1
http_server_request_size_bytes_bucket{http_methodGET,http_status_code302,service_nameanswer,le128} 1
http_server_request_size_bytes_bucket{http_methodGET,http_status_code302,service_nameanswer,le256} 1
http_server_request_size_bytes_bucket{http_methodGET,http_status_code302,service_nameanswer,le512} 1
http_server_request_size_bytes_bucket{http_methodGET,http_status_code302,service_nameanswer,le1024} 1
http_server_request_size_bytes_bucket{http_methodGET,http_status_code302,service_nameanswer,le2048} 1
http_server_request_size_bytes_bucket{http_methodGET,http_status_code302,service_nameanswer,le4096} 1
http_server_request_size_bytes_bucket{http_methodGET,http_status_code302,service_nameanswer,le8192} 1
http_server_request_size_bytes_bucket{http_methodGET,http_status_code302,service_nameanswer,leInf} 1
http_server_request_size_bytes_sum{http_methodGET,http_status_code302,service_nameanswer} 0
http_server_request_size_bytes_count{http_methodGET,http_status_code302,service_nameanswer} 1
# HELP promhttp_metric_handler_errors_total Total number of internal errors encountered by the promhttp metric handler.
# TYPE promhttp_metric_handler_errors_total counter
promhttp_metric_handler_errors_total{causeencoding} 0
promhttp_metric_handler_errors_total{causegathering} 0这些指标就可以用采集器来抓了比如 vmagent、categraf、prometheus 等完事之后入库使用 Grafana 展示分析即可经常关注本公众号的读者对于这些知识应该比较熟悉了这里不再赘述。Beyla 默认提供了一个 Grafana Dashboard可以导入测试https://github.com/grafana/beyla/tree/main/grafana。
结语
Beyla 目前还不太稳定还有很多功能没有完成。不过可以尝鲜研究了。可观测性整套技术栈搞起来还挺费劲的如果您想建设这套技术栈欢迎来和我们聊聊我们提供这方面的咨询和商业产品详情了解
快猫星云 Flashcat | 为了无法度量的价值 | 开源监控 | 夜莺监控 | 可观测平台 | 运维监控 | IT监控快猫星云(官网)支持云原生监控、混合云监控、多云统一监控解决云原生架构、混合云架构下统一监控难、故障定位慢的问题https://flashcat.cloud/