Skip to content

Commit

Permalink
add rocksDB stats (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
xjlgod authored Apr 7, 2022
1 parent 83b83fd commit ef1aced
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
13 changes: 13 additions & 0 deletions exporter/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,19 @@ func (exporter *NebulaExporter) collect(wg *sync.WaitGroup, namespace, clusterNa
instance.Name, instance.EndpointPort)

wg.Add(2)
if instance.ComponentType == "storaged" {
wg.Add(1)
go func() {
defer wg.Done()
rocksDBStatus, err := getNebulaRocksDBStats(podIpAddress, podHttpPort)
if err != nil {
klog.Errorf("get query metrics from %s:%d failed: %v", podIpAddress, podHttpPort, err)
return
}
exporter.CollectMetrics(instance.Name, instance.ComponentType, namespace, clusterName, rocksDBStatus, ch)
}()
}

go func() {
defer wg.Done()
metrics, err := getNebulaMetrics(podIpAddress, podHttpPort)
Expand Down
21 changes: 21 additions & 0 deletions exporter/metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,27 @@ func getNebulaMetrics(ipAddress string, port int32) ([]string, error) {
return metrics, nil
}

func getNebulaRocksDBStats(ipAddress string, port int32) ([]string, error) {
httpClient := http.Client{
Timeout: time.Second * 2,
}

resp, err := httpClient.Get(fmt.Sprintf("http://%s:%d/rocksdb_stats", ipAddress, port))
if err != nil {
return []string{}, err
}
defer resp.Body.Close()

bytes, err := ioutil.ReadAll(resp.Body)
if err != nil {
return []string{}, err
}

metrics := strings.Split(strings.TrimSpace(string(bytes)), "\n")

return metrics, nil
}

func isNebulaComponentRunning(ipAddress string, port int32) bool {
httpClient := http.Client{
Timeout: time.Second * 2,
Expand Down

0 comments on commit ef1aced

Please sign in to comment.