Comments (5)
+1 on getting template_name instead of template_id
from anka-prometheus-exporter.
I'm quite new to golang, so I apologize for the quality of code. Actually I've developed something working in my environment.
The idea is to map the templates uuid with their names and then add it to the metric.
diff --git a/src/client/communicator.go b/src/client/communicator.go
index 3fe83a3..b66d6eb 100644
--- a/src/client/communicator.go
+++ b/src/client/communicator.go
@@ -64,7 +64,16 @@ func (this *Communicator) GetVmsData() (interface{}, error) {
if err != nil {
return nil, fmt.Errorf("getting vms data error: %s", err)
}
- return d, nil
+ s, err := this.GetRegistryVms()
+ if err != nil {
+ return nil, fmt.Errorf("getting vms registry data error: %s", err)
+ }
+ m := d.([]types.Instance)
+ for k, v := range m {
+ i := v.Vm.TemplateUUID
+ m[k].Vm.TemplateNAME = s[i]
+ }
+ return m, nil
}
func (this *Communicator) GetRegistryData() (interface{}, error) {
@@ -77,6 +86,21 @@ func (this *Communicator) GetRegistryData() (interface{}, error) {
return d, nil
}
+func (this *Communicator) GetRegistryVms() (map[string]string, error) {
+ endpoint := "/api/v1/registry/vm"
+ resp := &types.RegistryVmResponse{}
+ d, err := this.getData(endpoint, resp)
+ if err != nil {
+ return nil, fmt.Errorf("getting registry vms error: %s", err)
+ }
+ m := d.([]types.Vms)
+ VmsData := make(map[string]string)
+ for _, v := range m {
+ VmsData[v.VmID] = v.TemplateNAME
+ }
+ return VmsData, nil
+}
+
func (this *Communicator) getData(endpoint string, repsObject types.Response) (interface{}, error) {
r, err := this.getResponse(endpoint)
if err != nil {
diff --git a/src/metrics/instance_state_per.go b/src/metrics/instance_state_per.go
index d43c8d3..be61d7a 100644
--- a/src/metrics/instance_state_per.go
+++ b/src/metrics/instance_state_per.go
@ -32,14 +32,16 @@ func (this InstanceStatePerMetric) GetEventHandler() func(interface{}) error {
var ankaInstanceStatePerMetrics = []InstanceStatePerMetric{
InstanceStatePerMetric{
BaseAnkaMetric: BaseAnkaMetric{
- metric: CreateGaugeMetricVec("anka_instance_state_per_template_count", "Count of Instances in a particular state, per Template (label: state, template_name)", []string{"state", "template_uuid"}),
+ metric: CreateGaugeMetricVec("anka_instance_state_per_template_count", "Count of Instances in a particular state, per Template (label: state, template_uuid, template_name)", []string{"state", "template_uuid", "template_name"}),
event: events.EVENT_VM_DATA_UPDATED,
},
HandleData: func(instances []types.Instance, metric *prometheus.GaugeVec) {
var InstanceStatePerTemplateCountMap = map[string]map[string]int{}
var instanceTemplates []string
+ var instanceTemplatesMap = map[string]string{}
for _, instance := range instances {
instanceTemplates = append(instanceTemplates, instance.Vm.TemplateUUID)
+ instanceTemplatesMap[instance.Vm.TemplateUUID] = instance.Vm.TemplateNAME
}
instanceTemplates = uniqueThisStringArray(instanceTemplates)
for _, wantedState := range types.InstanceStates {
@@ -63,7 +65,7 @@ var ankaInstanceStatePerMetrics = []InstanceStatePerMetric{
checkAndHandleResetOfGuageVecMetric((len(instances) + len(instanceTemplates)), "anka_instance_state_per_template_count", metric)
for wantedState, wantedStateMap := range InstanceStatePerTemplateCountMap {
for wantedTemplateUUID, count := range wantedStateMap {
- metric.With(prometheus.Labels{"state": wantedState, "template_uuid": wantedTemplateUUID}).Set(float64(count))
+ metric.With(prometheus.Labels{"state": wantedState, "template_uuid": wantedTemplateUUID, "template_name": instanceTemplatesMap[wantedTemplateUUID]}).Set(float64(count))
}
}
},
@@ -154,4 +156,4 @@ func init() { // runs on exporter init only (updates are made with the above Eve
for _, instanceStatePerMetric := range ankaInstanceStatePerMetrics {
AddMetric(instanceStatePerMetric)
}
-}
+}
\ No newline at end of file
diff --git a/src/types/types.go b/src/types/types.go
index 8c254ed..b90a27c 100644
--- a/src/types/types.go
+++ b/src/types/types.go
@@ -57,10 +57,19 @@ type Instance struct {
type VmData struct {
State string `json:"instance_state"`
TemplateUUID string `json:"vmid"`
+ TemplateNAME string `json:"name"`
GroupUUID string `json:"group_id"`
NodeUUID string `json:"node_id"`
}
+type Vms struct {
+ TemplateNAME string `json:"name"`
+ VmID string `json:"id"`
+ Size int64 `json:"size"`
+}
+
+type TemplateMap interface{}
+
type Response interface {
GetStatus() string
GetMessage() string
@@ -98,6 +107,16 @@ func (this *RegistryResponse) GetBody() interface{} {
return this.Body
}
+type RegistryVmResponse struct {
+ DefaultResponse
+ Body []Vms `json:"body,omtiempty"`
+}
+
+func (this *RegistryVmResponse) GetBody() interface{} {
+ return this.Body
+}
+
+
type InstancesResponse struct {
DefaultResponse
Body []Instance `json:"body,omtiempty"`
@NorseGaud , I can review the code and propose a PR.
from anka-prometheus-exporter.
@Esysc Regarding a PR: please do!
from anka-prometheus-exporter.
I had not so much time to do earlier. Here it is: #12 !
from anka-prometheus-exporter.
Thanks! This is great! It works wonderfully. https://github.com/veertuinc/anka-prometheus-exporter/releases/tag/v2.1.4
from anka-prometheus-exporter.
Related Issues (6)
- [Feature Request] Support registry metrics without the controller
- [Feature Request] gitlab runner per user and per user group metrics HOT 7
- Exporter doesn't start if controller works through HTTPS/TLS HOT 1
- CLOUD-747: v2.0: Registry Disk Used Incorrect Label or Data HOT 1
- CLOUD-762: Nodes (and anything else impermanent) that are disjoined stick around in previous state HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from anka-prometheus-exporter.