Skip to content

Commit

Permalink
Add comment describing data. Do some type checking.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason Harvey committed Oct 27, 2015
1 parent 3284331 commit a1d48ba
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions cmd/scollector/collectors/google_analytics.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,24 @@ func c_google_analytics(clientid string, secret string, tokenstr string, sites [
offset = 1
}
time := time.Now().Add(time.Duration(-1*offset) * time.Minute).Unix()
pageviews := 0
// Iterates through the response data and returns the time slice we
// actually care about when we find it.
for _, v := range data.Rows {
minute, err := strconv.Atoi(v[0])
for _, row := range data.Rows {
// row == [2]string{"0", "123"}
// First item is the minute, second is the data (pageviews in this case)
minute, err := strconv.Atoi(row[0])
if err != nil {
return md, fmt.Errorf("Error parsing GA data: %s", err)
}
if minute == offset {
value = v[1]
if pageviews, err = strconv.Atoi(row[1]); err != nil {
return md, fmt.Errorf("Error parsing GA data: %s", err)
}
break
}
}
AddTS(&md, "google.analytics.realtime.pageviews", time, value, opentsdb.TagSet{"site": site.Name}, metadata.Gauge, metadata.Count, "Number of pageviews tracked by GA in one minute")
AddTS(&md, "google.analytics.realtime.pageviews", time, pageviews, opentsdb.TagSet{"site": site.Name}, metadata.Gauge, metadata.Count, "Number of pageviews tracked by GA in one minute")
}

return md, err
Expand Down

0 comments on commit a1d48ba

Please sign in to comment.