Skip to content

Commit

Permalink
Merge pull request #67 from buildkite/expose-org-slug-as-cloudwatch-d…
Browse files Browse the repository at this point in the history
…imension

Expose org slug as a cloudwatch dimension
  • Loading branch information
lox authored Jan 2, 2019
2 parents 65fb162 + 1171638 commit 49b8eba
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
7 changes: 4 additions & 3 deletions backend/cloudwatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,10 @@ func (cb *CloudWatchBackend) Collect(r *collector.Result) error {
})
}

dimensions = append(dimensions, &cloudwatch.Dimension{
Name: aws.String("Queue"), Value: aws.String(name),
})
dimensions = append(dimensions,
&cloudwatch.Dimension{Name: aws.String("Queue"), Value: aws.String(name)},
&cloudwatch.Dimension{Name: aws.String("Org"), Value: aws.String(r.Org)},
)

metrics = append(metrics, cloudwatchMetrics(c, dimensions)...)
}
Expand Down
17 changes: 13 additions & 4 deletions collector/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type Collector struct {
type Result struct {
Totals map[string]int
Queues map[string]map[string]int
Org string
}

type metricsAgentsResponse struct {
Expand Down Expand Up @@ -61,9 +62,14 @@ type allMetricsJobsResponse struct {
Queues map[string]metricsJobsResponse `json:"queues"`
}

type allMetricsOrganizationResponse struct {
Slug string `json:"slug"`
}

type allMetricsResponse struct {
Agents allMetricsAgentsResponse `json:"agents"`
Jobs allMetricsJobsResponse `json:"jobs"`
Agents allMetricsAgentsResponse `json:"agents"`
Jobs allMetricsJobsResponse `json:"jobs"`
Organization allMetricsOrganizationResponse `json:"organization"`
}

func (c *Collector) Collect() (*Result, error) {
Expand Down Expand Up @@ -118,6 +124,9 @@ func (c *Collector) Collect() (*Result, error) {
return nil, err
}

log.Printf("Found organization %q", allMetrics.Organization.Slug)
result.Org = allMetrics.Organization.Slug

result.Totals[ScheduledJobsCount] = allMetrics.Jobs.Scheduled
result.Totals[RunningJobsCount] = allMetrics.Jobs.Running
result.Totals[UnfinishedJobsCount] = allMetrics.Jobs.Total
Expand Down Expand Up @@ -204,12 +213,12 @@ func (c *Collector) Collect() (*Result, error) {

func (r Result) Dump() {
for name, c := range r.Totals {
log.Printf("Buildkite > %s = %d", name, c)
log.Printf("Buildkite > Org=%s > %s=%d", r.Org, name, c)
}

for name, c := range r.Queues {
for k, v := range c {
log.Printf("Buildkite > [queue = %s] > %s = %d", name, k, v)
log.Printf("Buildkite > Org=%s > Queue=%s > %s=%d", r.Org, name, k, v)
}
}
}

0 comments on commit 49b8eba

Please sign in to comment.