diff options
| author | lijia <[email protected]> | 2019-08-26 18:39:31 +0800 |
|---|---|---|
| committer | lijia <[email protected]> | 2019-08-26 18:39:31 +0800 |
| commit | d7f3f505e2f48feea5efd7bccd2b5d209cf35541 (patch) | |
| tree | 3e3f67efee0c5e3a133726fe25c634be86314870 | |
| parent | b5f320eb9c7fc033d51c0a365623f95fdb2c0ee0 (diff) | |
update stream and protocol.
| -rw-r--r-- | deploy_etc/rsyslog.conf | 96 | ||||
| -rw-r--r-- | py_tools/tsg_monit_app.py (renamed from py_tools/tsg_monit_stream.py) | 0 | ||||
| -rw-r--r-- | py_tools/tsg_monit_protocol_v3.py | 172 | ||||
| -rw-r--r-- | service_script/certstore.service | 15 | ||||
| -rw-r--r-- | timer/monitor.service | 6 | ||||
| -rw-r--r-- | timer/monitor.timer | 12 | ||||
| -rw-r--r-- | timer/monitor.timer.sh | 5 | ||||
| -rw-r--r-- | timer/readme.txt | 3 |
8 files changed, 309 insertions, 0 deletions
diff --git a/deploy_etc/rsyslog.conf b/deploy_etc/rsyslog.conf new file mode 100644 index 0000000..68072af --- /dev/null +++ b/deploy_etc/rsyslog.conf @@ -0,0 +1,96 @@ +# rsyslog configuration file + +# For more information see /usr/share/doc/rsyslog-*/rsyslog_conf.html +# If you experience problems, see http://www.rsyslog.com/doc/troubleshoot.html + +#### MODULES #### + +# The imjournal module bellow is now used as a message source instead of imuxsock. +$ModLoad imuxsock # provides support for local system logging (e.g. via logger command) +$ModLoad imjournal # provides access to the systemd journal +#$ModLoad imklog # reads kernel messages (the same are read from journald) +#$ModLoad immark # provides --MARK-- message capability + +# Provides UDP syslog reception +#$ModLoad imudp +#$UDPServerRun 514 + +# Provides TCP syslog reception +#$ModLoad imtcp +#$InputTCPServerRun 514 + +#### GLOBAL DIRECTIVES #### + +# Where to place auxiliary files +$WorkDirectory /var/lib/rsyslog + +# Use default timestamp format +#$ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat +$template tsgformat,"%$NOW% %TIMESTAMP:8:15% %HOSTNAME% <%PRI%> [%syslogseverity-text%] %msg%\n" #定义模板 $template +$ActionFileDefaultTemplate tsgformat + +# File syncing capability is disabled by default. This feature is usually not required, +# not useful and an extreme performance hit +#$ActionFileEnableSync on + +# Include all config files in /etc/rsyslog.d/ +$IncludeConfig /etc/rsyslog.d/*.conf + +# Turn off message reception via local log socket; +# local messages are retrieved through imjournal now. +$OmitLocalLogging on + +# File to store the position in the journal +$IMJournalStateFile imjournal.state + + +#### RULES #### + +# Log all kernel messages to the console. +# Logging much else clutters up the screen. +#kern.* /dev/console + +# Log anything (except mail) of level info or higher. +# Don't log private authentication messages! +*.info;mail.none;authpriv.none;cron.none /var/log/messages + +# The authpriv file has restricted access. +authpriv.* /var/log/secure + +# Log all the mail messages in one place. +mail.* -/var/log/maillog + + +# Log cron stuff +cron.* /var/log/cron + +# Everybody gets emergency messages +*.emerg :omusrmsg:* + +# Save news errors of level crit and higher in a special file. +uucp,news.crit /var/log/spooler + +# Save boot messages also to boot.log +local7.* /var/log/boot.log + + +# ### begin forwarding rule ### +# The statement between the begin ... end define a SINGLE forwarding +# rule. They belong together, do NOT split them. If you create multiple +# forwarding rules, duplicate the whole block! +# Remote Logging (we use TCP for reliable delivery) +# +# An on-disk queue is created for this action. If the remote host is +# down, messages are spooled to disk and sent when it is up again. +#$ActionQueueFileName fwdRule1 # unique name prefix for spool files +#$ActionQueueMaxDiskSpace 1g # 1gb space limit (use as much as possible) +#$ActionQueueSaveOnShutdown on # save messages to disk on shutdown +#$ActionQueueType LinkedList # run asynchronously +$ActionResumeRetryCount -1 # infinite retries if host is down +# remote host is: name/ip:port, e.g. 192.168.0.1:514, port optional +#*.* @@remote-host:514 +#for UDP: +*.* @192.168.10.234:514 +#for TCP: +#*.* #@192.168.10.180:514 +# ### end of the forwarding rule ### diff --git a/py_tools/tsg_monit_stream.py b/py_tools/tsg_monit_app.py index ae75590..ae75590 100644 --- a/py_tools/tsg_monit_stream.py +++ b/py_tools/tsg_monit_app.py diff --git a/py_tools/tsg_monit_protocol_v3.py b/py_tools/tsg_monit_protocol_v3.py new file mode 100644 index 0000000..75bfd5c --- /dev/null +++ b/py_tools/tsg_monit_protocol_v3.py @@ -0,0 +1,172 @@ +#coding=utf-8
+#本文件获取kni fs2日志, 抽取可拦截、已拦截计数, 存入influxDB
+import sys
+import time
+import re
+import subprocess
+from sys import path
+path.append(r'../py_common') #将存放module的路径添加进来
+path.append(r'./py_common') #将存放module的路径添加进来
+from common_get_tags import *
+from common_whoami import *
+from common_system_cmd import *
+from common_telegraf import *
+from common_args import *
+from common_logger import *
+from common_get_tags import *
+
+G_KNI_FS2_FILE = "/home/tsg/kni/fs2_sysinfo.log"
+
+def find_expect_word_index(line_array, expect_word):
+ index = 0
+ for column in line_array:
+ if column == expect_word:
+ return index
+ else:
+ index += 1
+
+ return -1
+
+#根据fs2.log, 提取expect_word的sum和speed值
+#return value:
+#ret, sum, speed
+def get_sum_speed_from_fs2_matrix(filename, expect_word):
+ cmd_str = "cat %s | grep -A 2 %s" %(filename, expect_word)
+ ret, result = system_cmd_run(cmd_str)
+ if ret != 0:
+ print("no result for cmd: %s" %(cmd_str))
+ return 1, 0, 0
+
+ res = result.split('\n')
+ #print(res)
+
+ if len(res) != 3:
+ print("result lines is not 3!" %(res))
+ return 1, 0, 0
+
+ line = res[0].split()
+ index = find_expect_word_index(line, expect_word)
+ #后面的行有sum, speed, 多一列
+ index += 1
+
+ line = res[1].split()
+ sum = int(line[index])
+
+ line = res[2].split()
+ speed = int(line[index])
+
+ return 0, sum, speed
+
+def kni_protocol_init():
+ global telegraf_client
+
+ comm_arg_parser = setup_common_args()
+ arg_options = comm_arg_parser.parse_args()
+
+ telegraf_server_ip = arg_options.telegraf_ip
+ telegraf_server_port = int(arg_options.telegraf_port)
+ telegraf_tags = tsg_get_tags()
+
+ telegraf_client = telegraf_init(telegraf_server_ip, telegraf_server_port, telegraf_tags)
+
+ return 0
+
+def kni_protocol_fs2_stats():
+ metric_val = {}
+
+ key_word = "Ethernet_bps"
+ influxdb_field = "Eth_Bit"
+
+ ret, sum, speed = get_sum_speed_from_fs2_matrix(G_KNI_FS2_FILE, key_word)
+ if ret != 0:
+ print("get %s stat error" %(key_word))
+ sys.exit(1)
+ metric_val[influxdb_field] = speed
+
+ key_word = "Ethernet_pps"
+ influxdb_field = "Eth_Pkt"
+ ret, sum, speed = get_sum_speed_from_fs2_matrix(G_KNI_FS2_FILE, key_word)
+ if ret != 0:
+ print("get %s stat error" %(key_word))
+ sys.exit(1)
+ metric_val[influxdb_field] = speed
+
+ key_word = "IPv4_bps"
+ influxdb_field = "Ipv4_Bit"
+ ret, sum, speed = get_sum_speed_from_fs2_matrix(G_KNI_FS2_FILE, key_word)
+ if ret != 0:
+ print("get %s stat error" %(key_word))
+ sys.exit(1)
+ metric_val[influxdb_field] = speed
+
+ key_word = "IPv4_pps"
+ influxdb_field = "Ipv4_Pkt"
+ ret, sum, speed = get_sum_speed_from_fs2_matrix(G_KNI_FS2_FILE, key_word)
+ if ret != 0:
+ print("get %s stat error" %(key_word))
+ sys.exit(1)
+ metric_val[influxdb_field] = speed
+
+ key_word = "IPv6_bps"
+ influxdb_field = "Ipv6_Bit"
+ ret, sum, speed = get_sum_speed_from_fs2_matrix(G_KNI_FS2_FILE, key_word)
+ if ret != 0:
+ print("get %s stat error" %(key_word))
+ sys.exit(1)
+ metric_val[influxdb_field] = speed
+
+ key_word = "IPv6_pps"
+ influxdb_field = "Ipv6_Pkt"
+ ret, sum, speed = get_sum_speed_from_fs2_matrix(G_KNI_FS2_FILE, key_word)
+ if ret != 0:
+ print("get %s stat error" %(key_word))
+ sys.exit(1)
+ metric_val[influxdb_field] = speed
+
+ key_word = "TCP_bps"
+ influxdb_field = "Tcp_Bit"
+ ret, sum, speed = get_sum_speed_from_fs2_matrix(G_KNI_FS2_FILE, key_word)
+ if ret != 0:
+ print("get %s stat error" %(key_word))
+ sys.exit(1)
+ metric_val[influxdb_field] = speed
+
+ key_word = "TCP_pps"
+ influxdb_field = "Tcp_Pkt"
+ ret, sum, speed = get_sum_speed_from_fs2_matrix(G_KNI_FS2_FILE, key_word)
+ if ret != 0:
+ print("get %s stat error" %(key_word))
+ sys.exit(1)
+ metric_val[influxdb_field] = speed
+
+ key_word = "UDP_pps"
+ influxdb_field = "Udp_Bit"
+ ret, sum, speed = get_sum_speed_from_fs2_matrix(G_KNI_FS2_FILE, key_word)
+ if ret != 0:
+ print("get %s stat error" %(key_word))
+ sys.exit(1)
+ metric_val[influxdb_field] = speed
+
+ key_word = "UDP_bps"
+ influxdb_field = "Udp_Pkt"
+ ret, sum, speed = get_sum_speed_from_fs2_matrix(G_KNI_FS2_FILE, key_word)
+ if ret != 0:
+ print("get %s stat error" %(key_word))
+ sys.exit(1)
+ metric_val[influxdb_field] = speed
+
+ #print(metric_val)
+ return metric_val
+
+
+if __name__ == '__main__':
+ kni_protocol_init()
+ metric_val = kni_protocol_fs2_stats()
+
+ telegraf_client.metric('protocol', metric_val, tags = {})
+
+
+
+
+
+
\ No newline at end of file diff --git a/service_script/certstore.service b/service_script/certstore.service new file mode 100644 index 0000000..f0493c1 --- /dev/null +++ b/service_script/certstore.service @@ -0,0 +1,15 @@ +[Unit]
+Description=certstore module
+Requires=mrtunnat.service
+After=mrtunnat.service
+
+[Service]
+WorkingDirectory=/home/ceiec/certstore
+ExecStart=/home/ceiec/certstore/certstore --normal
+#ExecStop=/home/tsg/kni/kni_service_scipt stop
+#Type=forking
+Restart=always
+RestartSec=5s
+
+[Install]
+WantedBy=multi-user.target
\ No newline at end of file diff --git a/timer/monitor.service b/timer/monitor.service new file mode 100644 index 0000000..30ba829 --- /dev/null +++ b/timer/monitor.service @@ -0,0 +1,6 @@ +[Unit]
+Description=monitor service
+
+[Service]
+Type=simple
+ExecStart=/opt/tsg/monitor/monitor.timer.sh
diff --git a/timer/monitor.timer b/timer/monitor.timer new file mode 100644 index 0000000..fc1b8c0 --- /dev/null +++ b/timer/monitor.timer @@ -0,0 +1,12 @@ +[Unit]
+Description=run monitor every 10s
+
+[Timer]
+# Time to wait after enable this unit
+OnActiveSec=1
+# Time between running each consecutive time
+OnUnitActiveSec=10
+Unit=monitor.service
+
+[Install]
+WantedBy=multi-user.target
diff --git a/timer/monitor.timer.sh b/timer/monitor.timer.sh new file mode 100644 index 0000000..9df9ac2 --- /dev/null +++ b/timer/monitor.timer.sh @@ -0,0 +1,5 @@ +#!/bin/sh
+/opt/tsg/bin/tsg_update_tags
+/opt/tsg/bin/tsg_monit_device --telegraf-ip 127.0.0.1 --telegraf-port 8126
+/opt/tsg/bin/tsg_monit_stream --telegraf-ip 127.0.0.1 --telegraf-port 8126
+echo "monitor" >> /tmp/moniotr.log
diff --git a/timer/readme.txt b/timer/readme.txt new file mode 100644 index 0000000..4fe8655 --- /dev/null +++ b/timer/readme.txt @@ -0,0 +1,3 @@ +��timer��ֳ����֣�
+һ��������ִ������˳��ģ�
+һ������Ҫsleepһ�ᣬ�ֱ��ȡ���������ֵ�ģ�����ifconfig��speed, �������syslog����speed
\ No newline at end of file |
