-
Notifications
You must be signed in to change notification settings - Fork 121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to use exometer to monitor stock tick stream? #104
Comments
The way exometer works, you typically define a reporter which subscribes to metrics and at regular (configurable) intervals pushes data to some data store, log or analytics backend. What this gives you is a set of periodic snapshots, which is often just what you want. Is your question how you can ensure that all ticks are reported to the database? |
@uwiger, yes. I want to collect all ticks count snapshot and report to database. Update counter in client [updated]
I have tried to wrap the snapshot like below (stock_count.erl)
The return value of |
Ok, just to check: your Also, your Was this just a typo? What happens when you manually sample the My understanding of what you describe leads me to suggest this: For demonstration, I create a reporter which simply stores values in an ets table. Relevant callbacks: exometer_init(_Opts) ->
ets:new(demo_ticks, [ordered_set, named_table, public]),
{ok, []}.
exometer_report(Metric, value, _Extra, Value, St) ->
Time = erlang:monotonic_time(millisecond),
ets:insert(demo_ticks, {{Time,Metric}, Value}),
{ok, St};
exometer_report(_Metric, _DataPoint, _Extra, _Value, St) ->
{ok, St}.
exometer_report_bulk(Found, _Extra, St) ->
Time = erlang:monotonic_time(millisecond),
[ets:insert(demo_ticks, {{Time,Metric}, proplists:get_value(value, DPs)})
|| {Metric, DPs} <- Found], Then, testing it in the shell: Eshell V9.1 (abort with ^G)
1> application:ensure_all_started(exometer_core).
...
{ok,[hut,setup,bear,folsom,exometer_core]}
2> [exometer:update_or_create([tick,StockName,Exchange],1,counter,[]) || {StockName,Exchange} <- [{appl,x},{amzn,x},{appl,y},{amzn,y}]].
[ok,ok,ok,ok]
3> exometer_report:add_reporter(tick_reporter, [{module,tick_reporter},{intervals,[{main,5000}]},{report_bulk,true}]).
ok
4> exometer_report:subscribe(tick_reporter,{find,[tick,'_','_']},value,main).
ok
5> ets:tab2list(demo_ticks).
[{{-576460744789,[tick,amzn,x]},1},
{{-576460744789,[tick,amzn,y]},1},
{{-576460744789,[tick,appl,x]},1},
{{-576460744789,[tick,appl,y]},1},
{{-576460744788,[tick,amzn,x]},1},
{{-576460744788,[tick,amzn,y]},1},
{{-576460744788,[tick,appl,x]},1},
{{-576460744788,[tick,appl,y]},1},
{{-576460739787,[tick,amzn,x]},1},
{{-576460739787,[tick,amzn,y]},1},
{{-576460739787,[tick,appl,x]},1},
{{-576460739787,[tick,appl,y]},1},
{{-576460739786,[tick,amzn,x]},1},
{{-576460739786,[tick,amzn,y]},1},
{{-576460739786,[tick,appl,x]},1},
{{-576460739786,[tick,appl,y]},1}]
6> [exometer:update_or_create([tick,StockName,Exchange],1,counter,[]) || {StockName,Exchange} <- [{appl,x},{amzn,x},{appl,y},{amzn,y}]].
[ok,ok,ok,ok]
7> ets:tab2list(demo_ticks).
[...,
{{-576460739786,[tick,appl,y]},1},
{{-576460734785,[tick,amzn,x]},1},
{{-576460734785,[tick,amzn,y]},1},
{{-576460734785,[tick,appl,x]},1},
{{-576460734785,[tick,appl,y]},1},
{{-576460734783,[tick,amzn,x]},1},
{{-576460734783,[tick,amzn,y]},1},
{{-576460734783,[tick,appl,x]},1},
{{-576460734783,[tick,appl|...]},1},
{{-576460729782,[tick|...]},2},
{{-576460729782,[...]},2},
{{-576460729782,...},2},
{{...},...},
{...}|...] |
@uwiger, thanks for point out the errors. I've update the code in the original post. As mentioned before, I wanted to collect data from all stock metrics and send the data to one table in backend. And in above demonstration, it creates tables like |
Well, my example simply wrote the metric and values to an ets table, using an increasing timestamp to separate consecutive updates. But the |
Hello,
I am going to use exometer to monitor stock tick stream, InfluxDB acts as the backend database. And the table schema is designed as below:
And I create each metric for every stock
My question is how can I write
exometer_report:subscribe/6
method to send data back to influxdb described above?The text was updated successfully, but these errors were encountered: