Skip to content

Commit

Permalink
update ovn monitor (#3903)
Browse files Browse the repository at this point in the history
Signed-off-by: 马洪贞 <hzma@alauda.io>
  • Loading branch information
hongzhen-ma committed Apr 16, 2024
1 parent c91d5b6 commit 698c934
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 9 deletions.
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ require (
github.com/evanphx/json-patch/v5 v5.9.0
github.com/go-logr/stdr v1.2.2
github.com/golang/mock v1.6.0
github.com/greenpau/ovsdb v1.0.3
github.com/k8snetworkplumbingwg/network-attachment-definition-client v1.4.0
github.com/k8snetworkplumbingwg/sriovnet v1.2.0
github.com/kubeovn/go-iptables v0.0.0-20230322103850-8619a8ab3dca
github.com/kubeovn/gonetworkmanager/v2 v2.0.0-20230905082151-e28c4d73a589
github.com/kubeovn/ovsdb v0.0.0-20240410091831-5dd26006c475
github.com/mdlayher/arp v0.0.0-20220512170110-6706a2966875
github.com/moby/sys/mountinfo v0.7.1
github.com/onsi/ginkgo/v2 v2.17.1
Expand Down Expand Up @@ -286,7 +286,6 @@ require (

replace (
github.com/alauda/felix => github.com/kubeovn/felix v0.0.0-20220325073257-c8a0f705d139
github.com/greenpau/ovsdb => github.com/kubeovn/ovsdb v0.0.0-20221213053943-9372db56919f
github.com/mdlayher/arp => github.com/kubeovn/arp v0.0.0-20230101053045-8a0772d9c34c
github.com/openshift/client-go => github.com/openshift/client-go v0.0.0-20221107163225-3335a34a1d24
github.com/ovn-org/libovsdb => github.com/kubeovn/libovsdb v0.0.0-20230517064328-9d5a1383643f
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1371,8 +1371,8 @@ github.com/kubeovn/libovsdb v0.0.0-20230517064328-9d5a1383643f h1:HDjnbJZN+2T3XH
github.com/kubeovn/libovsdb v0.0.0-20230517064328-9d5a1383643f/go.mod h1:NHoQwGSKygdpFb8y7HBS6b1HP4EtJ14zzLrnd/A1fmY=
github.com/kubeovn/netlink v0.0.0-20230322092337-960188369daf h1:inZiuUjcQaX0O0Sdki38TWzCl0+wJty+vaQKEr47by8=
github.com/kubeovn/netlink v0.0.0-20230322092337-960188369daf/go.mod h1:p3BbJwJMQKnFy+IfKc5stjSCxpLN5d6R3MFOM3TQitw=
github.com/kubeovn/ovsdb v0.0.0-20221213053943-9372db56919f h1:nm0ZlQesCje/A5D0LyWfaSUM8/0ro9PVpwd8hVbLBeM=
github.com/kubeovn/ovsdb v0.0.0-20221213053943-9372db56919f/go.mod h1:LAd0qoeAAm/QyZcpxN2BnpndM2/dhZt+/kokPvcxKcE=
github.com/kubeovn/ovsdb v0.0.0-20240410091831-5dd26006c475 h1:KZba2Kj9TXCUdUSqOR3eiy4VvkkIyhDVImYmYs6GQWU=
github.com/kubeovn/ovsdb v0.0.0-20240410091831-5dd26006c475/go.mod h1:LAd0qoeAAm/QyZcpxN2BnpndM2/dhZt+/kokPvcxKcE=
github.com/kubernetes-csi/external-snapshotter/client/v4 v4.2.0 h1:nHHjmvjitIiyPlUHk/ofpgvBcNcawJLtf4PYHORLjAA=
github.com/kubernetes-csi/external-snapshotter/client/v4 v4.2.0/go.mod h1:YBCo4DoEeDndqvAn6eeu0vWM7QdXmHEeI9cFWplmBys=
github.com/kylelemons/godebug v0.0.0-20160406211939-eadb3ce320cb/go.mod h1:B69LEHPfb2qLo0BaaOLcbitczOKLWTsrBG9LczfCD4k=
Expand Down
10 changes: 8 additions & 2 deletions pkg/ovnmonitor/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"sync"
"time"

"github.com/greenpau/ovsdb"
"github.com/kubeovn/ovsdb"
"k8s.io/klog/v2"

"github.com/kubeovn/kube-ovn/pkg/util"
Expand Down Expand Up @@ -174,6 +174,12 @@ func (e *Exporter) exportOvnStatusGauge() {
for k, v := range result {
metricOvnHealthyStatus.WithLabelValues(e.Client.System.Hostname, k).Set(float64(v))
}

metricOvnHealthyStatusContent.Reset()
statusResult := e.getOvnStatusContent()
for k, v := range statusResult {
metricOvnHealthyStatusContent.WithLabelValues(e.Client.System.Hostname, k, v).Set(float64(1))
}
}

func (e *Exporter) exportOvnLogFileSizeGauge() {
Expand Down Expand Up @@ -223,7 +229,7 @@ func (e *Exporter) exportOvnChassisGauge() {
e.IncrementErrorCounter()
} else {
for _, vtep := range vteps {
metricChassisInfo.WithLabelValues(e.Client.System.Hostname, vtep.UUID, vtep.Name, vtep.IPAddress.String()).Set(1)
metricChassisInfo.WithLabelValues(vtep.Hostname, vtep.UUID, vtep.Name, vtep.IPAddress.String()).Set(1)
}
}
}
Expand Down
13 changes: 13 additions & 0 deletions pkg/ovnmonitor/metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,18 @@ var (
"component",
})

metricOvnHealthyStatusContent = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: metricNamespace,
Name: "ovn_status_content",
Help: "OVN Health Status. The values are always 1. While the value of status label is the really status report.",
},
[]string{
"hostname",
"component",
"status",
})

metricRequestErrorNums = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: metricNamespace,
Expand Down Expand Up @@ -465,6 +477,7 @@ var (
func registerOvnMetrics() {
// ovn status metrics
prometheus.MustRegister(metricOvnHealthyStatus)
prometheus.MustRegister(metricOvnHealthyStatusContent)
prometheus.MustRegister(metricRequestErrorNums)
prometheus.MustRegister(metricLogFileSize)
prometheus.MustRegister(metricDBFileSize)
Expand Down
32 changes: 31 additions & 1 deletion pkg/ovnmonitor/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"strings"
"sync/atomic"

"github.com/greenpau/ovsdb"
"github.com/kubeovn/ovsdb"
"k8s.io/klog/v2"
)

Expand Down Expand Up @@ -71,6 +71,36 @@ func (e *Exporter) getOvnStatus() map[string]int {
return result
}

func (e *Exporter) getOvnStatusContent() map[string]string {
result := map[string]string{"ovsdb-server-northbound": "", "ovsdb-server-southbound": ""}

// get ovn-northbound status
cmdstr := "ovs-appctl -t /var/run/ovn/ovnnb_db.ctl cluster/status OVN_Northbound"
cmd := exec.Command("sh", "-c", cmdstr)
output, err := cmd.CombinedOutput()
if err != nil {
klog.Errorf("get ovn-northbound status failed, err %v", err)
}
if strings.Contains(string(output), "Servers:") {
servers := strings.Split(string(output), "Servers:")[1]
result["ovsdb-server-northbound"] = servers
}

// get ovn-southbound status
cmdstr = "ovs-appctl -t /var/run/ovn/ovnsb_db.ctl cluster/status OVN_Southbound"
cmd = exec.Command("sh", "-c", cmdstr)
output, err = cmd.CombinedOutput()
if err != nil {
klog.Errorf("get ovn-southbound status failed, err %v", err)
}
if strings.Contains(string(output), "Servers:") {
servers := strings.Split(string(output), "Servers:")[1]
result["ovsdb-server-southbound"] = servers
}

return result
}

func getClusterEnableState(dbName string) (bool, error) {
cmdstr := fmt.Sprintf("ovsdb-tool db-is-clustered %s", dbName)
cmd := exec.Command("sh", "-c", cmdstr)
Expand Down
2 changes: 1 addition & 1 deletion pkg/pinger/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"sync"
"time"

"github.com/greenpau/ovsdb"
"github.com/kubeovn/ovsdb"
"k8s.io/klog/v2"
)

Expand Down
2 changes: 1 addition & 1 deletion pkg/pinger/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"strings"
"sync/atomic"

"github.com/greenpau/ovsdb"
"github.com/kubeovn/ovsdb"
"k8s.io/klog/v2"
)

Expand Down

0 comments on commit 698c934

Please sign in to comment.