-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9a81fb6
commit cec63e7
Showing
8 changed files
with
119 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
syntax = "proto3"; | ||
|
||
package pinax.sinks.prom.v1; | ||
|
||
message PrometheusMetrics { | ||
// TO-DO | ||
// Reference https://pkg.go.dev/github.com/prometheus/client_golang/prometheus#Gauge | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,41 @@ | ||
use substreams::errors::Error; | ||
use substreams::{log, prelude::*}; | ||
use substreams::log; | ||
use substreams_antelope::Block; | ||
|
||
use crate::eosmechanics::{BlockResults, ProducerStats}; | ||
use crate::eosmechanics::ProducerUsage; | ||
use crate::sinks::PrometheusMetrics; | ||
|
||
#[substreams::handlers::map] | ||
pub fn map_block_stats(block: Block) -> Result<BlockResults, Error> { | ||
pub fn map_producer_usage(block: Block) -> Result<ProducerUsage, Error> { | ||
|
||
// ToDo parse the transaction traces of the block | ||
// if it contains an action on account "eosmechanics" with the name "cpu" then take the | ||
// cpu time of the transaction and the name of the producer and return it. | ||
// Producer is found in the block header | ||
let producer = block.clone().header.unwrap().producer; | ||
|
||
for trx in block.clone().all_transaction_traces() { | ||
// CPU usage is found in the transaction receipt | ||
let cpu_usage = trx.clone().receipt.unwrap().cpu_usage_micro_seconds as i64; | ||
|
||
// the producer can be found on the block header using: | ||
// block.header.unwrap().producer | ||
// Only return a value if the transaction trace contains `eosmechanics:cpu` action | ||
for trace in trx.clone().action_traces { | ||
let action_trace = trace.action.as_ref().unwrap().clone(); | ||
if action_trace.account != "eosmechanics" { continue; } | ||
if action_trace.name != "cpu" { continue; } | ||
return Ok(ProducerUsage{ | ||
producer, | ||
cpu_usage, | ||
}) | ||
} | ||
} | ||
|
||
// the cpu usage can be found in the transaction receipt | ||
|
||
Ok(BlockResults{ | ||
producer_stats: vec![] | ||
}) | ||
// If no transaction trace contains `eosmechanics:cpu` action, return default value | ||
Ok(Default::default()) | ||
} | ||
|
||
// #[substreams::handlers::map] | ||
// pub fn prom_out(block_results: BlockResults) -> Result<PrometheusChange, Error> { | ||
// | ||
// ToDo push generic prometheus changes here | ||
// this requires that we define a prometheus changes protobuf first. I (Fred) will help you on that task | ||
// | ||
// } | ||
#[substreams::handlers::map] | ||
pub fn prom_out(producer_usage: ProducerUsage) -> Result<PrometheusMetrics, Error> { | ||
log::debug!("producer_usage={:?}", producer_usage); | ||
|
||
// TO-DO push generic prometheus changes here | ||
// this requires that we define a prometheus changes protobuf first. I (Fred) will help you on that task | ||
return Ok(PrometheusMetrics::default()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// @generated | ||
/// TO-DO | ||
/// Reference <https://pkg.go.dev/github.com/prometheus/client_golang/prometheus#Gauge> | ||
#[derive(Clone, PartialEq, ::prost::Message)] | ||
pub struct PrometheusMetrics { | ||
} | ||
/// Encoded file descriptor set for the `pinax.sinks.prom.v1` package | ||
pub const FILE_DESCRIPTOR_SET: &[u8] = &[ | ||
0x0a, 0xd6, 0x01, 0x0a, 0x0f, 0x73, 0x69, 0x6e, 0x6b, 0x2e, 0x70, 0x72, 0x6f, 0x6d, 0x2e, 0x70, | ||
0x72, 0x6f, 0x74, 0x6f, 0x12, 0x13, 0x70, 0x69, 0x6e, 0x61, 0x78, 0x2e, 0x73, 0x69, 0x6e, 0x6b, | ||
0x73, 0x2e, 0x70, 0x72, 0x6f, 0x6d, 0x2e, 0x76, 0x31, 0x22, 0x13, 0x0a, 0x11, 0x50, 0x72, 0x6f, | ||
0x6d, 0x65, 0x74, 0x68, 0x65, 0x75, 0x73, 0x4d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x73, 0x4a, 0x90, | ||
0x01, 0x0a, 0x06, 0x12, 0x04, 0x02, 0x00, 0x09, 0x01, 0x0a, 0x08, 0x0a, 0x01, 0x0c, 0x12, 0x03, | ||
0x02, 0x00, 0x12, 0x0a, 0x08, 0x0a, 0x01, 0x02, 0x12, 0x03, 0x04, 0x00, 0x1c, 0x0a, 0x66, 0x0a, | ||
0x02, 0x04, 0x00, 0x12, 0x04, 0x06, 0x00, 0x09, 0x01, 0x22, 0x5a, 0x20, 0x54, 0x4f, 0x2d, 0x44, | ||
0x4f, 0x0a, 0x20, 0x52, 0x65, 0x66, 0x65, 0x72, 0x65, 0x6e, 0x63, 0x65, 0x20, 0x68, 0x74, 0x74, | ||
0x70, 0x73, 0x3a, 0x2f, 0x2f, 0x70, 0x6b, 0x67, 0x2e, 0x67, 0x6f, 0x2e, 0x64, 0x65, 0x76, 0x2f, | ||
0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x70, 0x72, 0x6f, 0x6d, 0x65, | ||
0x74, 0x68, 0x65, 0x75, 0x73, 0x2f, 0x63, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x5f, 0x67, 0x6f, 0x6c, | ||
0x61, 0x6e, 0x67, 0x2f, 0x70, 0x72, 0x6f, 0x6d, 0x65, 0x74, 0x68, 0x65, 0x75, 0x73, 0x23, 0x47, | ||
0x61, 0x75, 0x67, 0x65, 0x0a, 0x0a, 0x0a, 0x0a, 0x03, 0x04, 0x00, 0x01, 0x12, 0x03, 0x06, 0x08, | ||
0x19, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, | ||
]; | ||
// @@protoc_insertion_point(module) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters