Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

release/v4.0.1 #54

Merged
merged 11 commits into from
Dec 12, 2024
Merged
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -142,6 +143,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)
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.0.0
4.0.1
12 changes: 6 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ go 1.22
toolchain go1.22.5

require (
github.com/prometheus/client_golang v1.20.4
github.com/prometheus/exporter-toolkit v0.13.0
github.com/prometheus/client_golang v1.20.5
github.com/prometheus/exporter-toolkit v0.13.1
)

require (
Expand All @@ -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
)
24 changes: 12 additions & 12 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -29,32 +29,32 @@ 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=
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=
Expand Down
2 changes: 2 additions & 0 deletions src/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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 {
Expand Down
12 changes: 12 additions & 0 deletions src/client/communicator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions src/events/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
69 changes: 69 additions & 0 deletions src/metrics/status.go
Original file line number Diff line number Diff line change
@@ -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)
}
}
8 changes: 8 additions & 0 deletions src/metrics/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
26 changes: 26 additions & 0 deletions src/types/types.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
package types

var ControllerStates = []string{
"Running",
}

var RegistryStates = []string{
"Running",
"FAIL",
}

var NodeStates = []string{
"Offline",
"Inactive (Invalid License)",
Expand All @@ -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"`
Expand Down Expand Up @@ -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"`
Expand Down
Loading