Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: hostd metrics #697

Merged
merged 1 commit into from
Aug 28, 2024
Merged
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
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',
alexfreska marked this conversation as resolved.
Show resolved Hide resolved
'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
Loading