summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLu Qiuwen <[email protected]>2023-08-21 16:03:03 +0800
committerLu Qiuwen <[email protected]>2023-08-21 16:03:03 +0800
commit85d22ea8fbd0bdbbb76a2e528af9f6ab9f558ba0 (patch)
tree53c147c4fbf02c370857285d10001cf792478e8e
parent11e07c53c5d09d71f659ecc061cca9bf235924e0 (diff)
增加应用逐线程的收、发、丢包计数的Prometheus输出。v4.6.44-20230823
-rwxr-xr-xtools/monit_stream/monit_stream.py72
1 files changed, 66 insertions, 6 deletions
diff --git a/tools/monit_stream/monit_stream.py b/tools/monit_stream/monit_stream.py
index f98e35c..58736d3 100755
--- a/tools/monit_stream/monit_stream.py
+++ b/tools/monit_stream/monit_stream.py
@@ -65,11 +65,23 @@ TITLE_PROMETHEUS_MAP = {'RxOnline': 'rx_on_line_total',
'FTxBits': 'ftx_bits_total'
}
+TITLE_PROMETHEUS_PER_STREAM_MAP = {'RxOnline': 'rx_on_line_per_stream',
+ 'RxPkts': 'rx_pkts_per_stream',
+ 'RxDrops': 'rx_drops_per_stream',
+ 'RxBits': 'rx_bits_per_stream',
+ 'TxOnline': 'tx_on_line_per_stream',
+ 'TxPkts': 'tx_pkts_per_stream',
+ 'TxDrops': 'tx_drops_per_stream',
+ 'TxBits': 'tx_total_per_stream',
+ 'FTXOnline': 'ftx_on_line_per_stream',
+ 'FTxPkts': 'ftx_pkts_per_stream',
+ 'FTxDrops': 'ftx_missed_per_stream',
+ 'FTxBits': 'ftx_bits_per_stream'
+ }
def locate_vector_by_symbol(vector, symbol):
return [s for s in vector if s['symbol'] == symbol]
-
def list_all_vdev(json_fp):
return [s['symbol'] for s in json_fp['raw']]
@@ -136,6 +148,34 @@ def dump_one_device(json_fp, devsym, title_vector_rx, title_vector_tx, speed):
return ValueListSum
+def dump_one_device_per_stream(json_fp, devsym, title_vector_rx, title_vector_tx, speed):
+
+ __rd_function = vdev_value_read if speed == 0 else vdev_speed_read
+
+ ValueTable = []
+ ValueListSum = [0] * len(title_vector_rx + title_vector_tx)
+ nr_rxstream, nr_txstream = vdev_streams_read(json_fp, devsym)
+
+ for stream_id in range(max(nr_rxstream, nr_txstream)):
+ ValueList = []
+
+ for item in title_vector_rx:
+ value = __rd_function(json_fp, devsym, TITLE_MAP[item])[stream_id] \
+ if stream_id < nr_rxstream else 0
+ ValueList.append(value)
+
+ for item in title_vector_tx:
+ value = __rd_function(json_fp, devsym, TITLE_MAP[item])[stream_id] \
+ if stream_id < nr_txstream else 0
+ ValueList.append(value)
+
+ ValueTable.append(ValueList)
+ for i, v in enumerate(ValueList):
+ ValueListSum[i] += v
+
+ ValueTable.append(ValueListSum)
+ return ValueTable
+
def dump_summary_table(json_fp, appsym, devsym, title_vector_rx, title_vector_tx,
is_human_number=0, speed=0):
@@ -347,7 +387,8 @@ def check_vdev_options(json_fp, r_option):
class PrometheusClient(BaseHTTPRequestHandler):
- def transfer_valuelist_to_prometheus_fmt(self, title_vec, value_list, app, device):
+ @staticmethod
+ def transfer_values_to_prometheus_fmt(title_vec, value_list, app, device):
output = ""
for id, value in enumerate(value_list):
@@ -357,6 +398,18 @@ class PrometheusClient(BaseHTTPRequestHandler):
return output
+ @staticmethod
+ def transfer_values_per_stream_to_prometheus_fmt(title_vec, value_list, app, device):
+ output = ""
+
+ for stream_id, value in enumerate(value_list):
+ for metric_id, stream_value in enumerate(value):
+ prometheus_metric_name = TITLE_PROMETHEUS_PER_STREAM_MAP[title_vec[metric_id]]
+ output += "%s{app=\"%s\", device=\"%s\", stream_id=\"%d\"} %u\n" % (
+ prometheus_metric_name, app, device, stream_id, stream_value)
+
+ return output
+
def do_construct_response(self):
try:
applist = app_symbol_load()
@@ -373,10 +426,17 @@ class PrometheusClient(BaseHTTPRequestHandler):
vdev_list = list_all_vdev(app_json_fp)
for dev in vdev_list:
- ValueListSum = dump_one_device(
+ value_list_sum = dump_one_device(
app_json_fp, dev, title_vec_rx, title_vec_tx, 0)
- output += self.transfer_valuelist_to_prometheus_fmt(
- title_vec, ValueListSum, app, dev)
+
+ output += self.transfer_values_to_prometheus_fmt(
+ title_vec, value_list_sum, app, dev)
+
+ value_list_per_stream = dump_one_device_per_stream(
+ app_json_fp, dev, title_vec_rx, title_vec_tx, 0)
+
+ output += self.transfer_values_per_stream_to_prometheus_fmt(
+ title_vec, value_list_per_stream, app, dev)
return output
@@ -388,7 +448,7 @@ class PrometheusClient(BaseHTTPRequestHandler):
return ""
def do_GET(self):
- if (self.path == '/metrics'):
+ if self.path == '/metrics':
resp = self.do_construct_response()
self.send_response(200)
self.send_header('Content-type', 'text/plain; version=0.0.4')