# Real Time Monitor

**URL:** <https://brian.discourse.group/t/real-time-monitor/173>\
**Category:** Feature requests\
**Created:** [2 October 2020 14:41 UTC](https://brian.discourse.group/t/real-time-monitor/173 "2020-10-02T14:41:41Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![mstimberg](https://yyz2.discourse-cdn.com/free1/user_avatar/brian.discourse.group/mstimberg/32/11_2.png) [@mstimberg](https://brian.discourse.group/u/mstimberg)\
**Post date:** [2 October 2020 16:19 UTC](https://brian.discourse.group/t/real-time-monitor/173/2 "2020-10-02T16:19:33Z")

</div>

Monitors that write their results to disk online has been on our list for a _long_ time (see e.g. github issue [#289](https://github.com/brian-team/brian2/issues/298), but no-one did find the time to actually do it (and the details of syntax and functionality have never been decided). If you don’t mind writing C++ code, there’s nothing that stops you from using our extension mechanisms from doing it, though. Here’s a simple example using a [custom function](https://brian2.readthedocs.io/en/stable/advanced/functions.html#other-code-generation-targets). This will write all the spikes from the group to a single text file at every time step:)

```auto
from brian2 import *
set_device('cpp_standalone')

@implementation('cpp','''
// Note that functions always need a return value at the moment
double store_spike(int i, double t) {
    static std::ofstream spike_file("/some/path/spikes.txt"); // opens the file the first time
    spike_file << i << " " << t << std::endl;
    return 0.; // unused
}
''')
@check_units(i=1, t=second, result=1)
def store_spike(i, t):
    raise NotImplementedError('Use standalone mode')

G = NeuronGroup(10, 'rates : Hz (constant)', threshold='rand()<rates*dt',
                reset='dummy_var = store_spike(i, t)')
G.rates = '50*Hz + i*50*Hz'
run(100*ms)

```

---

_[View the full topic](https://brian.discourse.group/t/real-time-monitor/173)._
