Skip to content

Commit

Permalink
Add a metric that measures s3 list duration (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
ribbybibby authored Oct 22, 2020
1 parent 4ecf1c1 commit 44d5e40
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ Flags can also be set as environment variables, prefixed by `S3_EXPORTER_`. For
| s3_biggest_object_size_bytes | The size of the largest object. | bucket, prefix |
| s3_last_modified_object_date | The modification date of the most recently modified object. | bucket, prefix |
| s3_last_modified_object_size_bytes | The size of the object that was modified most recently. | bucket, prefix |
| s3_list_duration_seconds | The duration of the ListObjects operation | bucket, prefix |
| s3_list_success | Did the ListObjects operation complete successfully? | bucket, prefix |
| s3_objects_size_sum_bytes | The sum of the size of all the objects. | bucket, prefix |
| s3_objects | The total number of objects. | bucket, prefix |
Expand Down
11 changes: 11 additions & 0 deletions s3_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ var (
"If the ListObjects operation was a success",
[]string{"bucket", "prefix"}, nil,
)
s3ListDuration = prometheus.NewDesc(
prometheus.BuildFQName(namespace, "", "list_duration_seconds"),
"The total duration of the list operation",
[]string{"bucket", "prefix"}, nil,
)
s3LastModifiedObjectDate = prometheus.NewDesc(
prometheus.BuildFQName(namespace, "", "last_modified_object_date"),
"The last modified date of the object that was modified most recently",
Expand Down Expand Up @@ -64,6 +69,7 @@ type Exporter struct {
// Describe all the metrics we export
func (e *Exporter) Describe(ch chan<- *prometheus.Desc) {
ch <- s3ListSuccess
ch <- s3ListDuration
ch <- s3LastModifiedObjectDate
ch <- s3LastModifiedObjectSize
ch <- s3ObjectTotal
Expand All @@ -85,6 +91,7 @@ func (e *Exporter) Collect(ch chan<- prometheus.Metric) {
}

// Continue making requests until we've listed and compared the date of every object
startList := time.Now()
truncated := true
for truncated {
resp, err := e.svc.ListObjectsV2(query)
Expand All @@ -109,10 +116,14 @@ func (e *Exporter) Collect(ch chan<- prometheus.Metric) {
query.ContinuationToken = resp.NextContinuationToken
truncated = *resp.IsTruncated
}
listDuration := time.Now().Sub(startList).Seconds()

ch <- prometheus.MustNewConstMetric(
s3ListSuccess, prometheus.GaugeValue, 1, e.bucket, e.prefix,
)
ch <- prometheus.MustNewConstMetric(
s3ListDuration, prometheus.GaugeValue, listDuration, e.bucket, e.prefix,
)
ch <- prometheus.MustNewConstMetric(
s3LastModifiedObjectDate, prometheus.GaugeValue, float64(lastModified.UnixNano()/1e9), e.bucket, e.prefix,
)
Expand Down

0 comments on commit 44d5e40

Please sign in to comment.