Skip to content

Commit

Permalink
Merge pull request #91 from MohawkTSDB/add-min-max-to-mem-storage
Browse files Browse the repository at this point in the history
add min max stat to mem endpoint
  • Loading branch information
yaacov authored Dec 24, 2017
2 parents 4596a6c + 38b7a44 commit 935f5bb
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/storage/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,6 @@ For a starting template of a storage plugin, look at the [storage example](/stor
| Plugin | Min | Max| First | Last | Avg | Median | Std | Sum | Count |
|------------------|-----|----|-------|------|-----|--------|-----|-----|-------|
| Example | | | | | ✔️ | | | | ✔️ |
| Memory | | | | ✔️ | ✔️ | | | ✔️ | ✔️ |
| Memory | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | | | ✔️ | ✔️ |
| Sqlite | ✔️ | ✔️ | | | ✔️ | | | ✔️ | ✔️ |
| Mongo | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | | | ✔️ | ✔️ |
23 changes: 23 additions & 0 deletions src/storage/memory/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,13 +199,33 @@ func (r Storage) GetStatData(tenant string, id string, end int64, start int64, l
for b := pEnd; count < limit && b > pStart && startTimestamp >= stepMillisec; b -= pStep {
samples := int64(0)
sum := float64(0)
first := float64(0)
last := float64(0)
min := float64(0)
max := float64(0)

// loop on all points in bucket
for i := (b - pStep); i < b; i++ {
d := r.tenant[tenant].ts[id].data[i%arraySize]
if d.timeStamp <= end && d.timeStamp > start {
samples++

// calculate bucket stat values
if samples == 1 {
// first sample
first = d.value
min = first
max = first
} else {
// all samples except first sample
if min > d.value {
min = d.value
}
if max < d.value {
max = d.value
}
}

last = d.value
sum += d.value
}
Expand All @@ -222,7 +242,10 @@ func (r Storage) GetStatData(tenant string, id string, end int64, start int64, l
End: startTimestamp + stepMillisec,
Empty: false,
Samples: samples,
First: first,
Last: last,
Min: min,
Max: max,
Avg: sum / float64(samples),
Sum: sum,
})
Expand Down

0 comments on commit 935f5bb

Please sign in to comment.