Skip to content

Commit

Permalink
Merge pull request #17 from pf93/feature-keruntime-prometheus-monitor
Browse files Browse the repository at this point in the history
Feature keruntime prometheus monitor
  • Loading branch information
qidu authored Aug 18, 2023
2 parents 4a10ed1 + 6d89f47 commit 2ed03e4
Show file tree
Hide file tree
Showing 7 changed files with 368 additions and 5 deletions.
20 changes: 20 additions & 0 deletions cloud/pkg/common/monitor/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ import (
"time"

"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/push"
"github.com/prometheus/client_golang/prometheus/promhttp"
mikunode "github.com/qbox/mikud-live/common/node"
"k8s.io/klog/v2"

beehivecontext "github.com/kubeedge/beehive/pkg/core/context"
Expand Down Expand Up @@ -68,6 +70,22 @@ func InstallHandlerForPProf(mux *http.ServeMux) {
mux.HandleFunc("/debug/pprof/trace", pprof.Trace)
}

func loopPrometheusPush(config config.MonitorServer) {
conf := config.Prometheus
if conf.IntervalS <= 0 {
conf.IntervalS = 10
}
for range time.Tick(time.Duration(conf.IntervalS) * time.Second) {
err := push.New(conf.Server, conf.Job).
Collector(ConnectedNodes).
Grouping("instance", mikunode.GetNodeId()).
Add();
if err != nil {
klog.Errorf("prometheus push failed:%v", err)
}
}
}

// ServeMonitor serve monitoring metric.
func ServeMonitor(config config.MonitorServer) {
registerMetrics()
Expand Down Expand Up @@ -95,6 +113,8 @@ func ServeMonitor(config config.MonitorServer) {
}
}()

go loopPrometheusPush(config)

klog.Infof("starting monitor server on addr: %s", config.BindAddress)
klog.Exit(s.ListenAndServe())
}
2 changes: 2 additions & 0 deletions common/constants/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ const (
DefaultTunnelPort = 10004
DefaultClusterDomain = "cluster.local"

// monitor server
DefaultJobName = "connected_node_count"
// appsd
DefaultSupervisordEndpoint = "/tmp/supervisor.sock"
DefaultSupervisordConfDir = "/etc/supervisord"
Expand Down
7 changes: 6 additions & 1 deletion pkg/apis/componentconfig/cloudcore/v1alpha1/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,13 @@ func NewDefaultCloudCoreConfig() *CloudCoreConfig {
CommonConfig: &CommonConfig{
TunnelPort: constants.ServerPort,
MonitorServer: MonitorServer{
BindAddress: "127.0.0.1:9091",
BindAddress: "127.0.0.1:9001",
EnableProfiling: false,
Prometheus: Prometheus{
Server: "127.0.0.1:9091",
IntervalS: 10,
Job: constants.DefaultJobName,
},
},
},
KubeAPIConfig: &KubeAPIConfig{
Expand Down
17 changes: 16 additions & 1 deletion pkg/apis/componentconfig/cloudcore/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,27 @@ type CommonConfig struct {
// MonitorServer indicates MonitorServer config
type MonitorServer struct {
// BindAddress is the IP address and port for the monitor server to serve on,
// defaulting to 127.0.0.1:9091 (set to 0.0.0.0 for all interfaces)
// defaulting to 127.0.0.1:9001 (set to 0.0.0.0 for all interfaces)
BindAddress string `json:"bindAddress,omitempty"`

// EnableProfiling enables profiling via web interface on /debug/pprof handler.
// Profiling handlers will be handled by monitor server.
EnableProfiling bool `json:"enableProfiling,omitempty"`

// prometheus is the config for the monitor metric data to push,
Prometheus Prometheus `json:"prometheus,omitempty"`
}

type Prometheus struct {
// Server is the IP address and port for the metric data to push,
// defaulting to 127.0.0.1:9091 (set to 0.0.0.0 for all interfaces)
Server string `json:"server,omitempty"`
// IntervalS is the time interval for pushing data to the prometheus service,
// defaulting to 10
IntervalS int `json:"interval_s,omitempty"`
// Job is the name of push job,
// defaulting to connected_node_count
Job string `json:"job,omitempty"`
}

// KubeAPIConfig indicates the configuration for interacting with k8s server
Expand Down
6 changes: 3 additions & 3 deletions pkg/apis/componentconfig/edgecore/v1alpha2/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ import (
"github.com/kubeedge/kubeedge/common/constants"
metaconfig "github.com/kubeedge/kubeedge/pkg/apis/componentconfig/meta/v1alpha1"
"github.com/kubeedge/kubeedge/pkg/util"
common "github.com/qbox/mikud-live/common/node"
mikunode "github.com/qbox/mikud-live/common/node"
)

// NewDefaultEdgeCoreConfig returns a full EdgeCoreConfig object
func NewDefaultEdgeCoreConfig() *EdgeCoreConfig {
hostnameOverride := common.GetNodeId()
hostnameOverride := mikunode.GetNodeId()
localIP, _ := util.GetLocalIP(util.GetHostname())

defaultTailedKubeletConfig := TailoredKubeletConfiguration{}
Expand Down Expand Up @@ -172,7 +172,7 @@ func NewDefaultEdgeCoreConfig() *EdgeCoreConfig {

// NewMinEdgeCoreConfig returns a common EdgeCoreConfig object
func NewMinEdgeCoreConfig() *EdgeCoreConfig {
hostnameOverride := common.GetNodeId()
hostnameOverride := mikunode.GetNodeId()
localIP, _ := util.GetLocalIP(util.GetHostname())

defaultTailedKubeletConfig := TailoredKubeletConfiguration{}
Expand Down
Loading

0 comments on commit 2ed03e4

Please sign in to comment.