【Prometheus】深入解析 【Blackbox_Exporter】的 gRPC 探针函数:`ProbeGRP

我们将逐步解析一个处理 gRPC 探测的 Go 语言函数 ProbeGRPC。该函数主要用于探测和监控 gRPC 服务的可用性和性能,并将相关指标推送到 Prometheus 进行实时监控。下面,我们将按照代码块逐步解释函数的实现和作用。

1. 函数签名与变量声明

func ProbeGRPC(ctx context.Context, target string, module config.Module, registry *prometheus.Registry, logger *slog.Logger) (success bool) {
   
    var (
        durationGaugeVec = prometheus.NewGaugeVec(prometheus.GaugeOpts{
   
            Name: "probe_grpc_duration_seconds",
            Help: "Duration of gRPC request by phase",
        }, []string{
   "phase"})

        isSSLGauge = prometheus.NewGauge(prometheus.GaugeOpts{
   
            Name: "probe_grpc_ssl",
            Help: "Indicates if SSL was used for the connection",
        })

        statusCodeGauge = prometheus.NewGauge(prometheus.GaugeOpts{
   
            Name: "probe_grpc_status_code",
            Help: "Response gRPC status code",
        })

        healthCheckResponseGaugeVec = prometheus.NewGaugeVec(prometheus.GaugeOpts{
   
            Name: "probe_grpc_healthcheck_response",
            Help: "Response HealthCheck response",
        }, []string{
   "serving_status"})

        probeSSLEarliestCertExpiryGauge = prometheus.NewGauge(sslEarliestCertExpiryGaugeOpts)

        probeTLSVersion = prometheus.NewGaugeVec(
            probeTLSInfoGaugeOpts,
            []string{
   "version"},
        )

        probeSSLLastInformation = prometheus.NewGaugeVec(
            prometheus.GaugeOpts{
   
                Name: "probe_ssl_last_chain_info",
                Help: "Contains SSL leaf certificate information",
            },
            []string{
   "fingerprint_sha256"
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值