hyperswarm-stats 1.1.4 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +6 -0
  2. package/index.js +37 -0
  3. package/package.json +2 -2
package/README.md CHANGED
@@ -26,3 +26,9 @@ stats.registerPrometheusMetrics(promClient)
26
26
  const metrics = await promClient.register.metrics()
27
27
  console.log(metrics)
28
28
  ```
29
+
30
+ ## Usage Without Prometheus
31
+
32
+ `swarmStats.toString()` returns a string overview of all hyperswarm and DHT stats.
33
+
34
+ `swarmStats.toJson()` returns a JSON overview of all hyperswarm and DHT stats.
package/index.js CHANGED
@@ -127,6 +127,43 @@ class HyperswarmStats {
127
127
  return this.swarm.peers.size
128
128
  }
129
129
 
130
+ toJson () {
131
+ return {
132
+ dht: this.dhtStats.toJson(),
133
+ nrPeers: this.nrPeers,
134
+ connects: JSON.parse(JSON.stringify(this.connects)), // quick-and-dirty deep copy
135
+ bytesTransmittedOverSwarmStreams: this.getBytesTransmittedAcrossAllStreams(),
136
+ bytesReceivedOverSwarmStreams: this.getBytesReceivedAcrossAllStreams(),
137
+ packetsTransmittedOverSwarmStreams: this.getPacketsTransmittedAcrossAllStreams(),
138
+ packetsReceivedOverSwarmStreams: this.getPacketsReceivedAcrossAllStreams(),
139
+ avgCongestionWindow: this.getAvgCongestionWindow(),
140
+ avgMtu: this.getAvgMTU(),
141
+ retransmitsOverSwarmStreams: this.getRetransmitsAcrossAllStreams(),
142
+ fastRecoveriesOverSwarmStreams: this.getFastRecoveriesAcrossAllStreams(),
143
+ rtoCountOverSwarmStreams: this.getRTOCountAcrossAllStreams()
144
+ }
145
+ }
146
+
147
+ toString () {
148
+ return `Hyperswarm Stats
149
+ - hyperswarm_nr_peers: ${this.nrPeers}
150
+ - hyperswarm_client_connections_opened: ${this.connects.client.opened}
151
+ - hyperswarm_client_connections_closed: ${this.connects.client.closed}
152
+ - hyperswarm_client_connections_attempted: ${this.connects.client.attempted}
153
+ - hyperswarm_server_connections_opened: ${this.connects.server.opened}
154
+ - hyperswarm_server_connections_closed: ${this.connects.server.closed}
155
+ - hyperswarm_total_bytes_transmitted_over_swarm_streams: ${this.getBytesTransmittedAcrossAllStreams()}
156
+ - hyperswarm_total_bytes_received_over_swarm_streams: ${this.getBytesReceivedAcrossAllStreams()}
157
+ - hyperswarm_total_packets_transmitted_over_swarm_streams: ${this.getPacketsTransmittedAcrossAllStreams()}
158
+ - hyperswarm_total_packets_received_over_swarm_streams: ${this.getPacketsReceivedAcrossAllStreams()}
159
+ - hyperswarm_avg_congestion_window: ${this.getAvgCongestionWindow()}
160
+ - hyperswarm_avg_mtu: ${this.getAvgMTU()}
161
+ - hyperswarm_total_retransmits_over_swarm_streams: ${this.getRetransmitsAcrossAllStreams()}
162
+ - hyperswarm_total_fast_recoveries_over_swarm_streams: ${this.getFastRecoveriesAcrossAllStreams()}
163
+ - hyperswarm_total_rto_count_over_swarm_streams: ${this.getRTOCountAcrossAllStreams()}
164
+ ${this.dhtStats.toString()}`
165
+ }
166
+
130
167
  registerPrometheusMetrics (promClient) {
131
168
  this.dhtStats.registerPrometheusMetrics(promClient)
132
169
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hyperswarm-stats",
3
- "version": "1.1.4",
3
+ "version": "1.3.0",
4
4
  "description": "Hyperswarm stats with prometheus support",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -32,6 +32,6 @@
32
32
  "standard": "^17.1.0"
33
33
  },
34
34
  "dependencies": {
35
- "hyperdht-stats": "^1.0.0"
35
+ "hyperdht-stats": "^1.7.0"
36
36
  }
37
37
  }