How to log link status ?

HI.
1)
Is it possible to log link up/down status and speed/duplex mode?
Im asking because it’s not a problem to get such kind of information under Linux.
2)
Is it possible to see/check error packet counter under interfaces?

Thank you.

You can do this in several ways. You can use SNMP to gather some of this information. You can cause the actual logging of this information (syslog) if you like as well. For syslog with wireless, just do:

/system logging add topics=wireless,debug action=memory

This will increase the logging information for wireless. You can see the list of actions available with:

/system logging action print



2)Is it possible to see/check error packet counter under interfaces?

See this thread: http://forum.mikrotik.com/t/feature-proposal-also-community-pls-say-if-it-is-required/17815/1

SNMP is not exactly what I want.
“/system logging add topics=wireless,debug action=memory” looks good, but I need the same for Ethernet interfaces :frowning:.

You can do this in several ways. You can use SNMP to gather some of this information. You can cause the actual logging of this information (syslog) if you like as well. For syslog with wireless, just do:

/system logging add topics=wireless,debug action=memory

This will increase the logging information for wireless. You can see the list of actions available with:

/system logging action print

The Dude ?

SNMP is not the best answer, but I only gave you the options that were currently available in Mikrotik, which, I assumed, was your question. For the statistics you are wanting in ethernet, SNMP is the ONLY currently available option.

OK thanks,
I understand your point of view.

However Link UP , and Link down is part of kernel messages under linux , that’s why I thought
that put a such kind of message into log should not be a big problem.

From other side I’d tried to setup logging via netwatch
/tool netwatch add host=x.x.x.x interval=10s timeout=998ms up-script=sc_1 down-script=sc_2

Try to add script like it’s describe in manual
http://www.mikrotik.com/testdocs/ros/2.9/system/scheduler.php

[admin@OFFICE] > /system script add name=sc-1 source=:log message=link-up
syntax error (line 1 column 37)
[admin@OFFICE] >/system script add name=sc-2 source=:log message=link-down
syntax error (line 1 column 37)

But this example do not work.

Actually it is better to print result of “interface ethernet monitor etherX once” into log , but I do not knew how to do that.

These are available with the debug messages that I quoted above.

From other side I’d tried to setup logging via netwatch
/tool netwatch add host=x.x.x.x interval=10s timeout=998ms up-script=sc_1 down-script=sc_2

Try to add script like it’s describe in manual
http://www.mikrotik.com/testdocs/ros/2.9/system/scheduler.php

[admin@OFFICE] > /system script add name=sc-1 source=:log message=link-up
syntax error (line 1 column 37)
[admin@OFFICE] >/system script add name=sc-2 source=:log message=link-down
syntax error (line 1 column 37)

But this example do not work.

The source needs to be quoted like this:
/system script add name=sc-1 source=“:log message=link-up”

Actually it is better to print result of “interface ethernet monitor etherX once” into log , but I do not knew how to do that.

This is untested, but try something like this:

 /interface ethernet monitor ether1 once do={
        :environment print
         :log info $status 
}

You can log the other variables, too. Like this:

/system script add name="check_stats" source=":local cpuload \[/system resource get cpu-load\]
:local memory \[/system resource get free-memory\]
:log error \"CPU Load:\"
:log error \$cpuload
:log error \"Available memory:\"
:log error \$memory
/interface monitor-traffic lan once do={
   :env print
   :log error \"RX pps:\"
   :log error \$received-packets-per-second
   :log error \"TX pps:\"
   :log error \$sent-packets-per-second
   :log error \"Received bps:\"
   :log error \$received-bits-per-second
   :log error \"TX bps:\"
   :log error \$sent-bits-per-second
}"

Not sure if this is what you’re after, but it is the best that we can do without SNMP.

I threw this together a long time ago to debug a client but I don’t remember if it works or not..

:if ( [:len($linkstate1)] = 0 ) do={
 /int ethernet monitor ether1 once do={:global linkstate1 $status;}
}
:if ( [:len($linkstate2)]  = 0) do={
 /int ethernet monitor ether1 once do={:global linkstate1 $status;}
}
/interface ethernet monitor ether1 once do {
 :if ($status != ($linkstate1) ) do={
  :global linkstate1 $status;
  :log info ("Ethernet link changed to " . $status)
 } else {
  
 }
}

It sets a variable based on the current status of ether1 (twice), then compares that status with the current status of ether1 and then exits. I’d doubt this will do what you need it to do. If you put an infinite loop around the last section, it will do what you want (monitor ether1 status and log changes), but it is not gonna do that as written.

oh well. I saw it in my script directory and figured I’d share.. iirc I called it from a scheduled task every minute.. That $linkstate2 line isn’t needed..

-Gerard