This repository has been archived by the owner on Oct 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add cluster info with status property (#980)
* 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
Showing
3 changed files
with
82 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters