Skip to content

Commit

Permalink
feat(explorer): use explored for host metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
telestrial committed Dec 16, 2024
1 parent 7a93acf commit c78b0e9
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 26 deletions.
5 changes: 5 additions & 0 deletions .changeset/spotty-moons-vanish.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'explorer': minor
---

Use explored for host metrics.
26 changes: 20 additions & 6 deletions apps/explorer/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { humanBytes } from '@siafoundation/units'
import { getLatestBlocks } from '../lib/blocks'
import { siaCentral } from '../config/siaCentral'
import { to } from '@siafoundation/request'
import { explored } from '../config/explored'

export function generateMetadata(): Metadata {
const title = 'siascan'
Expand All @@ -24,11 +25,11 @@ export const revalidate = 0

export default async function HomePage() {
const [
[metrics, metricsError],
[exchangeRates, exchangeRatesError],
[hosts, hostsError],
[hostMetrics, hostMetricsError],
[blockMetrics, blockMetricsError],
] = await Promise.all([
to(siaCentral.hostsNetworkMetrics()),
to(
siaCentral.exchangeRates({
params: { currencies: 'sc' },
Expand All @@ -41,38 +42,51 @@ export default async function HomePage() {
},
})
),
to(explored.hostMetrics()),
to(explored.blockMetrics()),
])

const [latestBlocks, latestBlocksError] = await getLatestBlocks()
const latestHeight = latestBlocks ? latestBlocks[0].height : 0

if (metricsError || latestBlocksError || exchangeRatesError || hostsError) {
if (
latestBlocksError ||
exchangeRatesError ||
hostsError ||
hostMetricsError ||
blockMetricsError
) {
console.log(new Date().toISOString(), {
metricsError,
latestBlocksError,
exchangeRatesError,
hostsError,
})
}

console.log(new Date().toISOString(), {
metrics: humanBytes(Buffer.byteLength(JSON.stringify(metrics || ''))),
latestBlocks: humanBytes(
Buffer.byteLength(JSON.stringify(latestBlocks || ''))
),
exchangeRates: humanBytes(
Buffer.byteLength(JSON.stringify(exchangeRates || ''))
),
hosts: humanBytes(Buffer.byteLength(JSON.stringify(hosts || ''))),
hostMetrics: humanBytes(
Buffer.byteLength(JSON.stringify(hostMetrics || ''))
),
blockMetrics: humanBytes(
Buffer.byteLength(JSON.stringify(blockMetrics || ''))
),
})

return (
<Home
metrics={metrics}
metrics={hostMetrics}
blockHeight={latestHeight}
blocks={latestBlocks || []}
hosts={hosts?.hosts || []}
rates={exchangeRates?.rates}
totalHosts={blockMetrics?.totalHosts}
/>
)
}
37 changes: 17 additions & 20 deletions apps/explorer/components/Home/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { reverse, sortBy } from '@technically/lodash'
import {
SiaCentralExchangeRates,
SiaCentralHost,
SiaCentralHostsNetworkMetricsResponse,
} from '@siafoundation/sia-central-types'
import { hashToAvatar } from '../../lib/avatar'
import {
Expand All @@ -26,20 +25,22 @@ import {
import { HostListItem } from './HostListItem'
import { useExchangeRate } from '../../hooks/useExchangeRate'
import { SiaCentralHostScanned } from '../Host/types'
import { ExplorerBlock } from '@siafoundation/explored-types'
import { ExplorerBlock, HostMetrics } from '@siafoundation/explored-types'

export function Home({
metrics,
blockHeight,
blocks,
hosts,
rates,
totalHosts,
}: {
metrics?: SiaCentralHostsNetworkMetricsResponse
metrics?: HostMetrics
blockHeight: number
blocks: ExplorerBlock[]
hosts: SiaCentralHost[]
rates?: SiaCentralExchangeRates
totalHosts?: number
}) {
const exchange = useExchangeRate(rates)
const values = useMemo(() => {
Expand Down Expand Up @@ -67,8 +68,7 @@ export function Home({
<div className="flex flex-col gap-1 items-baseline">
<Tooltip
content={`${humanBytes(
metrics?.totals.total_storage -
metrics?.totals.remaining_storage
metrics?.totalStorage - metrics?.remainingStorage
)} used storage`}
>
<Text
Expand All @@ -77,18 +77,15 @@ export function Home({
color="contrast"
>
{humanBytes(
metrics?.totals.total_storage -
metrics?.totals.remaining_storage
metrics?.totalStorage - metrics?.remainingStorage
)}
</Text>
</Tooltip>
<Tooltip
content={`${humanBytes(
metrics?.totals.total_storage
)} total storage`}
content={`${humanBytes(metrics?.totalStorage)} total storage`}
>
<Text scaleSize="20" color="subtle">
{humanBytes(metrics?.totals.total_storage)}
{humanBytes(metrics?.totalStorage)}
</Text>
</Tooltip>
</div>
Expand All @@ -104,12 +101,12 @@ export function Home({
weight="semibold"
color="contrast"
>
{humanNumber(metrics?.totals.active_hosts)}
{humanNumber(metrics?.activeHosts)}
</Text>
</Tooltip>
<Tooltip content="Total hosts">
<Text scaleSize="20" color="subtle">
{humanNumber(metrics?.totals.total_hosts)}
{humanNumber(totalHosts)}
</Text>
</Tooltip>
</div>
Expand All @@ -126,13 +123,13 @@ export function Home({
color="contrast"
>
{getStorageCost({
price: metrics?.average.settings.storage_price,
price: metrics?.settings.storageprice,
exchange,
})}
</Text>
<Text color="subtle">
{getStorageCost({
price: metrics?.average.settings.storage_price,
price: metrics?.settings.storageprice,
})}
</Text>
</div>
Expand All @@ -150,13 +147,13 @@ export function Home({
color="contrast"
>
{getDownloadCost({
price: metrics?.average.settings.download_price,
price: metrics?.priceTable.downloadbandwidthcost,
exchange,
})}
</Text>
<Text color="subtle">
{getDownloadCost({
price: metrics?.average.settings.download_price,
price: metrics?.priceTable.downloadbandwidthcost,
})}
</Text>
</div>
Expand All @@ -174,13 +171,13 @@ export function Home({
color="contrast"
>
{getUploadCost({
price: metrics?.average.settings.upload_price,
price: metrics?.priceTable.uploadbandwidthcost,
exchange,
})}
</Text>
<Text color="subtle">
{getUploadCost({
price: metrics?.average.settings.upload_price,
price: metrics?.priceTable.uploadbandwidthcost,
})}
</Text>
</div>
Expand All @@ -190,7 +187,7 @@ export function Home({
)
}
return list
}, [metrics, blockHeight, exchange])
}, [metrics, blockHeight, exchange, totalHosts])

return (
<ContentLayout
Expand Down

0 comments on commit c78b0e9

Please sign in to comment.