Skip to content

Commit

Permalink
Merge pull request #6 from montblu/1-fix-hardcoded-environment
Browse files Browse the repository at this point in the history
Fix AWS Environment Hardcode
  • Loading branch information
MiguelNdeCarvalho authored Dec 8, 2024
2 parents c863c49 + d2759a3 commit f848206
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 19 deletions.
4 changes: 2 additions & 2 deletions cmd/aws_batch_exporter.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package main

import (
"github.com/atr0phy/aws_batch_exporter"
awsBatchExporter "github.com/atr0phy/aws_batch_exporter"
)

func main() {
awsBatchExporter.Run()
}
}
31 changes: 15 additions & 16 deletions collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ import (
)

type Collector struct {
client batchiface.BatchAPI
region string
client batchiface.BatchAPI
region string
timeout time.Duration
}

const (
namespace = "aws_batch"
timeout = 10 * time.Second
timeout = 10 * time.Second
)

var (
Expand Down Expand Up @@ -69,7 +69,7 @@ var (
prometheus.BuildFQName(namespace, "", "failed_job"),
"Job in the queue that are in the FAILED state",
[]string{"region", "id", "queue", "name"}, nil,
)
)

jobSucceeded = prometheus.NewDesc(
prometheus.BuildFQName(namespace, "", "succeeded_job"),
Expand All @@ -79,20 +79,19 @@ var (

jobDescMap = map[string]*prometheus.Desc{
batch.JobStatusSubmitted: jobSubmitted,
batch.JobStatusPending: jobPending,
batch.JobStatusRunnable: jobRunnable,
batch.JobStatusStarting: jobStarting,
batch.JobStatusRunning: jobRunning,
batch.JobStatusFailed: jobFailed,
batch.JobStatusPending: jobPending,
batch.JobStatusRunnable: jobRunnable,
batch.JobStatusStarting: jobStarting,
batch.JobStatusRunning: jobRunning,
batch.JobStatusFailed: jobFailed,
batch.JobStatusSucceeded: jobSucceeded,
}

)

type JobResult struct {
id string
queue string
name string
id string
queue string
name string
status string
}

Expand All @@ -103,8 +102,8 @@ func New(region string) (*Collector, error) {
}

return &Collector{
client: batch.New(s),
region: "ap-northeast-1",
client: batch.New(s),
region: region,
timeout: timeout,
}, nil
}
Expand Down Expand Up @@ -134,7 +133,7 @@ func (c *Collector) Collect(ch chan<- prometheus.Metric) {
defer wg.Done()
var results []JobResult
for _, s := range jobStatus {
r, err := c.client.ListJobsWithContext(ctx, &batch.ListJobsInput{JobQueue: d.JobQueueName,JobStatus: &s})
r, err := c.client.ListJobsWithContext(ctx, &batch.ListJobsInput{JobQueue: d.JobQueueName, JobStatus: &s})
if err != nil {
log.Printf("Error collecting job status metrics: %v\n", err)
continue
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ func Run() {
prometheus.MustRegister(collector)
http.Handle("/metrics", promhttp.Handler())
log.Fatal(http.ListenAndServe(addr, nil))
}
}

0 comments on commit f848206

Please sign in to comment.