简体   繁体   English

有没有一种方法可以用Python脚本通过Apache日志请求对网站进行压力测试?

[英]Is there a way to stress test a website with Apache log requests with Python script?

Have been fiddling with a Python script that would take POST, GET requests from apache log and stress test a website upon the requests found from apache log for quite some time by now. 一直在摆弄一个将在apache日志中执行POST,GET请求并根据apache日志中发现的请求对网站进行压力测试的Python脚本,到目前为止已经有一段时间了。

Pretty much I could get the requests from the log file and parse them and convert them to CSV file with some help from here - https://lincolnloop.com/blog/load-testing-jmeter-part-3-replaying-apache-logs/ 我几乎可以从日志文件中获取请求并进行解析,然后在此处提供一些帮助下将其转换为CSV文件-https: //lincolnloop.com/blog/load-testing-jmeter-part-3-replaying-apache-日志/

But now I am stuck - I haven't quite found a good stress tester that would take such requests in and stress test upon them. 但是现在我被困住了-我还没有找到一个好的压力测试仪来接受这样的要求并对其进行压力测试。 Jmeter doesn't cut it because still the GUI would needed to be used and that's no good as the purpose is to have simple and portable Python script. Jmeter并没有削减它,因为仍然需要使用GUI,这不好,因为目的是拥有简单且可移植的Python脚本。 Of course any modules would be OK. 当然任何模块都可以。

If anybody has any good ideas or a bit of code to share then would be immensely grateful! 如果有人有什么好主意或要分享的代码,将不胜感激!

Thanks and have a beautiful day! 谢谢,祝你有美好的一天! :) :)

Johannes 约翰内斯

Is Python a must for your use case? 是您的用例必备的Python吗? If not, you could try Apache JMeter free and open-source Java-based load and performance testing solution. 如果没有,您可以尝试Apache JMeter免费和开源的基于Java的负载和性能测试解决方案。

It provides Access Log Sampler which seems to be exactly what you're looking for. 它提供了访问日志采样器 ,它似乎正是您所需要的。 See How to use Access Log Sampler to Generate Traffic with JMeter for detailed walkthrough. 有关详细的演练,请参见如何使用Access Log Sampler与JMeter生成流量

Alternative option is using Grinder and Apache Log Playback script . 另一种选择是使用GrinderApache Log Playback脚本 In this case you'll be able to integrate it with your existing Python code but Java will still be required. 在这种情况下,您可以将其与现有的Python代码集成在一起,但仍然需要Java。

The Locust python framework allows load and stress testing. Locust python框架允许进行负载和压力测试。

An example from their website: 他们网站上的一个例子:

from locust import HttpLocust, TaskSet, task

class WebsiteTasks(TaskSet):
    def on_start(self):
        self.client.post("/login", {
            "username": "test_user",
            "password": ""
        })

    @task
    def index(self):
        self.client.get("/")

    @task
    def about(self):
        self.client.get("/about/")

class WebsiteUser(HttpLocust):
    task_set = WebsiteTasks
    min_wait = 5000
    max_wait = 15000

Read more here: http://locust.io/ 在此处了解更多信息: http : //locust.io/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM