YONGFEIUALL

izheyi.com


  • Home

  • Archives

  • Categories

  • Tags

  • About

  • Search

Prometheus + Grafana 实时监控Windows

Posted on 2020-04-05 | In Performance Testing |

Prometheus 是一个最初在SoundCloud上构建的开源系统监视和警报工具包。
Grafana 是一个跨平台的开源的度量分析和可视化工具,可以通过将采集的数据查询然后可视化的展示,并及时通知。

Windows采集器(wmi_exporter)

要获取服务器运行时的参数,比如当前的CPU负载、内存消耗、硬盘使用、网络IO等等,就可以在服务器上运行一个node_exporter,它能把这些参数收集好,并且暴露出一个HTTP接口以便你访问查询。

  1. 下载采集器
    从wmi_exporter下载
  2. 安装
    直接双击安装即可。
    Windows默认9182端口。
  3. 验证
    访问http://127.0.0.1:9182/metrics
    显示以下数据,数据采集器安装成功。

Prometheus

  1. 下载
    从Prometheus下载
  2. 配置
    打开prometheus.yml

    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
    # my global config
    global:
    scrape_interval: 5s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
    evaluation_interval: 5s # Evaluate rules every 15 seconds. The default is every 1 minute.
    # scrape_timeout is set to the global default (10s).

    # Alertmanager configuration
    alerting:
    alertmanagers:
    - static_configs:
    - targets:
    # - alertmanager:9093

    # Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
    rule_files:
    # - "first_rules.yml"
    # - "second_rules.yml"

    # A scrape configuration containing exactly one endpoint to scrape:
    # Here it's Prometheus itself.
    scrape_configs:
    # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
    - job_name: 'prometheus'

    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.

    static_configs:
    - targets: ['localhost:9182']

  3. 运行(将默认端口9090改为8091)

    1
    prometheus.exe --config.file=prometheus.yml --web.listen-address=:8091 &
  4. 验证
    访问http://127.0.0.1:8091/
    目标列表中有你本地的机器,说明Prometheus已经成功监控到本地。

Grafana

  1. 下载
    从Grafana下载
  2. 启动
    双击安装即可。 进行到安装bin目录下:双击grafana-server.exe启动
    访问http://127.0.0.1:3000
    默认账号/密码:admin/admin

  3. 配置Prometheus数据源
    从刚才配置好的prometheus那里获取本地性能数据并展示。

  4. 搭建Prometheus仪表盘
    Import Dashboard: 10467

最终显示如下:

Python生成二维码

Posted on 2020-03-22 | In Automation Testing |

工作中用二维码扫描功能能带来不少的便利,简单看了一下,用Python和qrcode包来生成二维码其实很简单,

qrcode,详细信息查看pip qrcode,安装直接用pip命令安装即可。

纯文本二维码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
def generate_qrcode(data, file_name):

# 1. 实例化QRCode对象
qr = qrcode.QRCode(
version=1,
error_correction=qrcode.constants.ERROR_CORRECT_H,
box_size=10,
border=4
)
# 2. 添加数据
qr.add_data(data)
qr.make(fit=True)

# 3. 生成二维码
img = qr.make_image()

# 4. 保存二维码
img.save(file_name)

# 5. 展示二维码
img.show()

if __name__ == '__main__':
generate_qrcode("http://izheyi.com", 'text.png')

二维码显示:

带Logo二维码

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
def generate_qrcode(data, file_name):
# 1. 实例化QRCode对象
qr = qrcode.QRCode(
version=1,
error_correction=qrcode.constants.ERROR_CORRECT_H,
box_size=10,
border=4
)
# 2. 添加数据
qr.add_data(data)
qr.make(fit=True)

# 3. 生成二维码
img = qr.make_image(fill_color="green", back_color="white")

# 4. 添加logo
icon = Image.open("logo.jpg") # 打开logo照片
img_w, img_h = img.size # 图片的宽高

factor = 6
size_w = int(img_w / factor)
size_h = int(img_h / factor)
icon_w, icon_h = icon.size
if icon_w > size_w:
icon_w = size_w
if icon_h > size_h:
icon_h = size_h

icon = icon.resize((icon_w, icon_h), Image.ANTIALIAS)
w = int((img_w - icon_w) / 2)
h = int((img_h - icon_h) / 2)

img.paste(icon, (w, h), mask=None) # 添加logo照

# 5. 保存二维码
img.save(file_name)

# 6. 展示二维码
img.show()

if __name__ == '__main__':
generate_qrcode("http://izheyi.com", 'logo.png')

二维码显示:

还可以把二维码嵌入到页面中,以便更好的使用。

丁丁画画(三年级下学期)

Posted on 2020-03-08 | In 丁丁 |

















mitmproxy实现接口信息抓取

Posted on 2020-02-14 | In mitmproxy |

对于没有接口文档的系统,能不能快速获得接口信息,或者说在做功能测试的时候就得到接口测试的一些基本信息。这里就要用到mitmproxy: mitmproxy is a free and open source interactive HTTPS proxy.

在windows和Firefox下实验。

安装

pip直接安装:
pip install mitmproxy

基本使用

  • 命令行启动
    mitmdump
  • 常用参数
    -p 指定端口号
    -w outfile 将日志输出到本地文件
    –ignore all hosts with https/ssl 忽略https 证书错误 (–ignore-hosts “.*443$”)
    -s 加载自定义python脚本
  • 添加证书
    1. 配置好代理,并启动代理后, 浏览器进入mitm.it, 选择相应的证书,下载。
    2. 选项—隐私与安全—安全—证书—查看证书, 您的证书中导入下载的证书, 在“证书颁发机构”中找到mitmproxy, 编辑信任,勾选相应条目。

抓取接口信息

  1. 创建脚本

    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
    from mitmproxy import http, ctx
    import openpyxl,time,json

    class Record:

    def __init__(self):
    self.filter_url = 'https://reqres.in/api/'
    self.cur_time = time.strftime('%Y%m%d_%H_%M_%S')
    book = openpyxl.Workbook()
    table = book.active
    table.append(['Address', 'Request Type', 'Param Type',
    'Header', 'Param'])
    book.save('E:/{cur_time}.xlsx'.format(cur_time=self.cur_time))
    self.workbook = openpyxl.load_workbook('e:/{cur_time}.xlsx'.format(tmp=self.cur_time))
    self.workbook.active.title = 'API'
    self.table = self.workbook.active

    def write_to_excel(self, flow):
    url = flow.request.url
    method = flow.request.method
    type = flow.request.headers.get('Content-Type')
    if type == 'application/x-www-form-urlencoded':
    type = 'URL_ENCODE'
    elif type == 'application/json':
    type = 'JSON'
    elif type == 'text/xml':
    type = 'XML'
    headers = json.dumps(dict(flow.request.headers))
    body = flow.request.get_text()
    self.table.append([url, method, type, headers, body])
    self.workbook.save('e:/{cur_time}.xlsx'.format(cur_time=self.cur_time))

    def response(self, flow):
    if self.filter_url:
    if flow.request.url.startswith(self.filter_url):
    self.write_to_excel(flow)
    else:
    self.write_to_excel(flow)


    addons = [
    Record()
    ]
  2. 设置firefox代理
    设置本地Firefox代理,商品为9999

  3. 运行mitmdump

    1
    mitmdump -p 9999 -s a.py --ignore all hosts with https/ssl
  4. 打开测试网站操作

  5. 查看结果

奇点绘画画随记(2020)

Posted on 2020-02-02 | In 丁丁 |








python离线安装外部依赖包

Posted on 2020-01-19 | In Python |

公司Jenkins运行在内部环境,不能访问外部网络,所以要安装的外部依赖需要用离线的方式来安装。

  1. 制作requirement.txt
    pip freeze > requirement.txt
  2. 下载安装包
    pip download -d d:\package <package_name> # 单个下载
    pip download -d d:\package -r requirements.txt # 批量下载
  3. 离线安装
    pip install --no-index --find-links=d:\package package_name # 单个安装
    pip install --no-index --find-links=d:\package -r requirements.txt # 批量安装

分布式持续压测平台

Posted on 2019-10-19 | In Performance Testing |

压测平台介绍

  • QA设计场景和脚本,Github管理
  • QA创建Jenkins测试job
  • Dev利用Jenkins持续执行测试,直到达到预期性能
  • QA对主要接口进行验收测试,验证符合上线性能预期

压测平台设计

  • 脚本编写和执行 – Jmeter
  • 脚本管理 – Github
  • 驱动执行 – Taurus
  • 测试调度 – Jenkins

Performace Platform

丁丁画画(三年级上学期)

Posted on 2019-09-08 | In 丁丁 |





网站促销活动前端自动化监控

Posted on 2019-06-11 | In Automation Testing |

商城每年都会有太多有促销活动,大的来说几乎每天都有,对于测试来说,纯手工是个不小的挑战,能否用自动化的方式来快速实现测试?

对于商城的活动页面其实都是一个模板,只是针对不同的活动,不同的地址,不同的产品。这样来看就可以用自动化的方式来检查信息的正确性。

活动一般有

  • 一个主页,上面有图片,标题,价格
  • 详情页面
  • 下单

自动化思路:

  1. 从主页通过Selenium来获得所有的图片和产品详细页链接
  2. 通过Request来检查产品链接和图片存在与否
  3. 检查详细页的信息正确
  4. 利用Cookie实现下单流程的实现

丁丁画画(二年级下学期)

Posted on 2019-04-08 | In 丁丁 |






1…678…40
唐胡璐

唐胡璐

i just wanna live while i am alive

393 posts
42 categories
74 tags
RSS
LinkedIn Weibo GitHub E-Mail
Creative Commons
© 2022 唐胡璐
Powered by Hexo
|
Theme — NexT.Pisces v5.1.4