Skip to content

Commit

Permalink
feat(main): add zero value metrics (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
capuche2412 authored Dec 7, 2023
1 parent 55cb398 commit ebde972
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ var (
)

type Task struct {
Type string
Runner_Status string
Total int
Type string
RunnerStatus string
Total int
}

type DruidTasksExporter struct {
Expand Down Expand Up @@ -61,7 +61,6 @@ func (d *DruidTasksExporter) RetrieveMetrics() []Task {
if err != nil {
log.Fatalf("An Error occured while unmarshalling %s: %v", body, err)
}
fmt.Println(tasks)
return tasks
}

Expand All @@ -71,13 +70,31 @@ func (c *DruidTasksExporter) Describe(ch chan<- *prometheus.Desc) {

func (d *DruidTasksExporter) Collect(ch chan<- prometheus.Metric) {
tasks := d.RetrieveMetrics()
runnerStatuses := []string{"NONE", "PENDING", "RUNNING", "WAITING"}
taskTypes := []string{"single_phase_sub_task", "index", "index_parallel", "kill", "compact"}

for _, status := range runnerStatuses {
for _, taskType := range taskTypes {
is_present := false
for _, task := range tasks {
if task.Type == taskType && task.RunnerStatus == status {
is_present = true
}
}
if !is_present {
tasks = append(tasks, Task{Type: taskType, RunnerStatus: status, Total: 0})

}

}
}
for _, task := range tasks {
ch <- prometheus.MustNewConstMetric(
d.Tasks,
prometheus.GaugeValue,
float64(task.Total),
task.Type,
task.Runner_Status,
task.RunnerStatus,
)
}
}
Expand Down

0 comments on commit ebde972

Please sign in to comment.