Skip to content

Commit

Permalink
Log validation and prevalidation times for blocks to files
Browse files Browse the repository at this point in the history
  • Loading branch information
cmmarslender committed Dec 18, 2023
1 parent 647c0ce commit 0e6b775
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
7 changes: 7 additions & 0 deletions internal/metrics/fullnode.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,13 @@ func (s *FullNodeServiceMetrics) Block(resp *types.WebsocketResponse) {
s.preValidationTime.Set(block.PreValidationTime)
s.validationTime.Set(block.ValidationTime)

if err = utils.LogToFile("preValidationTime.log", fmt.Sprintf("%f", block.PreValidationTime)); err != nil {
log.Error(err.Error())
}
if err = utils.LogToFile("validationTime.log", fmt.Sprintf("%f", block.ValidationTime)); err != nil {
log.Error(err.Error())
}

if block.TransactionBlock {
s.blockCost.Set(float64(block.BlockCost.OrEmpty()))
s.blockFees.Set(float64(block.BlockFees.OrEmpty()))
Expand Down
26 changes: 26 additions & 0 deletions internal/utils/log.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package utils

import (
"os"

log "github.com/sirupsen/logrus"
)

// LogToFile logs a message to a given file
func LogToFile(filename, message string) error {
file, err := os.OpenFile(filename, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
return err
}
defer func(file *os.File) {
err := file.Close()
if err != nil {
log.Errorf("Error closing file: %s\n", err.Error())
}
}(file)

if _, err := file.WriteString(message + "\n"); err != nil {
return err
}
return nil
}

0 comments on commit 0e6b775

Please sign in to comment.