Giter VIP home page Giter VIP logo

httpstat's Introduction

httpstat

screenshot

httpstat visualizes curl(1) statistics in a way of beauty and clarity.

It is a single file🌟 Python script that has no dependency👏 and is compatible with Python 3🍻.

Installation

There are three ways to get httpstat:

  • Download the script directly: wget https://raw.githubusercontent.com/reorx/httpstat/master/httpstat.py

  • Through pip: pip install httpstat

  • Through homebrew (macOS only): brew install httpstat

For Windows users, @davecheney's Go version is suggested. → download link

Usage

Simply:

python httpstat.py httpbin.org/get

If installed through pip or brew, you can use httpstat as a command:

httpstat httpbin.org/get

cURL Options

Because httpstat is a wrapper of cURL, you can pass any cURL supported option after the url (except for -w, -D, -o, -s, -S which are already used by httpstat):

httpstat httpbin.org/post -X POST --data-urlencode "a=b" -v

Environment Variables

httpstat has a bunch of environment variables to control its behavior. Here are some usage demos, you can also run httpstat --help to see full explanation.

  • HTTPSTAT_SHOW_BODY

    Set to true to show response body in the output, note that body length is limited to 1023 bytes, will be truncated if exceeds. Default is false.

  • HTTPSTAT_SHOW_IP

    By default httpstat shows remote and local IP/port address. Set to false to disable this feature. Default is true.

  • HTTPSTAT_SHOW_SPEED

    Set to true to show download and upload speed. Default is false.

    HTTPSTAT_SHOW_SPEED=true httpstat http://cachefly.cachefly.net/10mb.test
    
    ...
    speed_download: 3193.3 KiB/s, speed_upload: 0.0 KiB/s
  • HTTPSTAT_SAVE_BODY

    By default httpstat stores body in a tmp file, set to false to disable this feature. Default is true

  • HTTPSTAT_CURL_BIN

    Indicate the cURL bin path to use. Default is curl from current shell $PATH.

    This exampe uses brew installed cURL to make HTTP2 request:

    HTTPSTAT_CURL_BIN=/usr/local/Cellar/curl/7.50.3/bin/curl httpstat https://http2.akamai.com/ --http2
    
    HTTP/2 200
    ...

    cURL must be compiled with nghttp2 to enable http2 feature (#12).

  • HTTPSTAT_METRICS_ONLY

    If set to true, httpstat will only output metrics in json format, this is useful if you want to parse the data instead of reading it.

  • HTTPSTAT_DEBUG

    Set to true to see debugging logs. Default is false

For convenience, you can export these environments in your .zshrc or .bashrc, example:

export HTTPSTAT_SHOW_IP=false
export HTTPSTAT_SHOW_SPEED=true
export HTTPSTAT_SAVE_BODY=false

Related Projects

Here are some implementations in various languages:

  • Go: davecheney/httpstat

    This is the Go alternative of httpstat, it's written in pure Go and relies no external programs. Choose it if you like solid binary executions (actually I do).

  • Go (library): tcnksm/go-httpstat

    Other than being a cli tool, this project is used as library to help debugging latency of HTTP requests in Go code, very thoughtful and useful, see more in this article

  • Bash: b4b4r07/httpstat

    This is what exactly I want to do at the very beginning, but gave up due to not confident in my bash skill, good job!

  • Node: yosuke-furukawa/httpstat

    b4b4r07 mentioned this in his article, could be used as a HTTP client also.

  • PHP: talhasch/php-httpstat

    The PHP implementation by @talhasch

Some code blocks in httpstat are copied from other projects of mine, have a look:

httpstat's People

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  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

httpstat's Issues

server processing time is negative

Body stored in: /var/folders/fh/5k0fl9xd06xgflnp5d90dz8m0000gn/T/tmpjIYObb

  DNS Lookup   TCP Connection   TLS Handshake   Server Processing   Content Transfer
[     2ms    |      194ms     |     92ms      |      -288ms       |      1255ms      ]
             |                |               |                   |                  |
    namelookup:2ms            |               |                   |                  |
                        connect:196ms         |                   |                  |
                                    pretransfer:288ms             |                  |
                                                      starttransfer:0ms              |
                                                                                 total:1255ms

Installed with pip but not working

Hi there,
First thanks for your really awesome tool, my problem with this is that I installed it with pip on ubuntu but my problem is that although I it is installed in the ~/.local/lib/python2.7/site-packages but it isn't available via commandline. I mean when I type httpstat it says command not found.

Could not decode json error on OSX

Hi! I receive following error on OSX:

➜  ~ httpstat https://google.com/

Could not decode json: Expecting property name: line 2 column 22 (char 23)
curl result: 0 {
"time_namelookup": 0,068,
"time_connect": 0,113,
"time_appconnect": 0,302,
"time_pretransfer": 0,302,
"time_redirect": 0,000,
"time_starttransfer": 0,370,
"time_total": 0,370,
"speed_download": 594,000,
"speed_upload": 0,000
}

I think, the problem is in number format, it uses a comma instead of dot as a delimiter.

Homebrew

Will there be a release on Homebrew? httpstat is available, too.

Lamentable screenshot

Hello! This is a nice project.

Please display an image of a high performance webserver to boost morale.

kép

FileNotFoundError on WIN7/Python3.6.0, installed with Pip

Trying to run httpstat https://google.com on Windows 7 with Python 3.6.0, results a stack trace:

Traceback (most recent call last):
  File "C:\Users\me\AppData\Local\Programs\Python\Python36\Scripts\httpstat-script.py", line 11, in <module>
    load_entry_point('httpstat==1.2.1', 'console_scripts', 'httpstat')()
  File "c:\users\me\appdata\local\programs\python\python36\lib\site-packages\httpstat.py", line 221, in main
    p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=cmd_env)
  File "c:\users\me\appdata\local\programs\python\python36\lib\subprocess.py", line 707, in __init__
    restore_signals, start_new_session)
  File "c:\users\me\appdata\local\programs\python\python36\lib\subprocess.py", line 990, in _execute_child
    startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified

Could not decode json

Windows 7 64-bit, Python 2.7.12 64-bit

C:\Users\xmr\Desktop>curl --version
curl 7.50.1 (x86_64-pc-win32) libcurl/7.50.1 OpenSSL/1.0.2h zlib/1.2.8 WinIDN libssh2/1.7.0 nghttp2/1.13.0
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtsp scp sftp smtp smtps telnet tftp
Features: AsynchDNS IDN IPv6 Largefile SSPI Kerberos SPNEGO NTLM SSL libz TLS-SRP HTTP2

C:\Users\xmr\Desktop>httpstat google.com
←[38;5;248m←[0m
←[33mCould not decode json: Expecting property name: line 2 column 22 (char 24)←
[0m
curl result: 0 ←[38;5;248m{
"time_namelookup": 0,110,
"time_connect": 0,328,
"time_appconnect": 0,000,
"time_pretransfer": 0,328,
"time_redirect": 0,000,
"time_starttransfer": 0,391,
"time_total": 0,391,
"speed_download": 659,000,
"speed_upload": 0,000
}←[0m ←[38;5;248m←[0m

Upgrade curl to test HTTP2

Current version:

$ curl --version
curl 7.43.0 (x86_64-apple-darwin15.0) libcurl/7.43.0 SecureTransport zlib/1.2.5
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtsp smb smbs smtp smtps telnet tftp
Features: AsynchDNS IPv6 Largefile GSS-API Kerberos SPNEGO NTLM NTLM_WB SSL libz UnixSockets

Upgrade using brew install --build-from-source curl --with-nghttp2 (hint from https://simonecarletti.com/blog/2016/01/http2-curl-macosx/)

Testing process will be logged here.

Error when running on Linux/Python 2.6

python httpstat.py httpbin.org/get
File "httpstat.py", line 110
grayscale = {(i - 232): make_color('38;5;' + str(i)) for i in xrange(232, 256)}
^
SyntaxError: invalid syntax

Redhat 6.5, Python 2.6

Provide Average based on number of attempts over time

This is a feature req. that I just thought of. I've been doing some testing of proxy servers and have used to httpstat to gain insight into how long each part of the connection process takes. To make httpstat even more adept to performance based testing like this, it would be exceptionally awesome if it had the option for making x number of requests over y timeframe and providing those results in a similar drawing to how it currently does i.e. TLS Handshake avg, Server Processing avg, etc..

Just a thought ;)

Add flag which does not store response body

Currently, the app stores the response body in tmp.
The new flag to support quick scan to look for metrics but not interested in keeping any output around.
This would be a great feature.
It would be even better if it does all operations in memory instead of using temp files and deleting them later.

why server processing is 0 with local request

curl 7.61.1 (x86_64-redhat-linux-gnu) libcurl/7.61.1 OpenSSL/1.1.1c zlib/1.2.11 brotli/1.0.6 libidn2/2.2.0 libpsl/0.20.2 (+libidn2/2.0.5) libssh/0.9.0/openssl/zlib nghttp2/1.33.0

export  HTTPSTAT_SHOW_IP=true
export  HTTPSTAT_SHOW_SPEED=true
export  HTTPSTAT_SAVE_BODY=false
export  HTTPSTAT_DEBUG=false

Connected to ::1:8094 from ::1:57934

HTTP/1.1 100 Continue

HTTP/1.1 200 OK
Content-Type: application/json
Grpc-Metadata-Content-Type: application/grpc
Date: Tue, 31 Aug 2021 12:33:30 GMT
Content-Length: 258

  DNS Lookup   TCP Connection   Server Processing   Content Transfer
[     0ms    |       0ms      |        0ms        |      1405ms      ]
             |                |                   |                  |
    namelookup:0ms            |                   |                  |
                        connect:0ms               |                  |
                                      starttransfer:0ms              |
                                                                 total:1405ms 

speed_download: 0.2 KiB/s, speed_upload: 36791.2 KiB/s

Screenshots

First off Great software !
and the screenshot looks pretty awesome too can you please tell how can I modify my terminal to get that black window bar and that awesome font! I am on macOS.

Thanks! 😄

Valid cURL invocation fails with httpstat because of URL position

An invocation that would be valid with cURL:

curl -X GET http://www.google.de/

gives the following error with httpstat:

$ httpstat -X GET http://www.google.de/
> curl -w <output-format> -D <tempfile> -o <tempfile> -s -S GET http://www.google.de/ -X
curl error: curl: option -X: requires parameter
curl: try 'curl --help' or 'curl --manual' for more information

whereas the command

httpstat http://www.google.de/ -X GET

is parsed successfully.

It would be nice if httpstat did not depend on the position of the URL. In my concrete example, the cURL command was generated by Flask-RESTPlus Swagger documentation.

'failed to create process' after PIP install - Possible Python 3 Compatibility Issue?

Installed via PIP on two separate computers running Windows 10 with Python 3.5.2 and Python 3.5.0 and attempted httpstat google.com in the command line and received 'failed to create process'. Navigated directly in the command line to the default Python scripts folder and ran py httpstat-script.py google.com and received the following on both machines:
Traceback (most recent call last): File ".\httpstat-script.py", line 9, in <module> load_entry_point('httpstat==1.2.1', 'console_scripts', 'httpstat')() File "c:\users\%NAME%\appdata\local\programs\python\python35\lib\site-packages\httpstat.py", line 221, in main p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=cmd_env) File "c:\users\%NAME%\appdata\local\programs\python\python35\lib\subprocess.py", line 947, in __init__ restore_signals, start_new_session) File "c:\users\%NAME%\appdata\local\programs\python\python35\lib\subprocess.py", line 1224, in _execute_child startupinfo) FileNotFoundError: [WinError 2] The system cannot find the file specified

Ran repair on my Python installation and retried. Uninstalled and reinstalled Python (using elevated privileges) and retried. No positive effect.

An attempt on a third Win10 computer with both Python 3.5.1 and Python 2.7 installed worked without issue. Installed via PIP and httpstat google.com ran correctly. Running the script directly on that machine with either version of Python also works without issue.

Detecting connectivity Issues to the destination

I have a networking solution which probes the destination with http, mtr, ping etc and collect metrics. Often I see when MTR, Ping return 100% packet loss, httpstat report a very large value of latency. Is it possible to put a time out in the code (preferably configurable) ?

Snapcraft.yaml for httpstat

I am a user of httpstat and I used httpstat as an example to show how to package software as snaps (https://www.ubuntu.com/desktop/snappy).

To make a snap for a software package, you need to create a snapcraft.yaml configuration file.
Here is the one for httpstat: https://gist.github.com/simos/3214bbd2f7d4a4647918bdb2afb926cd

How to create the snap?

  1. Install snapcraft 2.26 (default in Ubuntu 16.04 or newer)
  2. Run "snapcraft" in the same directory that has the snapcraft.yaml from the gist.
  3. The httpstat_1.1.3_amd64.snap will be produced.

I wrote an article about all this at https://blog.simos.info/how-to-create-a-snap-for-a-python-app-with-networking-using-snapcraft-in-ubuntu-16-04/

I understand that someone would simply need to grab the .py file and run it. I am posting this issue to inform that I have used "httpstat" as an example for my tutorial.

Add option for detailing SSL/TLS Certificate

This would be super useful to have for learning more about the certificate a particular site uses. It could be an add-on option (not default) which shows issuer information, if its valid, start/expire, and possibly other details.

Just an idea!

Option to display the IP address used to contact destination

It would be nice to find out the exact IP that was used to make the connection. This helps for things like debugging round-robin records etc..

Maybe something like HTTPSTAT_SHOW_IP

Great work on this btw, definitely my go to utility now ;)

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.