From 7bfedca500f7a1348aea9f4998d8c7404d74bbcc Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 15 Oct 2024 21:28:00 +0000 Subject: [PATCH 1/6] Bump github.com/prometheus/client_golang from 1.20.4 to 1.20.5 Bumps [github.com/prometheus/client_golang](https://github.com/prometheus/client_golang) from 1.20.4 to 1.20.5. - [Release notes](https://github.com/prometheus/client_golang/releases) - [Changelog](https://github.com/prometheus/client_golang/blob/main/CHANGELOG.md) - [Commits](https://github.com/prometheus/client_golang/compare/v1.20.4...v1.20.5) --- updated-dependencies: - dependency-name: github.com/prometheus/client_golang dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 2243a9b..a70ffaf 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.22 toolchain go1.22.5 require ( - github.com/prometheus/client_golang v1.20.4 + github.com/prometheus/client_golang v1.20.5 github.com/prometheus/exporter-toolkit v0.13.0 ) diff --git a/go.sum b/go.sum index 1cb5835..7750f3e 100644 --- a/go.sum +++ b/go.sum @@ -29,8 +29,8 @@ github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f h1:KUppIJq7/+ github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/prometheus/client_golang v1.20.4 h1:Tgh3Yr67PaOv/uTqloMsCEdeuFTatm5zIq5+qNN23vI= -github.com/prometheus/client_golang v1.20.4/go.mod h1:PIEt8X02hGcP8JWbeHyeZ53Y/jReSnHgO035n//V5WE= +github.com/prometheus/client_golang v1.20.5 h1:cxppBPuYhUnsO6yo/aoRol4L7q7UFfdm+bR9r+8l63Y= +github.com/prometheus/client_golang v1.20.5/go.mod h1:PIEt8X02hGcP8JWbeHyeZ53Y/jReSnHgO035n//V5WE= github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p8ais2e9E= github.com/prometheus/client_model v0.6.1/go.mod h1:OrxVMOVHjw3lKMa8+x6HeMGkHMQyHDk9E3jmP2AmGiY= github.com/prometheus/common v0.59.1 h1:LXb1quJHWm1P6wq/U824uxYi4Sg0oGvNeUm1z5dJoX0= From efb8c6176d95eafbbf68249a1e14081f783fce85 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 29 Oct 2024 21:38:04 +0000 Subject: [PATCH 2/6] Bump github.com/prometheus/exporter-toolkit from 0.13.0 to 0.13.1 Bumps [github.com/prometheus/exporter-toolkit](https://github.com/prometheus/exporter-toolkit) from 0.13.0 to 0.13.1. - [Release notes](https://github.com/prometheus/exporter-toolkit/releases) - [Changelog](https://github.com/prometheus/exporter-toolkit/blob/master/CHANGELOG.md) - [Commits](https://github.com/prometheus/exporter-toolkit/compare/v0.13.0...v0.13.1) --- updated-dependencies: - dependency-name: github.com/prometheus/exporter-toolkit dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- go.mod | 10 +++++----- go.sum | 20 ++++++++++---------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/go.mod b/go.mod index 2243a9b..921a699 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ toolchain go1.22.5 require ( github.com/prometheus/client_golang v1.20.4 - github.com/prometheus/exporter-toolkit v0.13.0 + github.com/prometheus/exporter-toolkit v0.13.1 ) require ( @@ -20,14 +20,14 @@ require ( github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f // indirect github.com/prometheus/client_model v0.6.1 // indirect - github.com/prometheus/common v0.59.1 // indirect + github.com/prometheus/common v0.60.1 // indirect github.com/prometheus/procfs v0.15.1 // indirect - golang.org/x/crypto v0.27.0 // indirect + golang.org/x/crypto v0.28.0 // indirect golang.org/x/net v0.29.0 // indirect golang.org/x/oauth2 v0.23.0 // indirect golang.org/x/sync v0.8.0 // indirect - golang.org/x/sys v0.25.0 // indirect - golang.org/x/text v0.18.0 // indirect + golang.org/x/sys v0.26.0 // indirect + golang.org/x/text v0.19.0 // indirect google.golang.org/protobuf v1.34.2 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect ) diff --git a/go.sum b/go.sum index 1cb5835..4976dc5 100644 --- a/go.sum +++ b/go.sum @@ -33,28 +33,28 @@ github.com/prometheus/client_golang v1.20.4 h1:Tgh3Yr67PaOv/uTqloMsCEdeuFTatm5zI github.com/prometheus/client_golang v1.20.4/go.mod h1:PIEt8X02hGcP8JWbeHyeZ53Y/jReSnHgO035n//V5WE= github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p8ais2e9E= github.com/prometheus/client_model v0.6.1/go.mod h1:OrxVMOVHjw3lKMa8+x6HeMGkHMQyHDk9E3jmP2AmGiY= -github.com/prometheus/common v0.59.1 h1:LXb1quJHWm1P6wq/U824uxYi4Sg0oGvNeUm1z5dJoX0= -github.com/prometheus/common v0.59.1/go.mod h1:GpWM7dewqmVYcd7SmRaiWVe9SSqjf0UrwnYnpEZNuT0= -github.com/prometheus/exporter-toolkit v0.13.0 h1:lmA0Q+8IaXgmFRKw09RldZmZdnvu9wwcDLIXGmTPw1c= -github.com/prometheus/exporter-toolkit v0.13.0/go.mod h1:2uop99EZl80KdXhv/MxVI2181fMcwlsumFOqBecGkG0= +github.com/prometheus/common v0.60.1 h1:FUas6GcOw66yB/73KC+BOZoFJmbo/1pojoILArPAaSc= +github.com/prometheus/common v0.60.1/go.mod h1:h0LYf1R1deLSKtD4Vdg8gy4RuOvENW2J/h19V5NADQw= +github.com/prometheus/exporter-toolkit v0.13.1 h1:Evsh0gWQo2bdOHlnz9+0Nm7/OFfIwhE2Ws4A2jIlR04= +github.com/prometheus/exporter-toolkit v0.13.1/go.mod h1:ujdv2YIOxtdFxxqtloLpbqmxd5J0Le6IITUvIRSWjj0= github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0learggepc= github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk= github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ= github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= -golang.org/x/crypto v0.27.0 h1:GXm2NjJrPaiv/h1tb2UH8QfgC/hOf/+z0p6PT8o1w7A= -golang.org/x/crypto v0.27.0/go.mod h1:1Xngt8kV6Dvbssa53Ziq6Eqn0HqbZi5Z6R0ZpwQzt70= +golang.org/x/crypto v0.28.0 h1:GBDwsMXVQi34v5CCYUm2jkJvu4cbtru2U4TN2PSyQnw= +golang.org/x/crypto v0.28.0/go.mod h1:rmgy+3RHxRZMyY0jjAJShp2zgEdOqj2AO7U0pYmeQ7U= golang.org/x/net v0.29.0 h1:5ORfpBpCs4HzDYoodCDBbwHzdR5UrLBZ3sOnUJmFoHo= golang.org/x/net v0.29.0/go.mod h1:gLkgy8jTGERgjzMic6DS9+SP0ajcu6Xu3Orq/SpETg0= golang.org/x/oauth2 v0.23.0 h1:PbgcYx2W7i4LvjJWEbf0ngHV6qJYr86PkAV3bXdLEbs= golang.org/x/oauth2 v0.23.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI= golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ= golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= -golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34= -golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/text v0.18.0 h1:XvMDiNzPAl0jr17s6W9lcaIhGUfUORdGCNsuLmPG224= -golang.org/x/text v0.18.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= +golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo= +golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM= +golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg= google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= From 7dad6a17e58a3989021feea4a03dc90758201dcb Mon Sep 17 00:00:00 2001 From: Gregor Jasny Date: Fri, 8 Nov 2024 09:45:37 +0100 Subject: [PATCH 3/6] docs: add ANKA_PROMETHEUS_EXPORTER_WEB_LISTEN_ADDRESS --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index d96dfb2..d63f34f 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,7 @@ Ensure you have a functioning Prometheus instance before using this. | ANKA_PROMETHEUS_EXPORTER_UAK_PATH (string) | --uak-path (string) | | ANKA_PROMETHEUS_EXPORTER_UAK_STRING (string) | --uak-string (string) | | ANKA_PROMETHEUS_EXPORTER_WEB_CONFIG_FILE (string) | --web.config.file (string) | +| ANKA_PROMETHEUS_EXPORTER_WEB_LISTEN_ADDRESS (string) | -web.listen-address (string) | ```bash Usage of anka-prometheus-exporter: From 8fc12166703008d037e6890a148fb060f032ddf4 Mon Sep 17 00:00:00 2001 From: Nathan Date: Mon, 2 Dec 2024 07:48:48 -0600 Subject: [PATCH 4/6] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d63f34f..48b58e1 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ Ensure you have a functioning Prometheus instance before using this. | ANKA_PROMETHEUS_EXPORTER_UAK_PATH (string) | --uak-path (string) | | ANKA_PROMETHEUS_EXPORTER_UAK_STRING (string) | --uak-string (string) | | ANKA_PROMETHEUS_EXPORTER_WEB_CONFIG_FILE (string) | --web.config.file (string) | -| ANKA_PROMETHEUS_EXPORTER_WEB_LISTEN_ADDRESS (string) | -web.listen-address (string) | +| ANKA_PROMETHEUS_EXPORTER_WEB_LISTEN_ADDRESS (string) | --web.listen-address (string) | ```bash Usage of anka-prometheus-exporter: From a5738d3218799c8b551b22dfec533d5cf5ecff56 Mon Sep 17 00:00:00 2001 From: Gregor Jasny Date: Fri, 6 Dec 2024 22:05:15 +0100 Subject: [PATCH 5/6] feat: add controller and registry state --- README.md | 3 ++ src/client/client.go | 2 ++ src/client/communicator.go | 12 +++++++ src/events/events.go | 1 + src/metrics/status.go | 69 ++++++++++++++++++++++++++++++++++++++ src/metrics/utils.go | 8 +++++ src/types/types.go | 26 ++++++++++++++ 7 files changed, 121 insertions(+) create mode 100644 src/metrics/status.go diff --git a/README.md b/README.md index d96dfb2..e0cd37e 100644 --- a/README.md +++ b/README.md @@ -142,6 +142,9 @@ The `-client-tls` flag is not required if your controller certificate is signed Metric name | Description ---- | ---------- +anka_controller_state_count | Status of the Anka Controller (labels: state) +anka_registry_state_count | Status of the Anka Registry (labels: state) +-- | -- anka_instance_state_count | Count of Instances in a particular State (labels: arch, state) anka_instance_state_per_template_count | Count of Instances in a particular state, per Template (labels: state, template_uuid, template_name) anka_instance_state_per_group_count | Count of Instances in a particular state, per Group (labels: state, group_name) diff --git a/src/client/client.go b/src/client/client.go index c34b18b..34722b9 100644 --- a/src/client/client.go +++ b/src/client/client.go @@ -35,6 +35,7 @@ func NewClient(addr, username, password string, interval int, certs ClientTLSCer events.EVENT_REGISTRY_DISK_DATA_UPDATED: make([]func(interface{}) error, 0), events.EVENT_VM_DATA_UPDATED: make([]func(interface{}) error, 0), events.EVENT_REGISTRY_TEMPLATES_UPDATED: make([]func(interface{}) error, 0), + events.EVENT_STATUS_UPDATED: make([]func(interface{}) error, 0), }, communicator: communicator, timeoutSeconds: int64(interval), @@ -55,6 +56,7 @@ func (client *Client) Init() { go client.initDataLoop(client.communicator.GetVmsData, events.EVENT_VM_DATA_UPDATED) go client.initDataLoop(client.communicator.GetRegistryDiskData, events.EVENT_REGISTRY_DISK_DATA_UPDATED) go client.initDataLoop(client.communicator.GetRegistryTemplatesData, events.EVENT_REGISTRY_TEMPLATES_UPDATED) + go client.initDataLoop(client.communicator.GetStatus, events.EVENT_STATUS_UPDATED) } func (client *Client) Register(ev events.Event, eventHandler func(interface{}) error) error { diff --git a/src/client/communicator.go b/src/client/communicator.go index dc8b428..5b006b5 100644 --- a/src/client/communicator.go +++ b/src/client/communicator.go @@ -89,6 +89,18 @@ func (comm *Communicator) TestConnection() error { } } +func (comm *Communicator) GetStatus() (interface{}, error) { + lock.Lock() + defer lock.Unlock() + endpoint := "/api/v1/status" + resp := &types.StatusResponse{} + d, err := comm.getData(endpoint, resp) + if err != nil { + return nil, fmt.Errorf("getting status error: %s", err) + } + return d, nil +} + func (comm *Communicator) GetNodesData() (interface{}, error) { lock.Lock() defer lock.Unlock() diff --git a/src/events/events.go b/src/events/events.go index 951e414..4d85ee9 100644 --- a/src/events/events.go +++ b/src/events/events.go @@ -7,4 +7,5 @@ const ( EVENT_REGISTRY_DISK_DATA_UPDATED = 2 EVENT_VM_DATA_UPDATED = 3 EVENT_REGISTRY_TEMPLATES_UPDATED = 4 + EVENT_STATUS_UPDATED = 5 ) diff --git a/src/metrics/status.go b/src/metrics/status.go new file mode 100644 index 0000000..f14ae8b --- /dev/null +++ b/src/metrics/status.go @@ -0,0 +1,69 @@ +package metrics + +import ( + "github.com/prometheus/client_golang/prometheus" + "github.com/veertuinc/anka-prometheus-exporter/src/events" + "github.com/veertuinc/anka-prometheus-exporter/src/types" +) + +type StatusMetric struct { + BaseAnkaMetric + HandleData func(*types.Status, *prometheus.GaugeVec) +} + +func (sm StatusMetric) GetEventHandler() func(interface{}) error { + return func(d interface{}) error { + status, err := ConvertToStatusData(d) + if err != nil { + return err + } + metric, err := ConvertMetricToGaugeVec(sm.metric) + if err != nil { + return err + } + sm.HandleData( + status, + metric, + ) + return nil + } +} + +var ankaStatusMetrics = []StatusMetric{ + { + BaseAnkaMetric: BaseAnkaMetric{ + metric: CreateGaugeMetricVec("anka_controller_state_count", "Status of the Anka Controller", []string{"state"}), + event: events.EVENT_STATUS_UPDATED, + }, + HandleData: func(status *types.Status, metric *prometheus.GaugeVec) { + for _, state := range types.ControllerStates { + counter := 0 + if status.Status == state { + counter++ + } + metric.With(prometheus.Labels{"state": state}).Set(float64(counter)) + } + }, + }, + { + BaseAnkaMetric: BaseAnkaMetric{ + metric: CreateGaugeMetricVec("anka_registry_state_count", "Status of the Anka Registry", []string{"state"}), + event: events.EVENT_STATUS_UPDATED, + }, + HandleData: func(status *types.Status, metric *prometheus.GaugeVec) { + for _, state := range types.RegistryStates { + counter := 0 + if status.RegistryStatus == state { + counter++ + } + metric.With(prometheus.Labels{"state": state}).Set(float64(counter)) + } + }, + }, +} + +func init() { // runs on exporter init only (updates are made with the above EventHandler; triggered by the Client) + for _, statusMetric := range ankaStatusMetrics { + AddMetric(statusMetric) + } +} diff --git a/src/metrics/utils.go b/src/metrics/utils.go index 2aa0aa5..fd2abde 100644 --- a/src/metrics/utils.go +++ b/src/metrics/utils.go @@ -62,6 +62,14 @@ func CreateGaugeMetricVec(name string, help string, labels []string) *prometheus }, labels) } +func ConvertToStatusData(d interface{}) (*types.Status, error) { + data, ok := d.(types.Status) + if !ok { + return nil, fmt.Errorf("could not convert incoming data to required status information. original data: %v", d) + } + return &data, nil +} + func ConvertToNodeData(d interface{}) ([]types.Node, error) { data, ok := d.([]types.Node) if !ok { diff --git a/src/types/types.go b/src/types/types.go index d934bb8..fea9aa6 100644 --- a/src/types/types.go +++ b/src/types/types.go @@ -1,5 +1,14 @@ package types +var ControllerStates = []string{ + "Running", +} + +var RegistryStates = []string{ + "Running", + "FAIL", +} + var NodeStates = []string{ "Offline", "Inactive (Invalid License)", @@ -25,6 +34,14 @@ var InstanceStates = []string{ "Pushing", } +type Status struct { + Status string `json:"status"` + Version string `json:"version"` + RegistryAddress string `json:"registry_address"` + RegistryStatus string `json:"registry_status"` + License string `json:"license"` +} + type Node struct { NodeID string `json:"node_id"` NodeName string `json:"node_name"` @@ -89,6 +106,15 @@ func (dr *DefaultResponse) GetMessage() string { return dr.Message } +type StatusResponse struct { + DefaultResponse + Body Status `json:"body"` +} + +func (sr *StatusResponse) GetBody() interface{} { + return sr.Body +} + type NodesResponse struct { DefaultResponse Body []Node `json:"body"` From 775b1168b85a673f70b3f550213e39aad8f4aabf Mon Sep 17 00:00:00 2001 From: Nathan Pierce Date: Wed, 11 Dec 2024 16:22:42 -0600 Subject: [PATCH 6/6] quick fix --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 0c89fc9..cc868b6 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -4.0.0 \ No newline at end of file +4.0.1 \ No newline at end of file