diff --git a/README.md b/README.md index acea378..4bd4f13 100644 --- a/README.md +++ b/README.md @@ -91,7 +91,8 @@ Note: `ZONE_` configuration is not supported as flag. # HELP cloudflare_zone_threats_country Threats per zone per country # HELP cloudflare_zone_threats_total Threats per zone # HELP cloudflare_zone_uniques_total Uniques per zone -# HELP cloudflare_zone_pool_health_status Reports the health of a pool, 1 for healthy, 0 for unhealthy. +# HELP cloudflare_zone_pool_health_status Reports the health of a pool, 1 for healthy, 0 for unhealthy +# HELP cloudflare_zone_pool_requests_total Requests per pool ``` ## Helm chart repository diff --git a/cloudflare.go b/cloudflare.go index 79df6bc..abd5aa6 100644 --- a/cloudflare.go +++ b/cloudflare.go @@ -183,15 +183,41 @@ type lbResp struct { LoadBalancingRequestsAdaptiveGroups []struct { Count uint64 `json:"count"` Dimensions struct { - ColoCode string `json:"coloCode"` - LbName string `json:"lbName"` - Region string `json:"region"` - SelectedOriginName string `json:"selectedOriginName"` - SelectedPoolHealthy int `json:"selectedPoolHealthy"` - SelectedPoolName string `json:"selectedPoolName"` - SteeringPolicy string `json:"steeringPolicy"` + LbName string `json:"lbName"` + Proxied uint8 `json:"proxied"` + Region string `json:"region"` + SelectedOriginName string `json:"selectedOriginName"` + SelectedPoolAvgRttMs uint64 `json:"selectedPoolAvgRttMs"` + SelectedPoolHealthy uint8 `json:"selectedPoolHealthy"` + SelectedPoolName string `json:"selectedPoolName"` + SteeringPolicy string `json:"steeringPolicy"` } `json:"dimensions"` } `json:"loadBalancingRequestsAdaptiveGroups"` + + LoadBalancingRequestsAdaptive []struct { + LbName string `json:"lbName"` + Proxied uint8 `json:"proxied"` + Region string `json:"region"` + SelectedPoolHealthy uint8 `json:"selectedPoolHealthy"` + SelectedPoolID string `json:"selectedPoolID"` + SelectedPoolName string `json:"selectedPoolName"` + SessionAffinityStatus string `json:"sessionAffinityStatus"` + SteeringPolicy string `json:"steeringPolicy"` + SelectedPoolAvgRttMs uint64 `json:"selectedPoolAvgRttMs"` + Pools []struct { + AvgRttMs uint64 `json:"avgRttMs"` + Healthy uint8 `json:"healthy"` + ID string `json:"id"` + PoolName string `json:"poolName"` + } `json:"pools"` + Origins []struct { + OriginName string `json:"originName"` + Health uint8 `json:"health"` + IPv4 string `json:"ipv4"` + Selected uint8 `json:"selected"` + } `json:"origins"` + } `json:"loadBalancingRequestsAdaptive"` + ZoneTag string `json:"zoneTag"` } @@ -493,15 +519,41 @@ func fetchLoadBalancerTotals(zoneIDs []string) (*cloudflareResponseLb, error) { limit: $limit) { count dimensions { - coloCode region lbName selectedPoolName + proxied selectedOriginName + selectedPoolAvgRttMs selectedPoolHealthy steeringPolicy } } + loadBalancingRequestsAdaptive( + filter: { datetime_geq: $mintime, datetime_lt: $maxtime}, + limit: $limit) { + lbName + proxied + region + selectedPoolHealthy + selectedPoolId + selectedPoolName + sessionAffinityStatus + steeringPolicy + selectedPoolAvgRttMs + pools { + id + poolName + healthy + avgRttMs + } + origins { + originName + health + ipv4 + selected + } + } } } } diff --git a/prometheus.go b/prometheus.go index 93eeb01..02a2bf3 100644 --- a/prometheus.go +++ b/prometheus.go @@ -174,12 +174,18 @@ var ( }, []string{"script_name", "quantile"}, ) - poolHealthStatus = promauto.NewGaugeVec( - prometheus.GaugeOpts{ - Name: "cloudflare_zone_pool_health_status", - Help: "Reports the health of a pool, 1 for healthy, 0 for unhealthy.", - }, - []string{"zone", "colo_code", "load_balancer_name", "origin_name", "steering_policy", "pool_name", "region"}, + poolHealthStatus = promauto.NewGaugeVec(prometheus.GaugeOpts{ + Name: "cloudflare_zone_pool_health_status", + Help: "Reports the health of a pool, 1 for healthy, 0 for unhealthy.", + }, + []string{"zone", "load_balancer_name", "pool_name"}, + ) + + poolRequestsTotal = promauto.NewCounterVec(prometheus.CounterOpts{ + Name: "cloudflare_zone_pool_requests_total", + Help: "Requests per pool", + }, + []string{"zone", "load_balancer_name", "pool_name", "origin_name"}, ) ) @@ -384,6 +390,7 @@ func fetchLoadBalancerAnalytics(zones []cloudflare.Zone, wg *sync.WaitGroup) { } for _, lb := range l.Viewer.Zones { name := findZoneName(zones, lb.ZoneTag) + addLoadBalancingRequestsAdaptive(&lb, name) addLoadBalancingRequestsAdaptiveGroups(&lb, name) } } @@ -391,16 +398,27 @@ func fetchLoadBalancerAnalytics(zones []cloudflare.Zone, wg *sync.WaitGroup) { func addLoadBalancingRequestsAdaptiveGroups(z *lbResp, name string) { for _, g := range z.LoadBalancingRequestsAdaptiveGroups { - poolHealthStatus.With( + poolRequestsTotal.With( prometheus.Labels{ "zone": name, - "colo_code": g.Dimensions.ColoCode, "load_balancer_name": g.Dimensions.LbName, - "origin_name": g.Dimensions.SelectedOriginName, - "steering_policy": g.Dimensions.SteeringPolicy, "pool_name": g.Dimensions.SelectedPoolName, - "region": g.Dimensions.Region, - }).Set(float64(g.Dimensions.SelectedPoolHealthy)) + "origin_name": g.Dimensions.SelectedOriginName, + }).Add(float64(g.Count)) + } +} + +func addLoadBalancingRequestsAdaptive(z *lbResp, name string) { + + for _, g := range z.LoadBalancingRequestsAdaptive { + for _, p := range g.Pools { + poolHealthStatus.With( + prometheus.Labels{ + "zone": name, + "load_balancer_name": g.LbName, + "pool_name": p.PoolName, + }).Set(float64(p.Healthy)) + } } }