Skip to content

Commit

Permalink
fix: hostd metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
alexfreska committed Aug 28, 2024
1 parent 6bb9322 commit d6eed36
Show file tree
Hide file tree
Showing 9 changed files with 92 additions and 36 deletions.
5 changes: 5 additions & 0 deletions .changeset/shiny-onions-unite.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'hostd': minor
---

The contracts metrics now show active, rejected, failed, renewed, finalized, and successful.
7 changes: 7 additions & 0 deletions .changeset/spicy-boats-sneeze.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@siafoundation/hostd-types': minor
'@siafoundation/hostd-js': minor
'@siafoundation/hostd-react': minor
---

The metrics API types now include all available fields.
7 changes: 7 additions & 0 deletions .changeset/sweet-meals-flash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@siafoundation/hostd-types': minor
'@siafoundation/hostd-js': minor
'@siafoundation/hostd-react': minor
---

The metrics APIs now include wallet with balance and immatureBalance. Closes https://github.com/SiaFoundation/hostd/issues/450
10 changes: 10 additions & 0 deletions apps/hostd/components/Home/HomeContracts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ export function HomeContracts() {
isLoading={contracts.isLoading}
enabledModes={['latest', 'average']}
/>
<DatumCardConfigurable
category="contracts"
label="Renewed contracts"
color={contracts.config.data['renewed'].color}
value={contracts.stats['renewed']}
valueFormat={(v) => v.toFixed(0)}
defaultMode="latest"
isLoading={contracts.isLoading}
enabledModes={['latest', 'average']}
/>
<DatumCardConfigurable
category="contracts"
label="Failed contracts"
Expand Down
16 changes: 9 additions & 7 deletions apps/hostd/config/charts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,26 @@ import { colors } from '@siafoundation/design-system'

export const chartConfigs = {
// states
successful: {
color: colors.green[600],
},
active: {
color: colors.amber[600],
// pattern: true,
},
pending: {
color: colors.amber[600],
pattern: true,
},
rejected: {
color: colors.red[600],
// pattern: true,
},
failed: {
color: colors.red[600],
},
renewed: {
color: colors.blue[600],
},
finalized: {
color: colors.yellow[600],
},
successful: {
color: colors.green[600],
},
// potential: {
// color: colors.amber[600],
// pattern: true,
Expand Down
28 changes: 22 additions & 6 deletions apps/hostd/contexts/metrics/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -381,9 +381,10 @@ function useMetricsMain() {
metricsPeriod.data
?.map((m) => ({
active: m.contracts.active,
failed: m.contracts.failed,
pending: m.contracts.pending,
rejected: m.contracts.rejected,
failed: m.contracts.failed,
renewed: m.contracts.renewed,
finalized: m.contracts.finalized,
successful: m.contracts.successful,
timestamp: new Date(m.timestamp).getTime(),
}))
Expand All @@ -395,13 +396,28 @@ function useMetricsMain() {
data,
stats,
config: {
enabledGraph: ['successful', 'active', 'pending', 'rejected', 'failed'],
enabledTip: ['successful', 'active', 'pending', 'rejected', 'failed'],
enabledGraph: [
'active',
'rejected',
'failed',
'renewed',
'finalized',
'successful',
],
enabledTip: [
'active',
'rejected',
'failed',
'renewed',
'finalized',
'successful',
],
data: {
active: chartConfigs.active,
failed: chartConfigs.failed,
pending: chartConfigs.pending,
rejected: chartConfigs.rejected,
failed: chartConfigs.failed,
renewed: chartConfigs.renewed,
finalized: chartConfigs.finalized,
successful: chartConfigs.successful,
},
format: (v) => `${v} contracts`,
Expand Down
7 changes: 4 additions & 3 deletions apps/hostd/contexts/metrics/types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ export type PricingKeys =
| 'storage'

export type ContractsKeys =
| 'failed'
| 'rejected'
| 'pending'
| 'active'
| 'rejected'
| 'failed'
| 'renewed'
| 'finalized'
| 'successful'

export type StorageKeys =
Expand Down
2 changes: 1 addition & 1 deletion apps/hostd/contexts/transactions/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ function useTransactionsMain() {
(metrics.data || [])
.map((t) => {
return {
sc: Number(t.balance),
sc: Number(t.wallet.balance),
timestamp: new Date(t.timestamp).getTime(),
}
})
Expand Down
46 changes: 27 additions & 19 deletions libs/hostd-types/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,27 +231,25 @@ type Revenue = {
registryWrite: string
}

// Data is a collection of metrics related to data usage.
type Data = {
type DataRHPMetrics = {
// Ingress returns the number of bytes received by the host.
ingress: number
// Egress returns the number of bytes sent by the host.
egress: number
}

// Contracts is a collection of metrics related to contracts.
type Contracts = {
pending: number
type ContractMetrics = {
active: number
rejected: number
failed: number
renewed: number
finalized: number
successful: number
lockedCollateral: string
riskedCollateral: string
}

// Pricing is a collection of metrics related to the host's pricing settings.
type Pricing = {
type PricingMetrics = {
contractPrice: string
ingressPrice: string
egressPrice: string
Expand All @@ -261,44 +259,54 @@ type Pricing = {
collateralMultiplier: number
}

// Registry is a collection of metrics related to the host's registry.
type Registry = {
type RegistryMetrics = {
entries: number
maxEntries: number

reads: number
writes: number
}

// Storage is a collection of metrics related to storage.
type Storage = {
type StorageMetrics = {
totalSectors: number
physicalSectors: number
lostSectors: number
contractSectors: number
tempSectors: number
reads: number
writes: number
sectorCacheHits: number
sectorCacheMisses: number
}

// RevenueMetrics is a collection of metrics related to revenue.
type RevenueMetrics = {
potential: Revenue
earned: Revenue
}

// DataMetrics is a collection of metrics related to data usage.
type DataMetrics = {
rhp: Data
rhp: DataRHPMetrics
}

type AccountMetrics = {
active: number
balance: string
}

type WalletMetrics = {
balance: string
immatureBalance: string
}

export type Metrics = {
accounts: AccountMetrics
revenue: RevenueMetrics
pricing: Pricing
contracts: Contracts
storage: Storage
registry: Registry
pricing: PricingMetrics
contracts: ContractMetrics
storage: StorageMetrics
registry: RegistryMetrics
data: DataMetrics
balance: string
wallet: WalletMetrics
timestamp: string
}

Expand Down

0 comments on commit d6eed36

Please sign in to comment.