Skip to content

Commit

Permalink
Add gas prices to grafana (#7935)
Browse files Browse the repository at this point in the history
  • Loading branch information
benaadams authored Dec 19, 2024
1 parent fbb9d0d commit 05c4a61
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 17 deletions.
82 changes: 72 additions & 10 deletions src/Nethermind/Nethermind.Evm/Metrics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,17 +141,79 @@ public class Metrics
public static long ThreadLocalContractsAnalysed => _contractsAnalysed.ThreadLocalValue;
public static void IncrementContractsAnalysed() => _contractsAnalysed.Increment();

internal static long Transactions { get; set; }
internal static float AveGasPrice { get; set; }
internal static float MinGasPrice { get; set; } = float.MaxValue;
internal static float MaxGasPrice { get; set; }
internal static float EstMedianGasPrice { get; set; }

internal static long BlockTransactions { get; set; }
internal static float BlockAveGasPrice { get; set; }
internal static float BlockMinGasPrice { get; set; } = float.MaxValue;
internal static float BlockMaxGasPrice { get; set; }
internal static float BlockEstMedianGasPrice { get; set; }

private static float _blockAveGasPrice;
internal static float BlockAveGasPrice
{
get => _blockAveGasPrice;
set
{
_blockAveGasPrice = value;
if (value != 0)
{
GasPriceAve = value;
}
}
}

private static float _blockMinGasPrice = float.MaxValue;
internal static float BlockMinGasPrice
{
get => _blockMinGasPrice;
set
{
_blockMinGasPrice = value;
if (_blockMinGasPrice != float.MaxValue)
{
GasPriceMin = value;
}
}
}

private static float _blockMaxGasPrice;
internal static float BlockMaxGasPrice
{
get => _blockMaxGasPrice;
set
{
_blockMaxGasPrice = value;
if (value != 0)
{
GasPriceMax = value;
}
}
}

private static float _blockEstMedianGasPrice;
internal static float BlockEstMedianGasPrice
{
get => _blockEstMedianGasPrice;
set
{
_blockEstMedianGasPrice = value;
if (value != 0)
{
GasPriceMedian = value;
}
}
}

[GaugeMetric]
[Description("Minimum tx gas price in block")]
public static float GasPriceMin { get; private set; }

[GaugeMetric]
[Description("Median tx gas price in block")]
public static float GasPriceMedian { get; private set; }

[GaugeMetric]
[Description("Mean tx gas price in block")]
public static float GasPriceAve { get; private set; }

[GaugeMetric]
[Description("Maximum tx gas price in block")]
public static float GasPriceMax { get; private set; }

public static void ResetBlockStats()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,16 +317,9 @@ private static void UpdateMetrics(ExecutionOptions opts, UInt256 effectiveGasPri
{
float gasPrice = (float)((double)effectiveGasPrice / 1_000_000_000.0);

Metrics.MinGasPrice = Math.Min(gasPrice, Metrics.MinGasPrice);
Metrics.MaxGasPrice = Math.Max(gasPrice, Metrics.MaxGasPrice);

Metrics.BlockMinGasPrice = Math.Min(gasPrice, Metrics.BlockMinGasPrice);
Metrics.BlockMaxGasPrice = Math.Max(gasPrice, Metrics.BlockMaxGasPrice);

Metrics.AveGasPrice = (Metrics.AveGasPrice * Metrics.Transactions + gasPrice) / (Metrics.Transactions + 1);
Metrics.EstMedianGasPrice += Metrics.AveGasPrice * 0.01f * float.Sign(gasPrice - Metrics.EstMedianGasPrice);
Metrics.Transactions++;

Metrics.BlockAveGasPrice = (Metrics.BlockAveGasPrice * Metrics.BlockTransactions + gasPrice) / (Metrics.BlockTransactions + 1);
Metrics.BlockEstMedianGasPrice += Metrics.BlockAveGasPrice * 0.01f * float.Sign(gasPrice - Metrics.BlockEstMedianGasPrice);
Metrics.BlockTransactions++;
Expand Down

0 comments on commit 05c4a61

Please sign in to comment.