'API for TPS and other cluster stats?
Is there any API that I can call to get the current cluster stats for mainnet or any cluster in fact?
I saw on the Solana Explorer source code that they are calculating it manually, but I was kinda hoping there would be an API as well?
https://github.com/solana-labs/solana/blob/master/explorer/src/components/TpsCard.tsx
Solution 1:[1]
In your case you'll want https://docs.solana.com/developing/clients/jsonrpc-api#getrecentperformancesamples, and you can even see how it's being used in the Solana Explorer.
With curl, you can do:
curl http://localhost:8899 -X POST -H "Content-Type: application/json" -d '
{"jsonrpc":"2.0", "id":1, "method":"getRecentPerformanceSamples", "params": [1]}
'
Which gives:
{
"jsonrpc": "2.0",
"result": [
{
"numSlots": 126,
"numTransactions": 126,
"samplePeriodSecs": 60,
"slot": 348125
}
}
Then you can figure out TPS by doing numTransactions / samplePeriodSecs.
Reference code at https://github.com/solana-labs/solana/blob/6d1b6bdd7cff9a4404d00811825493ed5ac1b074/explorer/src/providers/stats/solanaClusterStats.tsx#L105
Solution 2:[2]
There's no API endpoint for getting Solana cluster stats such as TPS today.
You can calculate it be using getBlock and using the list of transactions over time to get TPS.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Jon C |
| Solution 2 | Jacob Creech |
