ya-runtime-sdk
): https://github.com/golemfactory/ya-test-runtime-counters​yapapi
. If this is your first time using Golem and yapapi, please first refer to the resources linked above.yapapi
. It instantiates the runtime on a Provider and periodically fetches the current state of usage counters to demonstrate fetching of custom usage counter updates.metric_reporter()
function which periodically increments a value of a counter named golem.usage.custom.counter
, then notifies the runtime about this new value via anEventEmitter
:RuntimeCounter
struct is used to pass the value of a counter using EventEmitter
's counter()
method. The RuntimeCounter instance will be propagated by the ExeUnit to the Provider agent (for the purposes of pricing and invoicing) and to Requestor side where it can be fetched by the Requestor agent's code.ExampleRuntime
, which is fairly simple, as it includes some non-void implementations of start()
and run_command()
actions.com.Counter.TIME
) and another based on the actual CPU execution time (com.Counter.CPU
).start()
start()
action launches a local thread running the metric_reporter()
passing anEventEmitter
instance cloned from runtime's Context
:golem.usage.custom.counter
counter value.run_command()
run_command()
implements two explicitly named commands which can be triggered by calling a RUN <command> ExeScript call. The commands are:sleep n
- forces the runtime to wait n
milliseconds.stop
- causes the runtime shutdown.ya-test-runtime-counters.json
config file, which includes metadata for the runtime, required to plug it into a yagna provider service, under the name test-counters
:config.counters
structure is used to specify the custom usage counter metadata.golemsp
$HOME/.local/lib/yagna/plugins/
directory create:ya-test-runtime-counters.json
where you describe the plugin:ya-test-runtime-counters
(compare runtime-path
in above file) where ya-test-runtime-counters
binary along with Erigon binaries are placed.$HOME/.local/share/ya-provider/presets.json
. Preset object can be copied from other presets. Please note that exeunit-name
has to match to the name
property of the plugin above:golem.usage.custom.counter
is to be included in the pricing function (linear model) with a coefficient of 0.0003 GLM.test-counters
runtime as payload:run()
handler, it periodically fetches the usage vector as published by the ExeUnit alongside the accumulated cost and displays it in console:Golem
:CustomCounterService
:golem.usage.custom.counter
counter being periodically incremented.