simple queue - save statistic

Please allow roterOS to save statistic of simple queues into HDD. I always lost this data after reboot. I use this for counting user data and FUP. Is here any possibility to do this?

If you are talking about graphing, you have to specify store-on-disk=yes.
Use correct clock setings (setup NTP client).

P.S. I think such question should be asked in ‘General Networking’ section.

I am not talking about graphing. I am talking about transmitted data via queue (variable total-bytes). I am using this in my script for limiting user speed after transmitting given amount of data. Everything works fine, but after reset this variable is 0 so I want to store this variable on HDD or I need this variable to be stored on HDD by routerOS. I don’t want to use external PC for storing this variable. Is here any possibility how to do this.

http://forum.mikrotik.com/t/how-to-limit-a-user-to-a-given-amount-of-traffic/237/1

I guess, it’s not possible to store particular value on HDD, and data will be erased after reboot, shutdown, etc.
I think ‘graphing’ is more informative way to monitor queues (External SNMP server can be used as well).

And is it possible to read from graphing amount of transmitted data per month in a script?

Simple graphs provides information about ‘Daily’, ‘Weekly’, ‘Monthly’, ‘Yearly’ usage, and provides information like this,
http://demo2.mt.lv/graphs/iface/wlan1/

I know this, but is it possible to read the exact number of bytes via script?

Does anybody has any idea?

So did you find any solution for saving this data?

or anyone else? how to save this data?

Command to get detailed information about queue statistic,
/queue simple print stats
1 D rate=0/35080 total-rate=0 packet-rate=0/10 total-packet-rate=0
queued-bytes=0/0 total-queued-bytes=0 queued-packets=0/0
total-queued-packets=0 bytes=11737/33719917 total-bytes=0
packets=97/40651 total-packets=0 dropped=0/0 total-dropped=0 lends=97/581
total-lends=0 borrows=0/40070 total-borrows=0

Yes, but these statistics are deleted after reboot. But how to save these statistics so it stays there even if router is rebooted?

Query the router via SNMP. There’s OIDs for all the queues.

Can you be litle more precise about it? Thanks!

About what? What OIDs are? What SNMP is? Those questions would probably be better suited to a general Google search. SNMP is a common protocol used to monitor network equipment and collect information from it. OIDs are the addresses of data points a system provides. You can use SNMP via the NMS of your choice to monitor simple queues in RouterOS on an external server, and store data on the external data permanently.

That is ok, thanks for info. But all that are just alternative options. I asked why isn’t possible to store this on disk? So it will stay there even after reboot. I don’t need server or any other mashine to monitor traffic.. I share connection with 3 other friends, and need to know that simple stats. But I guess that it isn’t so simple.

We’ve looked into what you describe extensively and decided to build the DBS solution as described in the signature below.

If you insist in building this yourself you would need to gather and store the data off of the router and save in a “round robin database” a.k.a. “rrdtool” somewhere else. The trick is detecting data rates that are impossible and then ignoring those samples, as it would appear when a register rolls over or by having a counter being reset to zero. One great example of this is provided by the open source program called Cacti (http://www.cacti.net/), where the data is collected through SNMP and saved and graphed using RrdTool.

Once you have the data off the router, then your script would need to retrieve this data, and make adjustments as needed. No simple task.

It really isn’t.

Most RouterBOARDs have NAND storage. That limits the number of write cycles. How often do you update the stats on disk? They change all the time, so that’s an awful lot of write cycles, until the internal storage breaks.

Store statistics info in a remote server.
In this example i just post the name and bytes.
Script:

{
	/queue simple
	:local queueList [find]
	:foreach q in=$queueList do={
		:local qName [get $q name]
		:local qTarget [get $q target]
		:local qBytes [get $q bytes]
		:local qStatus [get $q disabled]
		:if (!$qStatus) do={
			:local logmessage ("{\"name\":\"" . $qName . "\",\"bytes\":\"" . $qBytes . "\"}")
			:put ($logmessage)
			/tool fetch http-method=post http-header-field="Content-Type: application/json" http-data=$logmessage url="http://192.168.100.17/queue.php"
		}
	}
}

queue.php:

<?php
  function isValidJSON($str) {
     json_decode($str);
     return json_last_error() == JSON_ERROR_NONE;
  }
  $json = file_get_contents('php://input');
  if (strlen($json) > 0 && isValidJSON($json)){
    $data = json_decode($json);
	date_default_timezone_set("America/New_York");
	$njsond = ["LastC"=>date("d-m-Y h:i:sa"),"bytesUD"=>$data->bytes];
	echo file_put_contents("Queue-" . $data->name . ".json",json_encode($njsond));
  }
?>