ns3 execute function during simulation at regular time interval - intervals

How can I execute a function every 20us for example?
I aim to log the busy/free state on a CSMA channel using ns3::CsmaChannel::IsBusy (is that the best way to do it?) I have to call it at regular time interval to log each returned value and time.

You can use
simulator:: schedule function
to schedule function on a regular time interval
Simulator:: Schedule (Seconds(20.0), &function name, parameter1, parameter 2)
This is the syntax for scheduling an event for every 20 seconds

Related

Laravel Task Scheduling - when does the execution starts

Laravel Task Scheduling has options like, everyMinute() which will run a command every minute. I want to know what is the time it actually starts executing. Is it when I run the server or any specific second of the minute?
I am trying to run a function depending on the time difference. Here's a pseudocode
Run myCustomFunction() if diffInMin(now, customTime) <= 1
I thought it will run 1 time but it ran twice every time.
The scheduler usually runs every minute right around the zero secound mark based on the server's current time as #apokryfos mentioned.
Assuming the customTime is a fixed DateTime, what makes you think the code you wrote will only run once?
When now() === customTime the diffInMin() would be zero so the
condition diffInMin(now, customTime) <= 1 will evaluate to true.
The next minute, the diffInMin() would be 1, so the
condition diffInMin(now, customTime) <= 1 will still evaluate to true.

Firing Alerts for an activity which is supposed to happen during a particular time interval(using Prometheus Metrics and AlertManager)

I am fairly new to Prometheus alertmanager and had a doubt regarding firing alerts only during a particular period
I have a microservice which receives a file and does some processing on it, which is only invoked when it gets a message through a Kafka queue. The aforementioned is supposed to come every day between 5 am and 6 am(UTC time). The microservice has a metric which is incremented by 1 every time it receives a file. I want to raise an alert if it does not receive a file in the interval. I have created a query like this :
expr : sum(increase(metric_name[1m]) and on() hour(vector(time()))==5) < 1
for: 1h
My questions:-
1) Is it correct or is there a better way to do it
2) In case of no update, will it return 0 or "datapoints not found"
3) Is increase the correct function as it tends to give results in decimals due to extrapolation, but I understand if increase is 0, it will show 0
I can't really play around with scrape_intervals, which is set at 30s.
I have not run this expression but I expect it will cause an alert to fire at 06:00 only and then go off at 06:01. It is the only time the expression would hold true for one hour.
Answering your questions
It is correct if what you want is a single fire of alert (sending a mail by example) but then no longer firing. Even with that, the schedule is a bit tight and may get hurt by alertmanager delay causing the alert to be lost.
In case of no increase, you will get the expression will evaluate to 0. It will be empty when there is an update
Increase is the right function. It even takes into account reset of the counter.
Answering if there is a better way to do it.
Regarding your expression, you can have the same result, without for clause, with:
expr: increase(metric_name[1h])==0 and on() hour()==6 and on() minute()<1
It reads a : starting at 6am and for 1 minutes, if there was no increase of metric over the lasthour.
Alerting longer
If you want the alert to last longer (say for the day and you silence it when it is solved), you can use sub-queries;
expr: increase((metric and on() hour()==5)[18h:])==0 and on() hour()>5
It reads as : starting at 6am (hour()>5), compute the increase over 5-6am for the next 18 hours. If you like having a pending, you can drop the trailing on() hour()>5 and use a for: 1h clause.
If you want to alert until a file is submitted and thus detect a resolution, simply transform the expression to evaluate the increase until now:
expr: increase((metric and on() hour()>5)[18h:])==0 and on() hour()>5

Is there a way to extract window start time and window endtime in spark streaming windowing?

I am having a DSTREAM on which I use window method. Then subsequently I do other operations like reduceByKey. Is it possible to add the window start time and end time to the DSTREAM data and use it as a key?
consider i have a DSTREAM with the following input schema:
(call_id, call_duration, call_count)
after window operation on the DSTREAM, is it possible produce the following output?
(window_start_time, window_end_time, average_call_duration, total_call_counts)
dstream.foreachRDD((rdd, time)=> {
// time is scheduler time for the batch job.it's interval was your window/slide length.
})
Use the time as the parameter of your ETL function.

difference between ${CDR(start)} and ${STRFTIME(${EPOCH},,%Y-%m-%d %H:%M:%S)} in asterisk

I have created a dialplan which takes the call and save the start and end time of the call. I used ${CDR(start)} to get the start time of the call but when I used ${STRFTIME(${EPOCH},,%Y-%m-%d %H:%M:%S)} instead it gave me a 10 or more seconds difference as compared to ${CDR(start)}.Part of my code:
same => n,NoOp(------${CDR(start)}----${STRFTIME(${EPOCH},,%Y-%m-%d %H:%M:%S)}--)
the above line is second line in my dialplan.From the docs ${CDR(start)} give start time of call and ${STRFTIME(${EPOCH},,%Y-%m-%d %H:%M:%S)} gives current time .But I place the line as second line of my dialplan so its nearly start of call so both ${CDR(start)} and ${STRFTIME(${EPOCH},,%Y-%m-%d %H:%M:%S)} should be equal approximately but the output was like
NoOp(------2015-10-25 12:30:10----2015-10-25 12:30:21--)
Why there is so much diffrence in both? and also I dont know why the value of ${CDR(end)} is empty.
${CDR(start)} - is a time of call start.
${STRFTIME(${EPOCH},,%Y-%m-%d %H:%M:%S)} - current time, when this command was executed.
If you use EPOCH variable after hangup, it may points to the end of call.
${CDR(end)} can be empty if call is active now and will be filled after hangup.
About CDR variables: https://wiki.asterisk.org/wiki/display/AST/CDR+Variables
${CDR(start)} is not time of current call start, but time of current cdr start. It can be changed after transfer from queue, ResetCDR, ForkCDR command
EPOCH always give current linux time. After hangup it can show end of call, but also can show different time if processing was long enoght.

how to get recent event recorded in event logs(eg: logged before about 10 seconds) in Windows using C++?

I need to collect event logs from Windows those are logged before 10 seconds. Using pull subscription I could collect already saved logs before execution of program and saving logs while program is running. I tried with the code available on MSDN:
Subscribing to Events
"I need to start to collect the event logged 10 seconds ago". Here I think I need to set value for LPWSTR pwsQuery to achieve that.
L"*[System/Level= 2]" gives the events with level equal to 2.
L"*[System/EventID= 4624]" gives events with eventID is 4624.
L"*[System/Level < 1]" gives events with level < 2.
Like that I need to set the value for pwsQuery to get event logged near 10 seconds. Can I do in the same way as above? If so how? If not what are the other ways to do it?
EvtSubscribe() gives you new events as they happen. You need to use EvtQuery() to get existing events that have already been logged.
The Consuming Events documentation shows a sample query that retrieves events beginning at a specific time:
// The following query selects all events from the channel or log file where the severity level is
// less than or equal to 3 and the event occurred in the last 24 hour period.
XPath Query: *[System[(Level <= 3) and TimeCreated[timediff(#SystemTime) <= 86400000]]]
So, you can use TimeCreated[timediff(#SystemTime) <= 10000] to get events in the last 10 seconds.
The TimeCreated element is documented here:
TimeCreated (SystemPropertiesType) Element
The timediff() function is described on the Consuming Events documentation:
The timediff function is supported. The function computes the difference between the second argument and the first argument. One of the arguments must be a literal number. The arguments must use FILETIME representation. The result is the number of milliseconds between the two times. The result is positive if the second argument represents a later time; otherwise, it is negative. When the second argument is not provided, the current system time is used.
 

Resources