Skip to content

Commit

Permalink
Add hotswaps and fully-downloaded cores (#3)
Browse files Browse the repository at this point in the history
* (WIP) Expose hotswaps

* Add hypercore_total_fully_downloaded_cores

* Default 0 hotswaps (if it doesn't exist)

* hypercore 10.38.0
  • Loading branch information
HDegroote authored Nov 18, 2024
1 parent 4708b0a commit 35712ae
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
27 changes: 27 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ class HypercoreStats {
return this._getStats().totalCores
}

get totalFullyDownloadedCores () {
return this._getStats().fullyDownloadedCores
}

getTotalLength () {
return this._getStats().totalLength
}
Expand Down Expand Up @@ -137,6 +141,10 @@ class HypercoreStats {
return this._getStats().totalWireExtensionTransmitted
}

get totalHotswaps () {
return this._getStats().totalHotswaps
}

// Caches the result for this._lastStatsCalcTime ms
_getStats () {
if (this._cachedStats && this._lastStatsCalcTime + this.cacheExpiryMs > Date.now()) {
Expand All @@ -162,6 +170,13 @@ class HypercoreStats {
this.set(self.totalCores)
}
})
new promClient.Gauge({ // eslint-disable-line no-new
name: 'hypercore_total_fully_downloaded_cores',
help: 'Total amount of fully downloaded hypercores (where its length equals its contiguous length)',
collect () {
this.set(self.totalFullyDownloadedCores)
}
})

new promClient.Gauge({ // eslint-disable-line no-new
name: 'hypercore_total_length',
Expand Down Expand Up @@ -343,6 +358,13 @@ class HypercoreStats {
this.set(self.totalWireExtensionTransmitted)
}
})
new promClient.Gauge({ // eslint-disable-line no-new
name: 'hypercore_total_hotswaps',
help: 'Total amount of hotswaps scheduled',
collect () {
this.set(self.totalHotswaps)
}
})
}

static fromCorestore (store) {
Expand Down Expand Up @@ -373,6 +395,7 @@ class HypercoreStats {
class HypercoreStatsSnapshot {
constructor (cores) {
this.cores = cores
this.fullyDownloadedCores = 0

this._totalPeersConns = new Set()
this._totalPeerCoreCombos = 0
Expand All @@ -393,6 +416,7 @@ class HypercoreStatsSnapshot {
this.totalWireRangeTransmitted = 0
this.totalWireExtensionReceived = 0
this.totalWireExtensionTransmitted = 0
this.totalHotswaps = 0

this.totalCores = 0
this.totalLength = 0
Expand Down Expand Up @@ -422,6 +446,8 @@ class HypercoreStatsSnapshot {

for (const core of this.cores) {
this.totalLength += core.length
if (core.length === core.contiguousLength) this.fullyDownloadedCores++

// this.totalBlocksUploaded += core.stats.blocksUploaded
// this.totalBlocksDownloaded += core.stats.blocksDownloaded
// this.totalBytesUploaded += core.stats.bytesUploaded
Expand All @@ -444,6 +470,7 @@ class HypercoreStatsSnapshot {
this.totalWireRangeTransmitted += core.replicator.stats.wireRange.tx
this.totalWireExtensionReceived += core.replicator.stats.wireExtension.rx
this.totalWireExtensionTransmitted += core.replicator.stats.wireExtension.tx
this.totalHotswaps += core.replicator.stats.hotswaps || 0
}

for (const peer of core.peers) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"devDependencies": {
"brittle": "^3.6.1",
"corestore": "^6.18.4",
"hypercore": "^10.37.19",
"hypercore": "^10.38.0",
"hyperdht": "^6.16.5",
"hyperswarm": "^4.8.2",
"prom-client": "^15.1.3",
Expand Down

0 comments on commit 35712ae

Please sign in to comment.