diff --git a/environment/0_env/install.sh b/environment/0_env/install.sh
index 1833a42d441c911e3e0404574f0a9b65d1e22d64..b9b342a541c952fa875367fd341df91e40c79e93 100644
--- a/environment/0_env/install.sh
+++ b/environment/0_env/install.sh
@@ -46,7 +46,7 @@ check_requirements() {
touch "$requirements_log" || exit
### atomic-0.7.3 need cffi, we show install cffi first###
pip install --upgrade pip
- pip install cffi
+ pip install cffi scikit-learn
pip install -r requirements.txt | tee -a "${requirements_log}" || exit 1
local pip_res=$?
if [ $pip_res -ne 0 ]; then
diff --git a/sysom_server/sysom_vmcore/apps/vmcore/views.py b/sysom_server/sysom_vmcore/apps/vmcore/views.py
index b4ff9e9ff01e84e22662365a5973b18a1200d154..c76bd870dc5f3ace979e32ea4b08f9b7f6fef9d8 100644
--- a/sysom_server/sysom_vmcore/apps/vmcore/views.py
+++ b/sysom_server/sysom_vmcore/apps/vmcore/views.py
@@ -4,6 +4,8 @@ from rest_framework.viewsets import GenericViewSet
from rest_framework import mixins
from rest_framework.views import APIView
from django_filters.rest_framework import DjangoFilterBackend
+from sklearn.feature_extraction.text import TfidfVectorizer #将文本转换为TF-IDF向量。
+from sklearn.metrics.pairwise import cosine_similarity #用于计算余弦相似度
# from apps.accounts.permissions import IsAdminPermission
# from apps.accounts.authentication import Authentication
@@ -217,6 +219,12 @@ class VmcoreViewSet(GenericViewSet,
i = i + 1
return -1
+ # 定义函数,计算文件文本的相似度
+ def calculate_similarity(self, text1, text2):
+ vectorizer = TfidfVectorizer()
+ tfidf = vectorizer.fit_transform([text1, text2])
+ similarity = cosine_similarity(tfidf[0], tfidf[1])[0][0]
+ return similarity
def parse_calltrace(self,dmesg):
if len(dmesg) <= 0:
@@ -281,6 +289,11 @@ class VmcoreViewSet(GenericViewSet,
if fcnt > 1:
data = serializer.PanicListSerializer(last_name.vmcore).data
data['rate'] = round(fcnt*100/s2,2)
+ panic_objects = models.Panic.objects.filter(name=last_name.name)
+ for panic_obj in panic_objects:
+ dmesg_content = panic_obj.dmesg
+ data['similarity'] = round((self.calculate_similarity(str(dmesg_content), str(dmesg)))*100)
+
result.append(data)
#result[last_name]=(fcnt*100/s2)+fpow
last_idx=0
@@ -301,6 +314,11 @@ class VmcoreViewSet(GenericViewSet,
if fcnt > 1:
data = serializer.PanicListSerializer(calltrace_set.vmcore).data
data['rate'] = round(fcnt*100/s2,2)
+ panic_objects = models.Panic.objects.filter(name=last_name.name)
+ for panic_obj in panic_objects:
+ dmesg_content = panic_obj.dmesg
+ data['similarity'] = round((self.calculate_similarity(str(dmesg_content), str(dmesg)))*100)
+
result.append(data)
if len(result) > 0:
break
@@ -462,4 +480,4 @@ class VmcoreConfigTest(APIView):
class HealthViewset(GenericViewSet):
def health_check(self, request, *args, **kwargs):
- return success(result={})
\ No newline at end of file
+ return success(result={})
diff --git a/sysom_web/src/locales/en-US/pages.js b/sysom_web/src/locales/en-US/pages.js
index cadb45aa2da7d5feb10d92e711f0936a9fce2706..e3518b6f352d542ca547aa0f9a25d0b26f6548a9 100644
--- a/sysom_web/src/locales/en-US/pages.js
+++ b/sysom_web/src/locales/en-US/pages.js
@@ -385,6 +385,7 @@ export default {
'pages.vmcore.view': 'View',
'pages.vmcore.similarstack': 'Similar stack',
'pages.vmcore.similarity': 'Similarity',
+ 'pages.vmcore.textsimilarity': 'TextSimilarity',
'pages.vmcore.configuration': 'Current configuration:',
'pages.vmcore.warehousename': 'Warehouse name',
'pages.vmcore.warehousevmcore': 'Name of the warehouse where the vmcore is faulty',
@@ -512,4 +513,4 @@ export default {
'pages.monitor.components.podName': "POD Name",
'pages.monitor.components.namespace': "Namespace",
'pages.monitor.components.detail': "Detail",
-};
\ No newline at end of file
+};
diff --git a/sysom_web/src/locales/zh-CN/pages.js b/sysom_web/src/locales/zh-CN/pages.js
index 19874ad72aff046559cc01df39bba309d88d74d5..1cdc3d5e9d958cbf9771b08b2ceb06aa049a10a9 100644
--- a/sysom_web/src/locales/zh-CN/pages.js
+++ b/sysom_web/src/locales/zh-CN/pages.js
@@ -429,8 +429,9 @@ export default {
'pages.vmcore.solution': '解决方案',
'pages.vmcore.outagedetails': '宕机详情',
'pages.vmcore.view': '查看',
- 'pages.vmcore.similarstack': '相似调用栈',
- 'pages.vmcore.similarity': '相似度',
+ 'pages.vmcore.similarstack': '相似调用栈或全文日志',
+ 'pages.vmcore.similarity': '调用栈相似度',
+ 'pages.vmcore.textsimilarity': '全文日志相似度',
'pages.vmcore.configuration': '当前配置:',
'pages.vmcore.warehousename': '仓库名',
'pages.vmcore.warehousevmcore': '存储宕机vmcore的仓库名称',
@@ -619,4 +620,4 @@ export default {
'pages.diagnose.net.pcap.pcap-lost-segment': "丢包数(\\ms)",
'pages.diagnose.net.pcap.pcap-node': '节点',
-};
\ No newline at end of file
+};
diff --git a/sysom_web/src/pages/vmcore/Match/index.jsx b/sysom_web/src/pages/vmcore/Match/index.jsx
index dd08fc8f7b2883ca85747f6ac9e4bf5f95ab2334..5dee0ba81822af99f15598ee7151780ed63f03c7 100644
--- a/sysom_web/src/pages/vmcore/Match/index.jsx
+++ b/sysom_web/src/pages/vmcore/Match/index.jsx
@@ -84,6 +84,12 @@ const VmcoreMatch = () => {
hideInSearch: true,
valueType: "textarea",
},
+ {
+ title: ,
+ dataIndex: "similarity",
+ hideInSearch: true,
+ valueType: "textarea",
+ },
{
title: ,
dataIndex: "option",