Simple API Counter from log files or folder.
Project description
Simple API Call Counter
Environment
- Python 3.11.x
It is recommended to set with pyenv.
If you can configure the Python execution environment in another way, you can skip the pyenv guide below.
pyenv
$ pyenv install 3.11.2
$ pyenv virtualenv 3.11.2 url_counter
$ pyenv local url_counter
Install
$ pip install -e .
Run
$ counter --help # Show me the help.
$ counter -d . -r -f # Counts urls from all (json and log) files under the current folder and
# creates a result file (however, json files starting with result_ are not included!)
Example of Using Options (Refer to the Help)
$ counter 000.json # Display the count result from 000.json on the screen
$ counter 000.json -f # Display the count result from 000.json on the screen and create a result_{date_time}.json file
$ counter 000.json 111.json 222.json ... # Count multiple json files and display the results on the screen
$ counter 000.json 111.json 222.json ... -f # Count multiple json files, display the results on the screen, and create a result file
$ counter -d ./0000 # Count all json files in the 0000 folder and display the result (subfolders are not processed)
$ counter -d ./0000 -f # Count all json files in the 0000 folder, display the result, and create files (subfolders are not included)
$ counter -d -r -f ./0000 # Count all json files in the 0000 folder, display the result, and create files (including subfolders)
Test (unittest with pytest)
$ pytest -svx -rsa tests
Result File Format
Format: result_{date_time(%Y%m%d_%H%M%S)}.json
{
"targets": [
list of counted files
],
"result": [
"Counted URL: 1st place in frequency",
"Counted URL: Sorted in descending order of frequency"
]
}
Sample: result_20231209_201928.json
{
"targets": [
"tests/samples/nginx.log"
],
"result": [
"GET /api/docs: 18",
"GET /api: 17",
"POST /api/v1/social/signup: 4",
"DELETE /api/v1/users/95: 2",
"PUT /api/v1/users/me: 1",
"POST /api/v1/social/profile/format: 1",
"POST /api/v1/social/profile: 1"
]
}
One More Thing (About the ignore option)
If you want to specify lines to exclude from the counter. (e.g. request from a specific IP address, etc.)
You can set export ignores=1.1.1.1 or export ignores=1.1.1.1,2.2.2.2 (no space allowed).
$ export ignores=1.1.1.1
or for multiple ignores.
$ export ignores=1.1.1.1,2.2.2.2
And surprisingly, this option can work with any string. (e.g. '/api/token')
$ export ignores='/api/token'
or for multiple ignores.
$ export ignores='/api/token',2.2.2.2
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Api-Counter-2.2.2.tar.gz
(4.3 kB
view hashes)
Built Distribution
Close
Hashes for Api_Counter-2.2.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8af3154238926846b254c1351c04e6103c66b1869aa52847161f09aafd217d3f |
|
MD5 | 363b7888cc11de0266cc7b1db89e2984 |
|
BLAKE2b-256 | 37762bb8b8861b82be1db9e300de209f70aba39cea4bb5fc5206db7347633f48 |