-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #57 from gjasny/add-status
feat: add controller and registry state
- Loading branch information
Showing
7 changed files
with
121 additions
and
0 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
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
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
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) | ||
} | ||
} |
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