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

Fix AWS Environment Hardcode #6

Merged
merged 2 commits into from
Dec 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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))
}
}