mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-31 04:23:40 +00:00
chore: fix comments
This commit is contained in:
19
web/projects/ui/src/app/services/metrics.service.ts
Normal file
19
web/projects/ui/src/app/services/metrics.service.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import { inject, Injectable } from '@angular/core'
|
||||
import { Observable, retry, shareReplay } from 'rxjs'
|
||||
import { Metrics } from 'src/app/services/api/api.types'
|
||||
import { ApiService } from 'src/app/services/api/embassy-api.service'
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class MetricsService extends Observable<Metrics> {
|
||||
private readonly metrics$ = inject(ApiService)
|
||||
.openMetricsWebsocket$({
|
||||
url: '',
|
||||
})
|
||||
.pipe(retry(), shareReplay(1))
|
||||
|
||||
constructor() {
|
||||
super(subscriber => this.metrics$.subscribe(subscriber))
|
||||
}
|
||||
}
|
||||
52
web/projects/ui/src/app/services/time.service.ts
Normal file
52
web/projects/ui/src/app/services/time.service.ts
Normal file
@@ -0,0 +1,52 @@
|
||||
import { inject, Injectable } from '@angular/core'
|
||||
import { PatchDB } from 'patch-db-client'
|
||||
import {
|
||||
combineLatest,
|
||||
defer,
|
||||
map,
|
||||
shareReplay,
|
||||
startWith,
|
||||
switchMap,
|
||||
timer,
|
||||
} from 'rxjs'
|
||||
import { ApiService } from 'src/app/services/api/embassy-api.service'
|
||||
import { DataModel } from 'src/app/services/patch-db/data-model'
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class TimeService {
|
||||
private readonly patch = inject(PatchDB<DataModel>)
|
||||
private readonly time$ = defer(() =>
|
||||
inject(ApiService).getSystemTime({}),
|
||||
).pipe(
|
||||
switchMap(({ now, uptime }) =>
|
||||
timer(0, 1000).pipe(
|
||||
map(index => ({
|
||||
now: new Date(now).valueOf() + 1000 * index,
|
||||
uptime: uptime + index,
|
||||
})),
|
||||
),
|
||||
),
|
||||
shareReplay(1),
|
||||
)
|
||||
|
||||
readonly now$ = combineLatest([
|
||||
this.time$,
|
||||
this.patch.watch$('serverInfo', 'ntpSynced'),
|
||||
]).pipe(map(([{ now }, synced]) => ({ now, synced })))
|
||||
|
||||
readonly uptime$ = this.time$.pipe(
|
||||
map(({ uptime }) => {
|
||||
const days = Math.floor(uptime / (24 * 60 * 60))
|
||||
const daysSec = uptime % (24 * 60 * 60)
|
||||
const hours = Math.floor(daysSec / (60 * 60))
|
||||
const hoursSec = uptime % (60 * 60)
|
||||
const minutes = Math.floor(hoursSec / 60)
|
||||
const seconds = uptime % 60
|
||||
|
||||
return `${days}:${hours}:${minutes}:${seconds}`
|
||||
}),
|
||||
startWith('-:-:-:-'),
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user