summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhandingkang <[email protected]>2024-01-15 19:54:42 +0800
committerhandingkang <[email protected]>2024-01-15 19:54:42 +0800
commit576b2ee0d35be920645ab5d93d29ae56a09b96ab (patch)
treee990c1c5e45131cc2a0cec35e4078ea6ec3ec9d2
parentd397aaf0416e52c8a261b45eaf54bd29273b3eac (diff)
功能更新
-rw-r--r--apps/sysinfo.py34
-rw-r--r--script/neo4jcommand.py72
-rw-r--r--script/schedule.py0
3 files changed, 100 insertions, 6 deletions
diff --git a/apps/sysinfo.py b/apps/sysinfo.py
index 6f0c842..ab4e757 100644
--- a/apps/sysinfo.py
+++ b/apps/sysinfo.py
@@ -13,7 +13,7 @@ bp = APIBlueprint('sys', __name__, url_prefix='/sys', description='获取系统�
class DataAccess():
def __init__(self):
# mysql连接
- dbname = "configcache"
+ dbname = "v6dnsminer"
self.tabname = "config"
conn = pymysql.connect(host='localhost', user='root', password='Hdk19990815')
self.cursor = conn.cursor()
@@ -34,7 +34,7 @@ class DataAccess():
self.cursor.execute(tablesql)
# neo4j连接
- url = "neo4j://neo4j:[email protected]:7678"
+ url = "neo4j://neo4j:[email protected]:7678"
config.DATABASE_URL = url
db.set_connection(url)
@@ -43,7 +43,7 @@ da = DataAccess()
# 运行时间获取接口
[email protected]("/startday")
def sysdays():
sql = "SELECT info FROM %s WHERE name=%s" % (da.tabname, "startday")
da.cursor.execute(sql)
@@ -61,11 +61,33 @@ def sysdays():
# v6 dns计数接口
[email protected]("/v6count")
def sysv6count():
return {"code": 0, "data": {"count": len(model.NodeResolver53.nodes.filter(IPType="v6"))}, "msg": "success"}
@bp.get("/dual")
-def sysv6count():
- return {"code": 0, "data": {"count": len(model.NodeResolver53.nodes.filter(IPType="v6"))}, "msg": "success"}
+def sysdualcount():
+ return {"code": 0, "data": {"count": 3000}, "msg": "success"}
+
+
+def sysdatecount():
+ sql = "SELECT info FROM %s WHERE name=%s" % (da.tabname, "datecount")
+ da.cursor.execute(sql)
+ result = da.cursor.fetchall()
+ datecount = []
+ todaycount = len(model.NodeResolver53.nodes.filter(IPType="v6"))
+ # 不存在结果,插入当天统计
+ if len(result) == 0:
+ sql = "INSERT INTO %s(name,info) VALUES (%s,%s)" % (
+ da.tabname, "datecount",
+ str(datetime.date.today()) + "," + str(todaycount))
+ da.cursor.execute(sql)
+ datecount.append({"date": str(datetime.date.today()), "count": todaycount})
+ else:
+ for r in result:
+ date, count = str(r[1]).split(",")
+ datecount.append({"date": date, "count": count})
+ # 返回datecount列表
+ return {"code": 0, "data": {"list": datecount}, "msg": "success"}
diff --git a/script/neo4jcommand.py b/script/neo4jcommand.py
new file mode 100644
index 0000000..022aa5d
--- /dev/null
+++ b/script/neo4jcommand.py
@@ -0,0 +1,72 @@
+# 去重指令
+distinct = '''
+match (n:NodeResolver53)
+WITH n ORDER BY n.W DESC
+with n.IP as IP,collect(n) as nodes,count(*) as c
+where c>1
+CALL apoc.refactor.mergeNodes(nodes,
+{properties:'discard',mergeRels:true})
+YIELD node
+RETURN count(*)
+'''
+
+# 新建catelog
+gds_newgraph = '''
+CALL gds.graph.project(
+ 'myGraph',
+ 'NodeResolver53',
+ 'IP_LINK',
+ {
+ relationshipProperties: 'W'
+ }
+)
+'''
+
+# 删除旧的catelog
+gds_delgraph = '''
+CALL gds.graph.drop('myGraph', false) YIELD graphName
+'''
+
+# 高风险节点
+dangerous_nodes = '''
+CALL gds.pageRank.stream('myGraph')
+YIELD nodeId, score
+with gds.util.asNode(nodeId) as n
+WHERE n.IPType contains "6"
+RETURN n.IP as ip, n.ISP as isp,n.CCODE as ccode,n.COU as cou,n.PROV as prov, score
+ORDER BY score DESC, ip ASC,isp ASC,ccode ASC,cou ASC,prov ASC limit 30'''
+
+# 双栈服务数量统计
+dualcountcypher = '''
+ CALL gds.wcc.stream('myGraph')
+ YIELD nodeId,componentId
+ with componentId as cid,count(*) as c
+ where 1<c<5
+ with collect(cid) as cc
+ CALL gds.wcc.stream('myGraph')
+ YIELD nodeId,componentId
+ where componentId in cc
+ with gds.util.asNode(nodeId).IP as ip,componentId
+ where ip contains ":"
+ return count(distinct componentId)
+ '''
+# 双栈服务详细数据
+dualdatacypher = '''
+ CALL gds.wcc.stream('myGraph')
+ YIELD nodeId,componentId
+ with componentId as cid,count(*) as c
+ where 1<c<5
+ with collect(cid) as cc
+ CALL gds.wcc.stream('myGraph')
+ YIELD nodeId,componentId
+ where componentId in cc
+ with gds.util.asNode(nodeId).IP as ip,componentId
+ where ip contains ":"
+ with collect(componentId) as ccl
+ CALL gds.wcc.stream('myGraph')
+ YIELD nodeId,componentId
+ where componentId in ccl
+ with gds.util.asNode(nodeId) as n,componentId
+ return n.IP,n.ISP,n.COU,n.CCODE,n.PROV,n.LAT,n.LNG,componentId
+ order by componentId
+ '''
diff --git a/script/schedule.py b/script/schedule.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/script/schedule.py