0. 准备
jython目前只支持python2
- Java环境:JDK1.8及以上版本
- python
下载 【jython-standalone-2.7.3.jar】包 把这个jar包下载下来后,放入到jmeter的
lib
文件夹中。添加完后重启JMeter
1. 启动
创建【JSR223 Sampler】,语言选择【jython】
import sys sys.path.append("D:\Python38\Lib\site-packages") import json from pymongo import MongoClient try: # 连接mongodb服务器 client = MongoClient("192.168.92.159", 20000) # 连接 mongodb数据库,jmeterdata为数据库名 db = client['seismic_space'] # 连接 mongodb 数据集,jdata为数据集名 collection = db['project_table'] document_count = collection.count_documents({}) print(f"Total number of documents in collection: {document_count}") # 关闭连接 client.close() except Exception as e: SampleResult.setSuccessful(false); SampleResult.setResponseCode("500"); SampleResult.setResponseMessage("Exception: " + e);