Git Product home page Git Product logo

wsstat's Introduction

wsstat

Websocket stress testing made beautiful

Build Status Coverage Status PyPi PyPi PyPi

Hello!

This repository holds WSStat, a websocket monitoring and visualization tool written in Python 3.3+, using the great AsyncIO, Websocket, and Urwid libraries ๐Ÿ˜Ž .

It aims to make diagnosing problems and understanding your websocket infrastructure easy and beautiful.

There are still a few edges and whatnot since it's fairly new, and some functionality doesn't exist (yet), but that's where I'm hoping the community can help.

I'm actively looking for feedback

The core of WSStat was written to be modular with extensibility in mind. Want a web API to gather statistics while it runs? How about a websocket server that pushes statistics from multiple workers to one place? Threshold based alerting? Slack integration? File a ticket and we'll kick it around!

It should go without saying, but pull requests are absolutely welcome!

Now, a demo

demo

When you pass the --demo flag to WSStat, it will spin up an asynchronous websocket server on port 65432 point the websocket monitors to that server, allowing you to see functionality with a real websocket server.

Installation

Install from pip - pip install wsstat

Note: if you have python 2 and 3 installed on the same system, you have to use pip3 install wsstat!

The installation should be 100% straight forward and work fine. If that's not the case, please file a ticket!

Please note: WSStat currently only works on Python >= 3.3, and won't install on python 2.7, which is a known limitation.

Usage

Using wsstat is pretty straight forward, and it only has a few knobs (for now). If you want to try wsstat out and don't have a websocket infrastructure handy, you can just pass in --demo to have wsstat set up a server for you!

Other than that, you can adjust the total number of connected clients with -n, the number of simultaneous sockets trying to connect at once with -c, or pass in an arbitrary header (for things like authentication) with -H.

$ wsstat -h
usage: wsstat [-h] [-n TOTAL_CONNECTIONS] [-c MAX_CONNECTING_SOCKETS]
              [-H HEADER] [--demo] [-i]
              [websocket_url]

positional arguments:
  websocket_url         The websocket URL to hit

optional arguments:
  -h, --help            show this help message and exit
  -n TOTAL_CONNECTIONS, --num-clients TOTAL_CONNECTIONS
                        Number of clients to connect - default 250
  -c MAX_CONNECTING_SOCKETS, --max-connects MAX_CONNECTING_SOCKETS
                        Number of connections attempted simultaneously -
                        default 15
  -H HEADER, --header HEADER
                        Pass a custom header with each websocket connection
  --demo                Start a demo websocket server and point wsstat at it
  -i, --insecure        Don't validate SSL certificates on websocket servers

wsstat's People

Contributors

abawchen avatar fitblip avatar uasouz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

wsstat's Issues

Could not run wsstat

After I did install wsstat using pip3, and when I tried to run it, I got the following:

wsstat
Traceback (most recent call last):
File "/bin/wsstat", line 7, in
from wsstat.main import wsstat_console
File "/usr/lib/python3.4/site-packages/wsstat/main.py", line 5, in
from wsstat.clients import WebsocketTestingClient
File "/usr/lib/python3.4/site-packages/wsstat/clients.py", line 16, in
from websockets.protocol import OPEN
ImportError: cannot import name 'OPEN'

Could you please help me with that?

pip3.4 list
DEPRECATION: The default format will switch to columns in the future. You can use --format=(legacy|columns) (or define a format=(legacy|columns) in your pip.conf under the [list] section) to disable this warning.
asyncio (3.4.3)
attrs (17.4.0)
pip (9.0.1)
pluggy (0.6.0)
py (1.5.2)
pytest (3.3.2)
setuptools (38.4.0)
six (1.11.0)
urwid (2.0.1)
websockets (4.0.1)
wheel (0.30.0)
wsstat (1.2.1)

python -V
Python 3.4.5

Thanks in advance.
Regards.

module 'asyncio' has no attribute 'ensure_future'

When testing on Python 3.6.5, I get the following error :

17:08 $ wsstat -n 10 -c 5 http://localhost:9000/
Traceback (most recent call last):
File "/usr/local/bin/wsstat", line 11, in
sys.exit(wsstat_console())
File "/usr/local/lib/python3.6/site-packages/wsstat/main.py", line 68, in wsstat_console
client = WebsocketTestingClient(**vars(args))
File "/usr/local/lib/python3.6/site-packages/wsstat/clients.py", line 87, in init
self.setup_tasks()
File "/usr/local/lib/python3.6/site-packages/wsstat/clients.py", line 237, in setup_tasks
tasks.append(asyncio.ensure_future(coro))
AttributeError: module 'asyncio' has no attribute 'ensure_future'

Is wsstat tested on that Python version ?!
Thx !

On Message Event

I have number of websocket connections connected,what if I want to send message on that connection from using some function. Do we have any utility function in the library for the same?
I was trying to something like this:

import json
from .clients import WebsocketTestingClient
messageTypes = {
'handshake': 'hello',
'chan_register': 'register'
}
class WPushClient(WebsocketTestingClient):

def _construct_event_payload(self, request_type, **kwargs):
    data = dict()
    data['messageType'] = messageTypes[request_type]
    data.update(**kwargs)
    return json.dumps(data)

def _handshake_request(self):
    payload =  self._construct_event_payload('handshake', use_webpush=True)
    return payload

def after_connect(self, statedict):
    msg = self._handshake_request()
    self.logger.log(msg)
    statedict['connected_websocket'].ws.sendMessage(msg)

I was unable to send the "msg" on the websocket connection?

need a real usage example

I just wasted a good hour because I had http://localhost:8000/ws as the websocket_url instead of ws://localhost:8000/ws. Yes I know that's on me but having usage examples are absolutely key for any project.

Connection Limit

This is the maximum stress connection i can achieve, whatever the values we provide, this is the maximum stress connection i can achieve.

Snap_Shot_00121

Connection limit : 992

Hitting a limit

It seems like wsstat hits an artificial 90k messages/sec on 500 connections. If i have wsstat running 4 times (in 4 terminals) at the same time, the total is something like 280k messages/sec.

Any idea why it plateus?

Secure websockets on self-signed certificates

It does seem like self-signed certificates can't be tested because wsstat can't automatically accept unverifiable certificates. Is this something that an option can be added for?

Can't automagically start on Ubuntu

At first:

$ pip install wsstat
Collecting wsstat
  Using cached wsstat-1.2.1.tar.gz
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-build-3vqNNt/wsstat/setup.py", line 11, in <module>
        raise Exception("websockets requires Python >= 3.3.")
    Exception: websockets requires Python >= 3.3.

However, installing wsstat using pip3 (pip for python3):

Successfully built urwid
Installing collected packages: websockets, urwid, asyncio, appdirs, six, pyparsing, packaging, setuptools, py, pytest, wsstat
Successfully installed appdirs asyncio packaging py pyparsing pytest setuptools-20.7.0 six-1.10.0 urwid websockets-3.0 wsstat

works.. except I can't just run wsstat:

$ wsstat
wsstat: command not found
$ python3 wsstat
python3: can't open file 'wsstat': [Errno 2] No such file or directory

ModuleNotFoundError: No module named 'websockets.handshake'

Traceback (most recent call last):
File "/usr/local/bin/wsstat", line 7, in
from wsstat.main import wsstat_console
File "/usr/local/lib/python3.6/dist-packages/wsstat/main.py", line 5, in
from wsstat.clients import WebsocketTestingClient
File "/usr/local/lib/python3.6/dist-packages/wsstat/clients.py", line 14, in
import websockets.handshake

ImportError: cannot import name 'Deque'

I'm getting this error when trying to run the wsstat. I've tried different versions of Python (3.5, 3.6.1, 3.8.5 and latest 3.9.5)

ImportError: cannot import name 'Deque'

I have a conda environment setup so I'm sure it's running the version of Python I installed.

Could not run wsstat about asyncio.async

hi , when i run wsstat --demo on my mac with python3.7 , it just show this:

ivydeMac-mini-2:~ ivy$ wsstat --demo
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.7/bin/wsstat", line 11, in <module>
    load_entry_point('wsstat==1.3.0', 'console_scripts', 'wsstat')()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pkg_resources/__init__.py", line 487, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pkg_resources/__init__.py", line 2728, in load_entry_point
    return ep.load()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pkg_resources/__init__.py", line 2346, in load
    return self.resolve()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pkg_resources/__init__.py", line 2352, in resolve
    module = __import__(self.module_name, fromlist=['__name__'], level=0)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/wsstat/main.py", line 5, in <module>
    from wsstat.clients import WebsocketTestingClient
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/wsstat/clients.py", line 24
    asyncio.ensure_future = asyncio.async
                                        ^
SyntaxError: invalid syntax

this is my pip3 installed modules

ivydeMac-mini-2:~ ivy$ pip3 list
Package        Version
-------------- -------
asyncio        3.4.3  
atomicwrites   1.2.1  
attrs          18.2.0 
more-itertools 5.0.0  
pip            18.1   
pluggy         0.8.0  
py             1.7.0  
pytest         4.0.2  
setuptools     40.6.2 
six            1.12.0 
urwid          2.0.1  
websockets     7.0    
wsstat         1.3.0  

i am not good at python ,but i want to use this great repository ,plz help me , thank you !

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.