Skip to content
Open
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
20 changes: 19 additions & 1 deletion webapp/backend/pkg/database/scrutiny_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const (
// 60seconds * 60minutes * 24hours * 7 days * (52 + 52 + 4)weeks
RETENTION_PERIOD_25_MONTHS_IN_SECONDS = 65_318_400

DURATION_KEY_DAY = "day"
DURATION_KEY_WEEK = "week"
DURATION_KEY_MONTH = "month"
DURATION_KEY_YEAR = "year"
Expand Down Expand Up @@ -445,6 +446,7 @@ func (sr *scrutinyRepository) GetSummary(ctx context.Context) (map[string]*model

func (sr *scrutinyRepository) lookupBucketName(durationKey string) string {
switch durationKey {
case DURATION_KEY_DAY:
case DURATION_KEY_WEEK:
//data stored in the last week
return sr.appConfig.GetString("web.influxdb.bucket")
Expand All @@ -462,8 +464,10 @@ func (sr *scrutinyRepository) lookupBucketName(durationKey string) string {
}

func (sr *scrutinyRepository) lookupDuration(durationKey string) []string {

switch durationKey {
case DURATION_KEY_DAY:
//data stored in the last day
return []string{"-1d", "now()"}
case DURATION_KEY_WEEK:
//data stored in the last week
return []string{"-1w", "now()"}
Expand All @@ -480,8 +484,22 @@ func (sr *scrutinyRepository) lookupDuration(durationKey string) []string {
return []string{"-1w", "now()"}
}

func (sr *scrutinyRepository) lookupResolution(durationKey string) string {
switch durationKey {
case DURATION_KEY_DAY:
// Return data with higher resolution for daily summaries
return "10m"
default:
// Return data with 1h resolution for other summaries
return "1h"
}
}

func (sr *scrutinyRepository) lookupNestedDurationKeys(durationKey string) []string {
switch durationKey {
case DURATION_KEY_DAY:
//all data is stored in a single bucket, but we want a finer resolution
return []string{DURATION_KEY_DAY}
case DURATION_KEY_WEEK:
//all data is stored in a single bucket
return []string{DURATION_KEY_WEEK}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,14 @@ func (sr *scrutinyRepository) aggregateTempQuery(durationKey string) string {
for _, nestedDurationKey := range nestedDurationKeys {
bucketName := sr.lookupBucketName(nestedDurationKey)
durationRange := sr.lookupDuration(nestedDurationKey)
durationResolution := sr.lookupResolution(nestedDurationKey)

subQueryNames = append(subQueryNames, fmt.Sprintf(`%sData`, nestedDurationKey))
partialQueryStr = append(partialQueryStr, []string{
fmt.Sprintf(`%sData = from(bucket: "%s")`, nestedDurationKey, bucketName),
fmt.Sprintf(`|> range(start: %s, stop: %s)`, durationRange[0], durationRange[1]),
`|> filter(fn: (r) => r["_measurement"] == "temp" )`,
`|> aggregateWindow(every: 1h, fn: mean, createEmpty: false)`,
fmt.Sprintf(`|> aggregateWindow(every: %s, fn: mean, createEmpty: false)`, durationResolution),
`|> group(columns: ["device_wwn"])`,
`|> toInt()`,
"",
Expand All @@ -167,5 +168,6 @@ func (sr *scrutinyRepository) aggregateTempQuery(durationKey string) string {
}...)
}


return strings.Join(partialQueryStr, "\n")
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ <h3 class="ml-4" *ngIf="hostId.key">{{ hostId.key }}</h3>
<button (click)="changeSummaryTempDuration('year')" mat-menu-item>year</button>
<button (click)="changeSummaryTempDuration('month')" mat-menu-item>month</button>
<button (click)="changeSummaryTempDuration('week')" mat-menu-item>week</button>
<button (click)="changeSummaryTempDuration('day')" mat-menu-item>day</button>
</mat-menu>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,11 +269,11 @@ export class DashboardComponent implements OnInit, AfterViewInit, OnDestroy
}

/*

DURATION_KEY_DAY = "day"
DURATION_KEY_WEEK = "week"
DURATION_KEY_MONTH = "month"
DURATION_KEY_YEAR = "year"
DURATION_KEY_FOREVER = "forever"
DURATION_KEY_MONTH = "month"
DURATION_KEY_YEAR = "year"
DURATION_KEY_FOREVER = "forever"
*/

changeSummaryTempDuration(durationKey: string): void {
Expand Down