-
Notifications
You must be signed in to change notification settings - Fork 431
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b073398
commit ecbd01a
Showing
3 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package controller | ||
|
||
import ( | ||
"sync" | ||
|
||
kubeovnv1 "github.com/alauda/kube-ovn/pkg/apis/kubeovn/v1" | ||
|
||
"k8s.io/apimachinery/pkg/labels" | ||
"k8s.io/klog" | ||
) | ||
|
||
var registerMetricsOnce sync.Once | ||
|
||
// registerSubnetMetrics register subnet metrics | ||
func (c *Controller) registerSubnetMetrics() { | ||
registerMetricsOnce.Do(func() { | ||
registerMetrics() | ||
}) | ||
} | ||
|
||
// resyncSubnetMetrics start to update subnet metrics | ||
func (c *Controller) resyncSubnetMetrics() { | ||
for c.exportSubnetMetrics() { | ||
} | ||
} | ||
|
||
func (c *Controller) exportSubnetMetrics() bool { | ||
subnets, err := c.subnetsLister.List(labels.Everything()) | ||
if err != nil { | ||
klog.Errorf("failed to list subnet, %v", err) | ||
return false | ||
} | ||
for _, subnet := range subnets { | ||
c.exportSubnetAvailableIPsGauge(subnet) | ||
c.exportSubnetUsedIPsGauge(subnet) | ||
} | ||
|
||
return true | ||
} | ||
|
||
func (c *Controller) exportSubnetAvailableIPsGauge(subnet *kubeovnv1.Subnet) { | ||
metricSubnetAvailableIPs.WithLabelValues(subnet.Name, subnet.Spec.Protocol, subnet.Spec.CIDRBlock).Set(subnet.Status.AvailableIPs) | ||
} | ||
|
||
func (c *Controller) exportSubnetUsedIPsGauge(subnet *kubeovnv1.Subnet) { | ||
metricSubnetUsedIPs.WithLabelValues(subnet.Name, subnet.Spec.Protocol, subnet.Spec.CIDRBlock).Set(subnet.Status.UsingIPs) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package controller | ||
|
||
import "github.com/prometheus/client_golang/prometheus" | ||
|
||
var ( | ||
metricSubnetAvailableIPs = prometheus.NewGaugeVec( | ||
prometheus.GaugeOpts{ | ||
Name: "subnet_available_ip_count", | ||
Help: "The available num of ip address in subnet.", | ||
}, | ||
[]string{ | ||
"subnet_name", | ||
"protocol", | ||
"subnet_cidr", | ||
}) | ||
|
||
metricSubnetUsedIPs = prometheus.NewGaugeVec( | ||
prometheus.GaugeOpts{ | ||
Name: "subnet_used_ip_count", | ||
Help: "The used num of ip address in subnet.", | ||
}, | ||
[]string{ | ||
"subnet_name", | ||
"protocol", | ||
"subnet_cidr", | ||
}) | ||
) | ||
|
||
func registerMetrics() { | ||
prometheus.MustRegister(metricSubnetAvailableIPs) | ||
prometheus.MustRegister(metricSubnetUsedIPs) | ||
} |