Skip to content

Commit

Permalink
add reset for kube-ovn-monitor metrics (#1403)
Browse files Browse the repository at this point in the history
  • Loading branch information
hongzhen-ma committed Mar 25, 2022
1 parent eda71b3 commit ffdd196
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
9 changes: 9 additions & 0 deletions pkg/ovnmonitor/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,13 +170,15 @@ func GetExporterName() string {
}

func (e *Exporter) exportOvnStatusGauge() {
metricOvnHealthyStatus.Reset()
result := e.getOvnStatus()
for k, v := range result {
metricOvnHealthyStatus.WithLabelValues(e.Client.System.Hostname, k).Set(float64(v))
}
}

func (e *Exporter) exportOvnLogFileSizeGauge() {
metricLogFileSize.Reset()
components := []string{
"ovsdb-server-southbound",
"ovsdb-server-northbound",
Expand All @@ -194,6 +196,7 @@ func (e *Exporter) exportOvnLogFileSizeGauge() {
}

func (e *Exporter) exportOvnDBFileSizeGauge() {
metricDBFileSize.Reset()
nbPath := e.Client.Database.Northbound.File.Data.Path
sbPath := e.Client.Database.Southbound.File.Data.Path
dirDbMap := map[string]string{
Expand All @@ -215,6 +218,7 @@ func (e *Exporter) exportOvnRequestErrorGauge() {
}

func (e *Exporter) exportOvnChassisGauge() {
metricChassisInfo.Reset()
if vteps, err := e.Client.GetChassis(); err != nil {
klog.Errorf("%s: %v", e.Client.Database.Southbound.Name, err)
e.IncrementErrorCounter()
Expand All @@ -226,14 +230,17 @@ func (e *Exporter) exportOvnChassisGauge() {
}

func (e *Exporter) exportLogicalSwitchGauge() {
resetLogicalSwitchMetrics()
e.setLogicalSwitchInfoMetric()
}

func (e *Exporter) exportLogicalSwitchPortGauge() {
resetLogicalSwitchPortMetrics()
e.setLogicalSwitchPortInfoMetric()
}

func (e *Exporter) exportOvnClusterEnableGauge() {
metricClusterEnabled.Reset()
isClusterEnabled, err := getClusterEnableState(e.Client.Database.Northbound.File.Data.Path)
if err != nil {
klog.Errorf("failed to get output of cluster status: %v", err)
Expand All @@ -246,6 +253,7 @@ func (e *Exporter) exportOvnClusterEnableGauge() {
}

func (e *Exporter) exportOvnClusterInfoGauge() {
resetOvnClusterMetrics()
dirDbMap := map[string]string{
"nb": "OVN_Northbound",
"sb": "OVN_Southbound",
Expand All @@ -261,6 +269,7 @@ func (e *Exporter) exportOvnClusterInfoGauge() {
}

func (e *Exporter) exportOvnDBStatusGauge() {
metricDBStatus.Reset()
dbList := []string{"OVN_Northbound", "OVN_Southbound"}
for _, database := range dbList {
ok, err := getDBStatus(database)
Expand Down
32 changes: 32 additions & 0 deletions pkg/ovnmonitor/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,3 +280,35 @@ func getDBStatus(dbName string) (bool, error) {

return result, nil
}

func resetLogicalSwitchMetrics() {
metricLogicalSwitchInfo.Reset()
metricLogicalSwitchPortsNum.Reset()
metricLogicalSwitchPortBinding.Reset()
metricLogicalSwitchExternalIDs.Reset()
metricLogicalSwitchTunnelKey.Reset()
}

func resetLogicalSwitchPortMetrics() {
metricLogicalSwitchPortInfo.Reset()
metricLogicalSwitchPortTunnelKey.Reset()
}

func resetOvnClusterMetrics() {
metricClusterRole.Reset()
metricClusterStatus.Reset()
metricClusterTerm.Reset()
metricClusterLeaderSelf.Reset()
metricClusterVoteSelf.Reset()

metricClusterElectionTimer.Reset()
metricClusterNotCommittedEntryCount.Reset()
metricClusterNotAppliedEntryCount.Reset()
metricClusterLogIndexStart.Reset()
metricClusterLogIndexNext.Reset()

metricClusterInConnTotal.Reset()
metricClusterOutConnTotal.Reset()
metricClusterInConnErrTotal.Reset()
metricClusterOutConnErrTotal.Reset()
}

0 comments on commit ffdd196

Please sign in to comment.