一、下载oracle安装包 此处省略,可以注册oracle官网地址或者从其他渠道获取 二、build docker镜像 1、克隆oracle官方镜像构建工程,地址如下 https://github.com/oracle/docker-images.git 2、进入构建目录,例如 /home/software/oracle-docker/docker-images/OracleDatabase/Si […]
作者:mowkeeper
pymysql查询datetime类型默认返回字符串配置方法
如果mysql表的字段类型是datetime,使用pymysql查询返回结果中这个字段的默认类型是datetime类型,不利于和原始数据进行对比,为此可以通过在建立connect的时候,传递conv参数从根本上解决这问题,如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
import pymysql from pymysql import converters,FIELD_TYPE conv = converters.conversions conv[FIELD_TYPE.NEWDECIMAL] = float # convert decimals to float conv[FIELD_TYPE.DATE] = str # convert dates to strings conv[FIELD_TYPE.TIMESTAMP] = str # convert dates to strings conv[FIELD_TYPE.DATETIME] = str # convert dates to strings conv[FIELD_TYPE.TIME] = str # convert dates to strings conn = pymysql.connect(**dict_conn, conv=conv) |
添加这些配置之后,默认cursor.execute返回的结果,dateime字段默认就是str格式的 转 […]
php打日志
虚无,真谛 file_put_contents('/tmp/php_debug.log', print_r($info, true), FILE_APPEND);
node-exporter无法获取cpu信息的一个案例
没什么,真没什么 1、现象 获取不到cpu的信息 2、原因 node-exporter开启了processes信息的获取(添加了启动参数--collector.processes),但是/proc/stat中processes信息是错误的 这里应该是个正值,但是现在却变为负数了,所以处理异常。 二期这还是某个os自己改内核出来的bug,虽然新版已经修复了,但是还很多机器跑在有问题的kernel版本 […]
prometheus基础部署使用
关于prometheus的介绍网上有很多详细的资料和整套的书籍,因为接触的晚,偶有用到,所以整理一下最基础的部署和使用,以便归档 一、安装prometheus 1、根据平台类型直接下载二进制包 2、解压后将包中的所有文件都移动到/usr/local/prometheus便于统一管理 3、启动应用 可以直接手动拉起,或者配置systemctl服务来监管,根据使用环境选择 (1)通过systemctl […]
python模块被import时获取caller的信息进行初始化
主要目的是将重复定义的模块独立出来,便于其他脚本直接引用,减少反复定义的问题 module1:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
import os,sys import inspect if __name__ == '__main__': pass else: # python3 if sys.version>'3': frm_list = inspect.stack() for item in frm_list: if item.index is None: # print(item) continue else: if __file__ in item.filename: # print(item) continue else: # print(item) frm = item mod = inspect.getmodule(frm[0]) t_file = str(os.path.abspath(mod.__file__)) # python2 else: frm_list = inspect.stack() mod = inspect.getmodule(frm_list[1][0]) t_file = str(os.path.abspath(mod.__file__)) t_list = [1,2,3] t_dict = {"k1":"v1"} |
module2:
1 2 3 4 5 6 7 8 9 10 11 |
import time from module1 import * # print(t_name) print(id(t_file),t_file) print(id(t_list),t_list) print(id(t_dict),t_dict) time.sleep(10) |
分别运行module2,返回结果如下:
1 2 3 4 5 6 7 8 9 10 11 |
# python2 module2.py (139742777226544, '/home/software/boofuzz/ft_local/module2.py') (139742781893304, [1, 2, 3]) (139742781927784, {'k1': 'v1'}) python3 module2.py 139720418778448 /home/software/boofuzz/ft_local/module2.py 139720418165064 [1, 2, 3] 139720421308600 {'k1': 'v1'} |
参考: https: […]
vscode不能自动补全import对象的方法
1、检查插件是否已经安装 Python Extension Pack,Python Extended,Python Path 2、添加2个额外的配置 在setting.json中,增加两个变量
1 2 3 4 5 6 7 8 |
"python.autoComplete.extraPaths": [ "/home/myTest" ], "python.analysis.extraPaths": [ "/home/myTest" ] |
参考地址 https://github.com/microsoft/python-language-server/blob/master/T […]
kazoo操作zookeeper基本功能的记录
任何数字化的信息在若干年后都会变成废品
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# coding: utf-8 from kazoo.client import KazooClient, NoNodeError zk = KazooClient(hosts="192.168.1.1:2181") zk.start() node_path_tpl = "/test1/resources/rsip@{ip}/rsport@{port}" # 从文件读取信息 # ip:port # with open("ip.list", "r") as f: # node_list = f.readlines() # 直接从zk获取信息 node_list = [] rsip_list = zk.get_children("/test1/resources") for rsip in rsip_list: _, host = rsip.split("@") rsport_list = zk.get_children("/test1/resources" + "/" + rsip) for rsport in rsport_list: _, port = rsport.split("@") node_list.append("{}:{}".format(host, port)) for item in node_list: sub_node_list = [] ip, port = item.replace("\n", "").split(":") node_path = node_path_tpl.format(ip=ip, port=port) print(node_path) # 获取所有子节点 # 方法1: 直接返回异常 # try: # if zk.exists(node_path): # sub_node_list = zk.get_children(node_path) # else: # print("(ne){}".format(node_path)) # except NoNodeError: # continue # 方法2: 通过zstat获取 if zk.exists(node_path): _, state = zk.get(node_path) if state.numChildren != 0: sub_node_list = zk.get_children(node_path) else: zk.ensure_path(node_path) # 子节点不为空,删除所有子节点 for sub_item in sub_node_list: sub_node_path = node_path + "/" + sub_item print("\t" + sub_node_path) # zk.delete(sub_node_path, recursive=True) zk.stop() zk.close() |