mirror of
https://github.com/KevinMidboe/mktxp-no-cli.git
synced 2025-10-29 17:50:23 +00:00
cli options
This commit is contained in:
52
README.md
52
README.md
@@ -1,4 +1,5 @@
|
||||
|
||||
|
||||

|
||||

|
||||

|
||||
@@ -7,8 +8,53 @@
|
||||

|
||||
|
||||
|
||||
|
||||
# mktxp
|
||||
Prometheus Exporter for Mikrotik RouterOS devices
|
||||
#### Requirements:
|
||||
- [Python 3.6.x](https://www.python.org/downloads/release/python-360/) or later
|
||||
|
||||
|
||||
- OSs:
|
||||
* Linux
|
||||
* Mac OSX
|
||||
* Windows: TBD / maybe
|
||||
|
||||
#### Install:
|
||||
- from [PyPI](https://pypi.python.org/pypi/batchmp): `$ pip install mktxp`
|
||||
- latest from source repository: `$ pip install git+https://github.com/akpw/mktxp`
|
||||
|
||||
|
||||
## Description
|
||||
Prometheus Exporter for Mikrotik RouterOS.
|
||||
MKTXP enables gathering metrics across multiple RouterOS devices, all easily configurable via built-in CLI interface.
|
||||
Comes along with a dedicated [Grafana dashboard](https://grafana.com/grafana/dashboards/13679)
|
||||
|
||||
|
||||
## Getting started
|
||||
Usage: $ mktxp [-h]
|
||||
{info, version, show, add, edit, delete, start}
|
||||
Commands:
|
||||
{info, version, show, add, edit, delete, start}
|
||||
|
||||
$ mktxp {command} -h #run this for detailed help on individual commands
|
||||
|
||||
|
||||
## Full description of CLI Commands
|
||||
### mktxp
|
||||
. action commands:
|
||||
.. start Starts collecting metrics for all enabled RouterOS configuration entries
|
||||
.. add Adds MKTXP RouterOS configuration entry
|
||||
.. show Shows MKTXP configuration entries
|
||||
.. delete Deletes a MKTXP RouterOS configuration entry
|
||||
.. edit Open MKTXP configuration file in your editor of choice
|
||||
.. info Shows base MKTXP info
|
||||
.. version Shows MKTXP version
|
||||
|
||||
|
||||
## Installing Development version
|
||||
- Clone the repo, then run: `$ python setup.py develop`
|
||||
|
||||
**Running Tests**
|
||||
- TDB
|
||||
- Run via: `$ python setup.py test`
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
|
||||
|
||||
from http.server import HTTPServer
|
||||
from datetime import datetime
|
||||
from prometheus_client.core import REGISTRY
|
||||
from prometheus_client import MetricsHandler, start_http_server
|
||||
from mktxp.cli.config.config import config_handler
|
||||
@@ -34,5 +35,6 @@ class MKTXPProcessor:
|
||||
def run(server_class=HTTPServer, handler_class=MetricsHandler, port = None):
|
||||
server_address = ('', port)
|
||||
httpd = server_class(server_address, handler_class)
|
||||
print(f'Running HTTP collector server on port {port}')
|
||||
current_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
||||
print(f'{current_time} Running metrics HTTP server on port {port}')
|
||||
httpd.serve_forever()
|
||||
|
||||
@@ -42,7 +42,9 @@ class MKTXPConfigKeys:
|
||||
FE_MONITOR_KEY = 'monitor'
|
||||
FE_ROUTE_KEY = 'route'
|
||||
FE_WIRELESS_KEY = 'wireless'
|
||||
FE_WIRELESS_CLIENTS_KEY = 'wireless_clients'
|
||||
FE_CAPSMAN_KEY = 'capsman'
|
||||
FE_CAPSMAN_CLIENTS_KEY = 'capsman_clients'
|
||||
|
||||
# UnRegistered entries placeholder
|
||||
NO_ENTRIES_REGISTERED = 'NoEntriesRegistered'
|
||||
@@ -58,7 +60,7 @@ class MKTXPConfigKeys:
|
||||
|
||||
BOOLEAN_KEYS = [ENABLED_KEY, SSL_KEY, SSL_CERTIFICATE,
|
||||
FE_DHCP_KEY, FE_DHCP_LEASE_KEY, FE_DHCP_POOL_KEY, FE_INTERFACE_KEY,
|
||||
FE_MONITOR_KEY, FE_ROUTE_KEY, FE_WIRELESS_KEY, FE_CAPSMAN_KEY]
|
||||
FE_MONITOR_KEY, FE_ROUTE_KEY, FE_WIRELESS_KEY, FE_WIRELESS_CLIENTS_KEY, FE_CAPSMAN_KEY, FE_CAPSMAN_CLIENTS_KEY]
|
||||
STR_KEYS = [HOST_KEY, USER_KEY, PASSWD_KEY]
|
||||
|
||||
# MKTXP config entry nane
|
||||
@@ -71,7 +73,8 @@ class ConfigEntry:
|
||||
MKTXPConfigKeys.SSL_KEY, MKTXPConfigKeys.SSL_CERTIFICATE,
|
||||
|
||||
MKTXPConfigKeys.FE_DHCP_KEY, MKTXPConfigKeys.FE_DHCP_LEASE_KEY, MKTXPConfigKeys.FE_DHCP_POOL_KEY, MKTXPConfigKeys.FE_INTERFACE_KEY,
|
||||
MKTXPConfigKeys.FE_MONITOR_KEY, MKTXPConfigKeys.FE_ROUTE_KEY, MKTXPConfigKeys.FE_WIRELESS_KEY, MKTXPConfigKeys.FE_CAPSMAN_KEY
|
||||
MKTXPConfigKeys.FE_MONITOR_KEY, MKTXPConfigKeys.FE_ROUTE_KEY, MKTXPConfigKeys.FE_WIRELESS_KEY, MKTXPConfigKeys.FE_WIRELESS_CLIENTS_KEY,
|
||||
MKTXPConfigKeys.FE_CAPSMAN_KEY, MKTXPConfigKeys.FE_CAPSMAN_CLIENTS_KEY
|
||||
])
|
||||
|
||||
class OSConfig(metaclass = ABCMeta):
|
||||
@@ -221,16 +224,3 @@ class MKTXPConfigHandler:
|
||||
|
||||
# Simplest possible Singleton impl
|
||||
config_handler = MKTXPConfigHandler()
|
||||
|
||||
|
||||
''' if not os.path.exists(self.usr_conf_data_path):
|
||||
# stage from the mktxp conf template
|
||||
lookup_path = resource_filename(Requirement.parse("mktxp"), "mktxp/cli/config/mktxp.conf")
|
||||
shutil.copy(lookup_path, self.usr_conf_data_path)
|
||||
|
||||
if not os.path.exists(self.mktxp_conf_path):
|
||||
# stage from the mktxp conf template
|
||||
lookup_path = resource_filename(Requirement.parse("mktxp"), "mktxp/cli/config/.mktxp.conf")
|
||||
shutil.copy(lookup_path, self.mktxp_conf_path)
|
||||
|
||||
'''
|
||||
|
||||
@@ -23,9 +23,6 @@
|
||||
use_ssl = False
|
||||
ssl_certificate = False
|
||||
|
||||
identity = True
|
||||
resource = True
|
||||
health = True
|
||||
dhcp = True
|
||||
dhcp_lease = True
|
||||
pool = True
|
||||
@@ -33,4 +30,6 @@
|
||||
monitor = True
|
||||
route = True
|
||||
wireless = True
|
||||
capsman = True
|
||||
wireless_clients = True
|
||||
capsman = True
|
||||
capsman_clients = True
|
||||
@@ -45,7 +45,9 @@ class MKTXPOptionsParser:
|
||||
self._script_name = 'MKTXP'
|
||||
self._description = \
|
||||
'''
|
||||
Prometheus Exporter for Mikrotik RouterOS Devices.
|
||||
Prometheus Exporter for Mikrotik RouterOS.
|
||||
Supports gathering metrics across multiple RouterOS devices, all easily configurable via built-in CLI interface.
|
||||
Comes along with a dedicated Grafana dashboard(https://grafana.com/grafana/dashboards/13679)
|
||||
|
||||
'''
|
||||
|
||||
|
||||
@@ -47,29 +47,46 @@ class CapsmanCollector(BaseCollector):
|
||||
registration_per_interface_metrics = BaseCollector.gauge_collector('capsman_registrations_count', 'Number of active registration per CAPsMAN interface', registration_per_interface_records, 'count', ['interface'])
|
||||
yield registration_per_interface_metrics
|
||||
|
||||
# translate / trim / augment registration records
|
||||
dhcp_lease_labels = ['mac_address', 'host_name', 'comment']
|
||||
dhcp_lease_records = router_metric.dhcp_lease_records(dhcp_lease_labels)
|
||||
for registration_record in registration_records:
|
||||
dhcp_lease_record = next((dhcp_lease_record for dhcp_lease_record in dhcp_lease_records if dhcp_lease_record['mac_address']==registration_record['mac_address']))
|
||||
if dhcp_lease_record:
|
||||
registration_record['name'] = dhcp_lease_record.get('comment', dhcp_lease_record.get('host_name', dhcp_lease_record.get('mac_address')))
|
||||
else:
|
||||
registration_record['name'] = registration_record['mac_address']
|
||||
|
||||
# split out tx/rx bytes
|
||||
registration_record['tx_bytes'] = registration_record['bytes'].split(',')[0]
|
||||
registration_record['rx_bytes'] = registration_record['bytes'].split(',')[1]
|
||||
del registration_record['bytes']
|
||||
# the client info metrics
|
||||
if router_metric.router_entry.capsman_clients:
|
||||
# translate / trim / augment registration records
|
||||
dhcp_lease_labels = ['mac_address', 'host_name', 'comment']
|
||||
dhcp_lease_records = router_metric.dhcp_lease_records(dhcp_lease_labels)
|
||||
for registration_record in registration_records:
|
||||
dhcp_lease_record = next((dhcp_lease_record for dhcp_lease_record in dhcp_lease_records if dhcp_lease_record['mac_address']==registration_record['mac_address']))
|
||||
if dhcp_lease_record:
|
||||
registration_record['name'] = dhcp_lease_record.get('comment', dhcp_lease_record.get('host_name', dhcp_lease_record.get('mac_address')))
|
||||
else:
|
||||
registration_record['name'] = registration_record['mac_address']
|
||||
|
||||
# split out tx/rx bytes
|
||||
registration_record['tx_bytes'] = registration_record['bytes'].split(',')[0]
|
||||
registration_record['rx_bytes'] = registration_record['bytes'].split(',')[1]
|
||||
del registration_record['bytes']
|
||||
|
||||
tx_byte_metrics = BaseCollector.counter_collector('capsman_traffic_tx_bytes', 'Number of sent packet bytes', registration_records, 'tx_bytes', ['name'])
|
||||
yield tx_byte_metrics
|
||||
|
||||
rx_byte_metrics = BaseCollector.counter_collector('capsman_traffic_rx_bytes', 'Number of received packet bytes', registration_records, 'rx_bytes', ['name'])
|
||||
yield rx_byte_metrics
|
||||
|
||||
signal_strength_metrics = BaseCollector.gauge_collector('capsman_registered_signal_strength', 'Registered devices signal strength', registration_records, 'rx_signal', ['name'])
|
||||
yield signal_strength_metrics
|
||||
|
||||
registration_metrics = BaseCollector.info_collector('capsman_registered_devices', 'Registered devices info',
|
||||
registration_records, ['name', 'rx_signal', 'ssid', 'tx_rate', 'rx_rate', 'interface', 'mac_address', 'uptime'])
|
||||
yield registration_metrics
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
tx_byte_metrics = BaseCollector.counter_collector('capsman_traffic_tx_bytes', 'Number of sent packet bytes', registration_records, 'tx_bytes', ['name'])
|
||||
yield tx_byte_metrics
|
||||
|
||||
rx_byte_metrics = BaseCollector.counter_collector('capsman_traffic_rx_bytes', 'Number of received packet bytes', registration_records, 'rx_bytes', ['name'])
|
||||
yield rx_byte_metrics
|
||||
|
||||
registration_metrics = BaseCollector.info_collector('capsman_registered_devices', 'Registered devices info',
|
||||
registration_records, ['name', 'rx_signal', 'ssid', 'tx_rate', 'rx_rate', 'interface', 'mac_address', 'uptime'])
|
||||
yield registration_metrics
|
||||
|
||||
|
||||
|
||||
@@ -36,3 +36,9 @@ class WLANCollector(BaseCollector):
|
||||
if tx_ccq_records:
|
||||
overall_tx_ccq_metrics = BaseCollector.gauge_collector('wlan_overall_tx_ccq', ' Client Connection Quality for transmitting', tx_ccq_records, 'overall_tx_ccq', ['channel'])
|
||||
yield overall_tx_ccq_metrics
|
||||
|
||||
|
||||
# the client info metrics
|
||||
if router_metric.router_entry.wireless_clients:
|
||||
# TBD
|
||||
pass
|
||||
Reference in New Issue
Block a user