Skip to content

Commit

Permalink
metrics: support candidate score report
Browse files Browse the repository at this point in the history
  • Loading branch information
mycoin2019 authored and lianxiangcloud committed Sep 19, 2019
1 parent be53118 commit fe6e024
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
11 changes: 11 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/lianxiangcloud/linkchain/utxo"
"github.com/lianxiangcloud/linkchain/vm/evm"
"github.com/lianxiangcloud/linkchain/vm/wasm"
"github.com/lianxiangcloud/linkchain/metrics"
"github.com/xunleichain/tc-wasm/vm"
)

Expand Down Expand Up @@ -627,6 +628,16 @@ func (app *LinkApplication) CommitBlock(block *types.Block, blockParts *types.Pa
app.blockChain.SaveBlock(block, blockParts, seenCommit, processResult.GetReceipts(), processResult.GetTxsResult())
app.utxoStore.SaveUtxo(processResult.txsResult.KeyImages(), processResult.txsResult.UTXOOutputs(), block.Height)

// candidate score metrics report
if metrics.PrometheusMetricInstance.ProposerPubkeyEquals() {
metricCans := processResult.tmpState.GetAllCandidates(log.Root())
for _, metricCan := range metricCans {
scoreMetric := metrics.PrometheusMetricInstance.GenCandidateScoreMetric(block.Height,
metricCan.Address.String(), metricCan.Score)
metrics.PrometheusMetricInstance.AddMetrics(scoreMetric)
}
}

app.mempool.Lock()

app.LockState()
Expand Down
7 changes: 6 additions & 1 deletion metrics/prometheus_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,12 @@ func (p *prometheusMetric) GenBlockValidatorsListMetric(validatorsListStr string
p.hostname, p.roleType, p.httpEndpoint, validatorsListStr, blockHeight)
}

func (p *prometheusMetric) GenNetInfo(peerName string, peerRole types.NodeType, peerVersion string) string {
func (p *prometheusMetric) GenNetInfoMetric(peerName string, peerRole types.NodeType, peerVersion string) string {
return fmt.Sprintf("link_NetInfo{hostname=\"%s\",role=\"%d\",ip_port=\"%s\",peerName=\"%s\",peerRole=\"%s\",peerVersion=\"%s\"} 0\n",
p.hostname, p.roleType, p.httpEndpoint, peerName, peerRole, peerVersion)
}

func (p *prometheusMetric) GenCandidateScoreMetric(blockHeight uint64, candidateAddr string, score int64) string {
return fmt.Sprintf("link_CandidateScore{blockHeight=\"%d\",addr=\"%s\"} %d\n",
blockHeight, candidateAddr, score)
}
2 changes: 1 addition & 1 deletion rpc/ethapi/api_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (s *PublicPrometheusMetricsAPI) PrometheusMetrics() string {
return err.Error()
}
for _, peer := range nInfo.Peers {
prometheusMetrics += metrics.PrometheusMetricInstance.GenNetInfo(peer.Moniker,
prometheusMetrics += metrics.PrometheusMetricInstance.GenNetInfoMetric(peer.Moniker,
peer.Type, peer.Version)
}

Expand Down

0 comments on commit fe6e024

Please sign in to comment.