Skip to content

Commit

Permalink
metrics: Init metrics send all exists node info. (#189)
Browse files Browse the repository at this point in the history
  • Loading branch information
atlas-comstock authored Mar 26, 2020
1 parent 623779f commit d4f25d2
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 9 deletions.
17 changes: 17 additions & 0 deletions cluster/calcium/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,23 @@ func (c *Calcium) GetNodes(ctx context.Context, podname, nodename string, labels
return ns, err
}

// GetAllNodes get nodes
func (c *Calcium) GetAllNodes(ctx context.Context, labels map[string]string) ([]*types.Node, error) {
var listOfNodes []*types.Node
pods, err := c.ListPods(ctx)
if err != nil {
return listOfNodes, err
}
for _, pod := range pods {
nodes, err := c.ListPodNodes(ctx, pod.Name, labels, true)
if err != nil {
return listOfNodes, err
}
listOfNodes = append(listOfNodes, nodes...)
}
return listOfNodes, err
}

// SetNode set node available or not
func (c *Calcium) SetNode(ctx context.Context, opts *types.SetNodeOptions) (*types.Node, error) {
var n *types.Node
Expand Down
1 change: 1 addition & 0 deletions cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ type Cluster interface {
RemoveNode(ctx context.Context, nodename string) error
SetNode(ctx context.Context, opts *types.SetNodeOptions) (*types.Node, error)
GetNode(ctx context.Context, nodename string) (*types.Node, error)
GetAllNodes(ctx context.Context, labels map[string]string) ([]*types.Node, error)
NodeResource(ctx context.Context, nodename string) (*types.NodeResource, error)
// meta containers
GetContainer(ctx context.Context, ID string) (*types.Container, error)
Expand Down
23 changes: 23 additions & 0 deletions cluster/mocks/Cluster.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 21 additions & 4 deletions core.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"context"
"fmt"
"net"
"net/http"
Expand Down Expand Up @@ -45,6 +46,22 @@ func setupLog(l string) error {
return nil
}

func initMetrics(ctx context.Context, statsd string, cluster *calcium.Calcium) error {
if err := metrics.InitMetrics(statsd); err != nil {
return err
}
labels := map[string]string{}
nodes, err := cluster.GetAllNodes(ctx, labels)
if err != nil {
return err
}
for _, node := range nodes {
metrics.Client.SendNodeInfo(node)
}

return nil
}

func serve() {
config, err := utils.LoadConfig(configPath)
if err != nil {
Expand All @@ -55,16 +72,16 @@ func serve() {
log.Fatalf("[main] %v", err)
}

if err := metrics.InitMetrics(config.Statsd); err != nil {
log.Fatalf("[main] %v", err)
}

cluster, err := calcium.New(config, embeddedStorage)
if err != nil {
log.Fatalf("[main] %v", err)
}
defer cluster.Finalizer()

if err := initMetrics(context.Background(), config.Statsd, cluster); err != nil {
log.Fatalf("[main] initMetrics %v", err)
}

rpcch := make(chan struct{}, 1)
vibranium := rpc.New(cluster, config, rpcch)
s, err := net.Listen("tcp", config.Bind)
Expand Down
1 change: 1 addition & 0 deletions metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,5 +159,6 @@ func InitMetrics(statsd string) error {
Client.DeployCount, Client.MemoryCapacity,
Client.StorageCapacity, Client.CPUMap,
)

return nil
}
14 changes: 9 additions & 5 deletions store/mocks/Store.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d4f25d2

Please sign in to comment.