Skip to content
Snippets Groups Projects
Commit edce0044 authored by Hans Moog's avatar Hans Moog
Browse files

Feat: metrics plugin stub (for web based metrics)

parent 3a67ebb0
No related branches found
No related tags found
No related merge requests found
...@@ -9,6 +9,7 @@ import ( ...@@ -9,6 +9,7 @@ import (
"github.com/iotaledger/goshimmer/plugins/gossip" "github.com/iotaledger/goshimmer/plugins/gossip"
gossip_on_solidification "github.com/iotaledger/goshimmer/plugins/gossip-on-solidification" gossip_on_solidification "github.com/iotaledger/goshimmer/plugins/gossip-on-solidification"
"github.com/iotaledger/goshimmer/plugins/gracefulshutdown" "github.com/iotaledger/goshimmer/plugins/gracefulshutdown"
"github.com/iotaledger/goshimmer/plugins/metrics"
"github.com/iotaledger/goshimmer/plugins/statusscreen" "github.com/iotaledger/goshimmer/plugins/statusscreen"
statusscreen_tps "github.com/iotaledger/goshimmer/plugins/statusscreen-tps" statusscreen_tps "github.com/iotaledger/goshimmer/plugins/statusscreen-tps"
"github.com/iotaledger/goshimmer/plugins/tangle" "github.com/iotaledger/goshimmer/plugins/tangle"
...@@ -31,6 +32,7 @@ func main() { ...@@ -31,6 +32,7 @@ func main() {
gracefulshutdown.PLUGIN, gracefulshutdown.PLUGIN,
tipselection.PLUGIN, tipselection.PLUGIN,
zeromq.PLUGIN, zeromq.PLUGIN,
metrics.PLUGIN,
statusscreen.PLUGIN, statusscreen.PLUGIN,
statusscreen_tps.PLUGIN, statusscreen_tps.PLUGIN,
......
...@@ -4,12 +4,12 @@ import ( ...@@ -4,12 +4,12 @@ import (
"sync" "sync"
"testing" "testing"
"github.com/iotaledger/goshimmer/packages/ternary" "github.com/iotaledger/iota.go/trinary"
) )
func BenchmarkBatchHasher_Hash(b *testing.B) { func BenchmarkBatchHasher_Hash(b *testing.B) {
batchHasher := NewBatchHasher(243, 81) batchHasher := NewBatchHasher(243, 81)
tritsToHash := ternary.Trytes("A999999FF").ToTrits() tritsToHash := trinary.MustTrytesToTrits(trinary.Trytes("A999999FF"))
b.ResetTimer() b.ResetTimer()
......
...@@ -7,8 +7,8 @@ import ( ...@@ -7,8 +7,8 @@ import (
"github.com/iotaledger/goshimmer/packages/events" "github.com/iotaledger/goshimmer/packages/events"
"github.com/iotaledger/goshimmer/packages/model/bundle" "github.com/iotaledger/goshimmer/packages/model/bundle"
"github.com/iotaledger/goshimmer/packages/model/value_transaction" "github.com/iotaledger/goshimmer/packages/model/value_transaction"
"github.com/iotaledger/goshimmer/packages/ternary"
"github.com/iotaledger/goshimmer/plugins/tangle" "github.com/iotaledger/goshimmer/plugins/tangle"
"github.com/iotaledger/iota.go/trinary"
"github.com/magiconair/properties/assert" "github.com/magiconair/properties/assert"
) )
...@@ -35,7 +35,7 @@ func TestProcessSolidBundleHead(t *testing.T) { ...@@ -35,7 +35,7 @@ func TestProcessSolidBundleHead(t *testing.T) {
if err != nil { if err != nil {
t.Error(err) t.Error(err)
} else { } else {
assert.Equal(t, result.GetHash(), ternary.Trytes("UFWJYEWKMEQDNSQUCUWBGOFRHVBGHVVYEZCLCGRDTRQSMAFALTIPMJEEYFDPMQCNJWLXUWFMBZGHQRO99"), "invalid bundle hash") assert.Equal(t, result.GetHash(), trinary.Trytes("UFWJYEWKMEQDNSQUCUWBGOFRHVBGHVVYEZCLCGRDTRQSMAFALTIPMJEEYFDPMQCNJWLXUWFMBZGHQRO99"), "invalid bundle hash")
assert.Equal(t, result.IsValueBundle(), true, "invalid value bundle status") assert.Equal(t, result.IsValueBundle(), true, "invalid value bundle status")
} }
} }
package metrics
import (
"github.com/iotaledger/goshimmer/packages/events"
)
// define a struct with the available events
type pluginEvents struct {
ReceivedTPSUpdated *events.Event
}
// define a function that maps our event parameters to the correct type: uint64 (GO has no generics)
func uint64EventCaller(handler interface{}, params ...interface{}) {
handler.(func(uint64))(params[0].(uint64))
}
// expose our event API
var Events = pluginEvents{
ReceivedTPSUpdated: events.NewEvent(uint64EventCaller),
}
package metrics
import (
"time"
"github.com/iotaledger/goshimmer/packages/daemon"
"github.com/iotaledger/goshimmer/packages/events"
"github.com/iotaledger/goshimmer/packages/model/meta_transaction"
"github.com/iotaledger/goshimmer/packages/node"
"github.com/iotaledger/goshimmer/packages/timeutil"
"github.com/iotaledger/goshimmer/plugins/gossip"
)
// create configure handler (get's called when the PLUGIN is "loaded" by the node)
func configure(plugin *node.Plugin) {
// increase received TPS counter whenever we receive a new transaction
gossip.Events.ReceiveTransaction.Attach(events.NewClosure(func(_ *meta_transaction.MetaTransaction) { increaseReceivedTPSCounter() }))
}
// create run handler (get's called when the PLUGIN is "executed" by the node)
func run(plugin *node.Plugin) {
// create a background worker that "measures" the TPS value every second
daemon.BackgroundWorker("Metrics TPS Updater", func() { timeutil.Ticker(measureReceivedTPS, 1*time.Second) })
}
// export plugin
var PLUGIN = node.NewPlugin("Metrics", configure, run)
package metrics
import (
"sync/atomic"
)
// public api method to proactively retrieve the received TPS value
func GetReceivedTPS() uint64 {
return atomic.LoadUint64(&measuredReceivedTPS)
}
// counter for the received TPS
var tpsReceivedSinceLastMeasurement uint64
// measured value of the received TPS
var measuredReceivedTPS uint64
// increases the received TPS counter
func increaseReceivedTPSCounter() {
atomic.AddUint64(&tpsReceivedSinceLastMeasurement, 1)
}
// measures the received TPS value
func measureReceivedTPS() {
// sample the current counter value into a measured TPS value
sampledTPS := atomic.LoadUint64(&tpsReceivedSinceLastMeasurement)
// store the measured value
atomic.StoreUint64(&measuredReceivedTPS, sampledTPS)
// reset the counter
atomic.StoreUint64(&tpsReceivedSinceLastMeasurement, 0)
// trigger events for outside listeners
Events.ReceivedTPSUpdated.Trigger(sampledTPS)
}
...@@ -8,6 +8,7 @@ import ( ...@@ -8,6 +8,7 @@ import (
"github.com/iotaledger/goshimmer/plugins/bundleprocessor" "github.com/iotaledger/goshimmer/plugins/bundleprocessor"
"github.com/iotaledger/iota.go/address" "github.com/iotaledger/iota.go/address"
. "github.com/iotaledger/iota.go/consts" . "github.com/iotaledger/iota.go/consts"
"github.com/iotaledger/iota.go/kerl"
"github.com/iotaledger/iota.go/signing" "github.com/iotaledger/iota.go/signing"
. "github.com/iotaledger/iota.go/trinary" . "github.com/iotaledger/iota.go/trinary"
) )
...@@ -17,7 +18,6 @@ var PLUGIN = node.NewPlugin("Validator", configure, run) ...@@ -17,7 +18,6 @@ var PLUGIN = node.NewPlugin("Validator", configure, run)
// Creates bundle signature fragments and the corresponding address to validate against. // Creates bundle signature fragments and the corresponding address to validate against.
// Each signature fragment after the first must go into its own meta transaction with value = 0. // Each signature fragment after the first must go into its own meta transaction with value = 0.
func demoSign(seed Trytes, index uint64, sec SecurityLevel, bundleHash Hash) (Hash, []Trytes) { func demoSign(seed Trytes, index uint64, sec SecurityLevel, bundleHash Hash) (Hash, []Trytes) {
addr, _ := address.GenerateAddress(seed, index, sec) addr, _ := address.GenerateAddress(seed, index, sec)
// compute seed based on address index // compute seed based on address index
...@@ -63,7 +63,7 @@ func validateSignatures(bundleHash Hash, txs []*value_transaction.ValueTransacti ...@@ -63,7 +63,7 @@ func validateSignatures(bundleHash Hash, txs []*value_transaction.ValueTransacti
} }
// validate all the fragments against the address using Kerl // validate all the fragments against the address using Kerl
valid, err := signing.ValidateSignatures(address, fragments, bundleHash, signing.NewKerl) valid, err := signing.ValidateSignatures(address, fragments, bundleHash, kerl.NewKerl())
if err != nil { if err != nil {
return false, err return false, err
} }
...@@ -77,7 +77,7 @@ func validateSignatures(bundleHash Hash, txs []*value_transaction.ValueTransacti ...@@ -77,7 +77,7 @@ func validateSignatures(bundleHash Hash, txs []*value_transaction.ValueTransacti
func configure(plugin *node.Plugin) { func configure(plugin *node.Plugin) {
bundleprocessor.Events.ValueBundleReceived.Attach(events.NewClosure(func(b *bundle.Bundle, txs []*value_transaction.ValueTransaction) { bundleprocessor.Events.BundleSolid.Attach(events.NewClosure(func(b *bundle.Bundle, txs []*value_transaction.ValueTransaction) {
// signature are verified against the bundle hash // signature are verified against the bundle hash
valid, _ := validateSignatures(b.GetBundleEssenceHash(), txs) valid, _ := validateSignatures(b.GetBundleEssenceHash(), txs)
if !valid { if !valid {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment