Skip to content
This repository has been archived by the owner on Oct 30, 2024. It is now read-only.

Commit

Permalink
Add cluster info with status property (#980)
Browse files Browse the repository at this point in the history
* Add cluster info with status property

* Deletion timestamp is not annotation is property under metadata

* Add paggintation

* Short g8s client alphabetically

* Align var definition
  • Loading branch information
pipo02mix authored Jun 6, 2018
1 parent 9d79939 commit a789f08
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 4 deletions.
66 changes: 66 additions & 0 deletions service/collector/cluster_info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package collector

import (
"github.com/prometheus/client_golang/prometheus"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

const (
clusterLabel = "cluster_id"
statusLabel = "status"
listClusterConfigLimit = 20
)

var clustersDesc *prometheus.Desc = prometheus.NewDesc(
prometheus.BuildFQName(Namespace, "", "cluster_info"),
"Cluster information.",
[]string{
clusterLabel,
statusLabel,
},
nil,
)

func (c *Collector) collectClusterInfo(ch chan<- prometheus.Metric) {
c.logger.Log("level", "debug", "message", "collecting metrics for clusters")

opts := v1.ListOptions{
Limit: listClusterConfigLimit,
}

continueToken := ""

for {
opts.Continue = continueToken

clustersConfigList, err := c.g8sClient.ProviderV1alpha1().AWSConfigs("").List(opts)
if err != nil {
c.logger.Log(err)
}

for _, clusterConfig := range clustersConfigList.Items {

clusterID := clusterConfig.Name
status := "Running"

if clusterConfig.DeletionTimestamp != nil {
status = "Terminating"
}

ch <- prometheus.MustNewConstMetric(
clustersDesc,
prometheus.GaugeValue,
GaugeValue,
clusterID,
status,
)
}

continueToken = clustersConfigList.Continue
if continueToken == "" {
break
}
}

c.logger.Log("level", "debug", "message", "finished collecting metrics for clusters")
}
17 changes: 14 additions & 3 deletions service/collector/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,30 @@ import (

"github.com/giantswarm/microerror"
"github.com/giantswarm/micrologger"

"github.com/giantswarm/apiextensions/pkg/clientset/versioned"
)

type Config struct {
Logger micrologger.Logger
G8sClient versioned.Interface
Logger micrologger.Logger

AwsConfig awsutil.Config
InstallationName string
}

type Collector struct {
logger micrologger.Logger
g8sClient versioned.Interface
logger micrologger.Logger

awsClients awsutil.Clients
installationName string
}

func New(config Config) (*Collector, error) {
if config.G8sClient == nil {
return nil, microerror.Maskf(invalidConfigError, "%T.G8sClient must not be empty", config)
}
if config.Logger == nil {
return nil, microerror.Maskf(invalidConfigError, "%T.Logger must not be empty", config)
}
Expand All @@ -38,7 +45,8 @@ func New(config Config) (*Collector, error) {
awsClients := awsutil.NewClients(config.AwsConfig)

c := &Collector{
logger: config.Logger,
g8sClient: config.G8sClient,
logger: config.Logger,

awsClients: awsClients,
installationName: config.InstallationName,
Expand All @@ -49,12 +57,15 @@ func New(config Config) (*Collector, error) {

func (c *Collector) Describe(ch chan<- *prometheus.Desc) {
ch <- vpcsDesc
ch <- clustersDesc
}

func (c *Collector) Collect(ch chan<- prometheus.Metric) {
c.logger.Log("level", "debug", "message", "collecting metrics")

c.collectVPCs(ch)

c.collectClusterInfo(ch)

c.logger.Log("level", "debug", "message", "finished collecting metrics")
}
3 changes: 2 additions & 1 deletion service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,8 @@ func New(config Config) (*Service, error) {
var metricsCollector *collector.Collector
{
c := collector.Config{
Logger: config.Logger,
G8sClient: g8sClient,
Logger: config.Logger,

AwsConfig: awsConfig,
InstallationName: config.Viper.GetString(config.Flag.Service.Installation.Name),
Expand Down

0 comments on commit a789f08

Please sign in to comment.