Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
Signed-off-by: sayedppqq <[email protected]>
  • Loading branch information
sayedppqq committed Jan 30, 2024
1 parent 7f9fd7f commit 8accbb3
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 0 deletions.
27 changes: 27 additions & 0 deletions pkg/connection/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package connection
import (
"k8s.io/klog/v2"
cmdutil "k8s.io/kubectl/pkg/cmd/util"
"kubedb.dev/cli/pkg/lib"
"log"
"strconv"
)

// kubectl dba monitor check-connection mongodb -n demo sample_mg -> all connection check and report
Expand All @@ -13,6 +15,10 @@ type PromSvc struct {
Namespace string
Port int
}
type metrics struct {
metric string
label string
}

func Run(f cmdutil.Factory, args []string, prom PromSvc) {
if len(args) < 2 {
Expand All @@ -26,4 +32,25 @@ func Run(f cmdutil.Factory, args []string, prom PromSvc) {
klog.Error(err, "failed to get current namespace")
}

identicalMetrics := []metrics{
{metric: cAdvisorMetric},
{metric: kubeletMetric},
{metric: ksmMetric},
{metric: nodeExporterMetric},
}
identicalMetrics = append(identicalMetrics, getDBMetrics(database, databaseName, namespace)...)

config, err := f.ToRESTConfig()
if err != nil {
log.Fatal(err)
}
// Port forwarding cluster prometheus service for that grafana dashboard's prom datasource.
tunnel, err := lib.TunnelToDBService(config, prom.Name, prom.Namespace, prom.Port)
if err != nil {
log.Fatal(err)
}
defer tunnel.Close()

promClient := getPromClient(strconv.Itoa(tunnel.Local))

}
66 changes: 66 additions & 0 deletions pkg/connection/helper.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package connection

import (
"fmt"
"github.com/prometheus/client_golang/api"
v1 "github.com/prometheus/client_golang/api/prometheus/v1"
"log"
)

const (
cAdvisorMetric = "container_cpu_usage_seconds_total"
kubeletMetric = "kubelet_active_pods"
ksmMetric = "kube_pod_status_phase"
nodeExporterMetric = "node_cpu_seconds_total"
)

func getIdenticalMetrics(database, databaseName, namespace string) []metrics {
identicalMetrics := []metrics{
{metric: cAdvisorMetric},
{metric: kubeletMetric},
{metric: ksmMetric},
{metric: nodeExporterMetric},
}
identicalMetrics = append(identicalMetrics, getDBMetrics(database, databaseName, namespace)...)
return identicalMetrics
}
func getDBMetrics(database, name, namespace string) []metrics {
var dbMetric []metrics
label := fmt.Sprintf("%s-stats", name)
metric := fmt.Sprintf("kubedb_com_%s", database)
switch database {
case "mongodb":
dbMetric = append(dbMetric, metrics{
metric: "",
label: "",
})
case "postgres":
case "mysql":
case "redis":
case "mariadb":
case "proxysql":
case "elasticsearch":
case "perconaxtradb":
case "kafka":
default:
log.Fatal("database invalid")
}
panopticon := getPanopticonMetric()
}
func getPanopticonMetric() {

}

func getPromClient(localPort string) v1.API {
prometheusURL := fmt.Sprintf("http://localhost:%s/", localPort)

client, err := api.NewClient(api.Config{
Address: prometheusURL,
})
if err != nil {
log.Fatal("Error creating Prometheus client:", err)
}

// Create a new Prometheus API client
return v1.NewAPI(client)
}

0 comments on commit 8accbb3

Please sign in to comment.