最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

基于python3抓取pinpoint應(yīng)用信息入庫(kù)

 更新時(shí)間:2020年01月08日 08:26:38   作者:whitesky-root  
這篇文章主要介紹了基于python3抓取pinpoint應(yīng)用信息入庫(kù),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下

這篇文章主要介紹了基于python3抓取pinpoint應(yīng)用信息入庫(kù),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下

Pinpoint是用Java編寫的大型分布式系統(tǒng)的APM(應(yīng)用程序性能管理)工具。 受Dapper的啟發(fā),Pinpoint提供了一種解決方案,通過(guò)在分布式應(yīng)用程序中跟蹤事務(wù)來(lái)幫助分析系統(tǒng)的整體結(jié)構(gòu)以及它們中的組件之間的相互關(guān)系.

pinpoint api:

  • /applications.pinpoint 獲取applications基本信息
  • /getAgentList.pinpoint 獲取對(duì)應(yīng)application agent信息
  • /getServerMapData.pinpoint 獲取對(duì)應(yīng)app 基本數(shù)據(jù)流信息

db.py

import mysql.connector
class MyDB(object):
 """docstring for MyDB"""
 def __init__(self, host, user, passwd , db):
  self.host = host
  self.user = user
  self.passwd = passwd
  self.db = db

  self.connect = None
  self.cursor = None
 def db_connect(self):
  """數(shù)據(jù)庫(kù)連接
  """
  self.connect = mysql.connector.connect(host=self.host, user=self.user, passwd=self.passwd, database=self.db)
  return self
 def db_cursor(self):
  if self.connect is None:
   self.connect = self.db_connect()

  if not self.connect.is_connected():
   self.connect = self.db_connect()
  self.cursor = self.connect.cursor()
  return self
 def get_rows(self , sql):
  """ 查詢數(shù)據(jù)庫(kù)結(jié)果
  :param sql: SQL語(yǔ)句
  :param cursor: 數(shù)據(jù)庫(kù)游標(biāo)
  """
  self.cursor.execute(sql)
  return self.cursor.fetchall()
 def db_execute(self, sql):
  self.cursor.execute(sql)
  self.connect.commit()
 def db_close(self):
  """關(guān)閉數(shù)據(jù)庫(kù)連接和游標(biāo)
  :param connect: 數(shù)據(jù)庫(kù)連接實(shí)例
  :param cursor: 數(shù)據(jù)庫(kù)游標(biāo)
  """
  if self.connect:
   self.connect.close()
  if self.cursor:
   self.cursor.close()

pinpoint.py:

# -*- coding: utf-8 -*-

'''
Copyright (c) 2018, mersap
All rights reserved.

摘 要: pinpoint.py
創(chuàng) 建 者: mersap
創(chuàng)建日期: 2019-01-17
'''

import sys
import requests
import time
import datetime
import json

sys.path.append('../Golf')
import db #db.py

PPURL = "https://pinpoint.*******.com"


From_Time = datetime.datetime.now() + datetime.timedelta(seconds=-60)
To_Time = datetime.datetime.now()
From_TimeStamp = int(time.mktime(From_Time.timetuple()))*1000
To_TimeStamp = int(time.mktime(datetime.datetime.now().timetuple()))*1000


class PinPoint(object):
 """docstring for PinPoint"""
 def __init__(self, db):
  self.db = db
  super(PinPoint, self).__init__()

 """獲取pinpoint中應(yīng)用"""
 def get_applications(self):
  '''return application dict
  '''
  applicationListUrl = PPURL + "/applications.pinpoint"
  res = requests.get(applicationListUrl)
  if res.status_code != 200:
   print("請(qǐng)求異常,請(qǐng)檢查")
   return
  applicationLists = []
  for app in res.json():
   applicationLists.append(app)
  applicationListDict={}
  applicationListDict["applicationList"] = applicationLists
  return applicationListDict
 def getAgentList(self, appname):
  AgentListUrl = PPURL + "/getAgentList.pinpoint"
  param = {
   'application':appname
  }
  res = requests.get(AgentListUrl, params=param)
  if res.status_code != 200:
   print("請(qǐng)求異常,請(qǐng)檢查")
   return
  return len(res.json().keys()),json.dumps(list(res.json().keys()))
  
 def update_servermap(self, appname , from_time=From_TimeStamp,
       to_time=To_TimeStamp, serviceType='SPRING_BOOT'):
  '''更新app上下游關(guān)系
  :param appname: 應(yīng)用名稱
  :param serviceType: 應(yīng)用類型
  :param from_time: 起始時(shí)間
  :param to_time: 終止時(shí)間
  :
  '''
  #https://pinpoint.*****.com/getServerMapData.pinpoint?applicationName=test-app&from=1547721493000&to=1547721553000&callerRange=1&calleeRange=1&serviceTypeName=TOMCAT&_=1547720614229
  param = {
   'applicationName':appname,
   'from':from_time,
   'to':to_time,
   'callerRange':1,
   'calleeRange':1,
   'serviceTypeName':serviceType
  }

  # serverMapUrl = PPURL + "/getServerMapData.pinpoint"
  serverMapUrl = "{}{}".format(PPURL, "/getServerMapData.pinpoint")
  res = requests.get(serverMapUrl, params=param)
  if res.status_code != 200:
   print("請(qǐng)求異常,請(qǐng)檢查")
   return
  update_time = time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time()))
  links = res.json()["applicationMapData"]["linkDataArray"]
  for link in links :
   ###排除test的應(yīng)用
   if link['sourceInfo']['applicationName'].startswith('test'):
    continue
   #應(yīng)用名稱、應(yīng)用類型、下游應(yīng)用名稱、下游應(yīng)用類型、應(yīng)用節(jié)點(diǎn)數(shù)、下游應(yīng)用節(jié)點(diǎn)數(shù)、總請(qǐng)求數(shù)、 錯(cuò)誤請(qǐng)求數(shù)、慢請(qǐng)求數(shù)(本應(yīng)用到下一個(gè)應(yīng)用的數(shù)量)
   application = link['sourceInfo']['applicationName']
   serviceType = link['sourceInfo']['serviceType']
   to_application = link['targetInfo']['applicationName']
   to_serviceType = link['targetInfo']['serviceType']
   agents = len(link.get('fromAgent',' '))
   to_agents = len(link.get('toAgent',' '))
   totalCount = link['totalCount']
   errorCount = link['errorCount']
   slowCount = link['slowCount']

   sql = """
    REPLACE into application_server_map (application, serviceType, 
    agents, to_application, to_serviceType, to_agents, totalCount, 
    errorCount,slowCount, update_time, from_time, to_time) 
    VALUES ("{}", "{}", {}, "{}", "{}", {}, {}, {}, {},"{}","{}",
    "{}")""".format(
     application, serviceType, agents, to_application, 
     to_serviceType, to_agents, totalCount, errorCount,
      slowCount, update_time, From_Time, To_Time)
   self.db.db_execute(sql)

 def update_app(self):
  """更新application
  """
  appdict = self.get_applications()
  apps = appdict.get("applicationList")
  update_time = time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time()))
  for app in apps:
   if app['applicationName'].startswith('test'):
    continue
   agents, agentlists = self.getAgentList(app['applicationName'])
   sql = """
    REPLACE into application_list( application_name, 
    service_type, code, agents, agentlists, update_time) 
    VALUES ("{}", "{}", {}, {}, '{}', "{}");""".format(
     app['applicationName'], app['serviceType'], 
     app['code'], agents, agentlists, update_time)
   self.db.db_execute(sql)
  return True

 def update_all_servermaps(self):
  """更新所有應(yīng)用數(shù)
  """
  appdict = self.get_applications()
  apps = appdict.get("applicationList")
  for app in apps:
   self.update_servermap(app['applicationName'], serviceType=app['serviceType'])
  ###刪除7天前數(shù)據(jù)
  Del_Time = datetime.datetime.now() + datetime.timedelta(days=-7)

  sql = """delete from application_server_map where update_time <= "{}"
  """.format(Del_Time)
  self.db.db_execute(sql)
  return True


def connect_db():
 """ 建立SQL連接
 """
 mydb = db.MyDB(
   host="rm-*****.mysql.rds.aliyuncs.com",
   user="user",
   passwd="passwd",
   db="pinpoint"
   )
 mydb.db_connect()
 mydb.db_cursor()
 return mydb

def main():
 db = connect_db()
 pp = PinPoint(db)
 pp.update_app()
 pp.update_all_servermaps()
 db.db_close()


if __name__ == '__main__':
 main()

附sql語(yǔ)句

CREATE TABLE `application_list` (
 `application_name` varchar(32) NOT NULL,
 `service_type` varchar(32) DEFAULT NULL COMMENT '服務(wù)類型',
 `code` int(11) DEFAULT NULL COMMENT '服務(wù)類型代碼',
 `agents` int(11) DEFAULT NULL COMMENT 'agent個(gè)數(shù)',
 `agentlists` varchar(256) DEFAULT NULL COMMENT 'agent list',
 `update_time` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP COMMENT '更新時(shí)間',
 PRIMARY KEY (`application_name`),
 UNIQUE KEY `Unique_App` (`application_name`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='pinpoint app list'

CREATE TABLE `application_server_map` (
 `application` varchar(32) NOT NULL COMMENT '應(yīng)用名稱',
 `serviceType` varchar(8) NOT NULL,
 `agents` int(2) NOT NULL COMMENT 'agent個(gè)數(shù)',
 `to_application` varchar(32) NOT NULL COMMENT '下游服務(wù)名稱',
 `to_serviceType` varchar(32) DEFAULT NULL COMMENT '下游服務(wù)類型',
 `to_agents` int(2) DEFAULT NULL COMMENT '下游服務(wù)agent數(shù)量',
 `totalCount` int(8) DEFAULT NULL COMMENT '總請(qǐng)求數(shù)',
 `errorCount` int(8) DEFAULT NULL,
 `slowCount` int(8) DEFAULT NULL,
 `update_time` datetime NOT NULL ON UPDATE CURRENT_TIMESTAMP,
 `from_time` datetime DEFAULT NULL,
 `to_time` datetime DEFAULT NULL,
 PRIMARY KEY (`application`,`to_application`),
 UNIQUE KEY `Unique_AppMap` (`application`,`to_application`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='應(yīng)用鏈路數(shù)據(jù)'

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Python實(shí)現(xiàn)二維數(shù)組輸出為圖片

    Python實(shí)現(xiàn)二維數(shù)組輸出為圖片

    下面小編就為大家分享一篇Python實(shí)現(xiàn)二維數(shù)組輸出為圖片,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2018-04-04
  • Python 解析XML文件

    Python 解析XML文件

    google一篇關(guān)于Python解析XML文件的博文不過(guò)XML文件出錯(cuò),整理如下。
    2009-04-04
  • python調(diào)用Delphi寫的Dll代碼示例

    python調(diào)用Delphi寫的Dll代碼示例

    這篇文章主要介紹了python調(diào)用Delphi寫的Dll代碼示例,具有一定參考價(jià)值,需要的朋友可以了解下。
    2017-12-12
  • python腳本執(zhí)行CMD命令并返回結(jié)果的例子

    python腳本執(zhí)行CMD命令并返回結(jié)果的例子

    今天小編就為大家分享一篇python腳本執(zhí)行CMD命令并返回結(jié)果的例子,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2019-08-08
  • Pandas導(dǎo)入導(dǎo)出excel、csv、txt文件教程

    Pandas導(dǎo)入導(dǎo)出excel、csv、txt文件教程

    Pandas?是一個(gè)強(qiáng)大的數(shù)據(jù)分析和處理庫(kù),可以用來(lái)讀取和處理多種數(shù)據(jù)格式,本文主要介紹了Pandas導(dǎo)入導(dǎo)出excel、csv、txt文件教程,具有一定的參考價(jià)值,感興趣的可以了解一下
    2024-04-04
  • Python中assert函數(shù)的使用(含源代碼)

    Python中assert函數(shù)的使用(含源代碼)

    本文主要介紹了Python中assert函數(shù)的使用(含源代碼),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2023-04-04
  • pycharm中導(dǎo)入模塊錯(cuò)誤時(shí)提示Try to run this command from the system terminal

    pycharm中導(dǎo)入模塊錯(cuò)誤時(shí)提示Try to run this command from the system ter

    這篇文章主要介紹了pycharm中導(dǎo)入模塊錯(cuò)誤時(shí)提示Try to run this command from the system terminal問(wèn)題,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-03-03
  • 使用Python制作新型冠狀病毒實(shí)時(shí)疫情圖

    使用Python制作新型冠狀病毒實(shí)時(shí)疫情圖

    最近被新型冠狀病毒搞的人心惶惶,很多城市被病毒感染,今天小編給大家分享使用Python制作新型冠狀病毒實(shí)時(shí)疫情圖,感興趣的朋友跟隨小編一起看看吧
    2020-01-01
  • python pytorch模型轉(zhuǎn)onnx模型的全過(guò)程(多輸入+動(dòng)態(tài)維度)

    python pytorch模型轉(zhuǎn)onnx模型的全過(guò)程(多輸入+動(dòng)態(tài)維度)

    這篇文章主要介紹了python pytorch模型轉(zhuǎn)onnx模型的全過(guò)程(多輸入+動(dòng)態(tài)維度),本文給大家記錄記錄了pt文件轉(zhuǎn)onnx全過(guò)程,簡(jiǎn)單的修改即可應(yīng)用,結(jié)合實(shí)例代碼給大家介紹的非常詳細(xì),感興趣的朋友一起看看吧
    2024-03-03
  • 詳解Python是如何處理不同時(shí)區(qū)的

    詳解Python是如何處理不同時(shí)區(qū)的

    時(shí)區(qū)是指在地球上不同地方的時(shí)間差異,地球分為?24?個(gè)時(shí)區(qū),每個(gè)時(shí)區(qū)都相對(duì)于格林威治標(biāo)準(zhǔn)時(shí)間或協(xié)調(diào)世界時(shí)(UTC)有所偏移。本文主要和大家來(lái)聊聊Python是如何處理不同時(shí)區(qū)的,希望對(duì)大家有所幫助
    2023-02-02

最新評(píng)論

磴口县| 方正县| 师宗县| 阿勒泰市| 石首市| 丹棱县| 都匀市| 巫溪县| 石首市| 蒲城县| 高青县| 视频| 郁南县| 辽宁省| 通许县| 杭锦旗| 琼中| 遂川县| 宣威市| 克拉玛依市| 利津县| 梁山县| 怀集县| 都江堰市| 汶上县| 东台市| 东宁县| 固原市| 陆良县| 怀化市| 凤阳县| 云林县| 四会市| 雷州市| 永州市| 天台县| 攀枝花市| 榆树市| 紫阳县| 溆浦县| 石台县|