Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/moetelo/xray-stats
https://github.com/moetelo/xray-stats
shadowsocks vless vmess xray xray-core
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/moetelo/xray-stats
- Owner: moetelo
- License: mit
- Created: 2024-08-29T15:28:57.000Z (4 months ago)
- Default Branch: master
- Last Pushed: 2024-11-13T19:31:58.000Z (about 1 month ago)
- Last Synced: 2024-11-13T20:26:58.854Z (about 1 month ago)
- Topics: shadowsocks, vless, vmess, xray, xray-core
- Language: Shell
- Homepage:
- Size: 11.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# xray-stats
## Usage
`./install.sh`: Installs the scripts and sets up the environment.
`./install.sh `: Installs the scripts and sets up the environment with the specified traffic data directory.
## Scripts
`install.sh`: Sets up the environment and installs the necessary scripts.
`stats-collect`: Collects traffic statistics using the xray API and processes them.
`stats-query`: Summarizes the traffic data for each user on a specified date. If no date is provided, it defaults to the current date. It displays the downlink and uplink data in megabytes (MB) for each user.
## Configuration
The traffic data directory is stored in `/usr/local/etc/xray-stats/directory`. You can change this by re-running the `install.sh` script with a different directory.
## How it works
The `stats-collect` script collects and stores traffic data for each user:
1. Runs `xray api statsquery -reset` to get traffic stats.
1. Processes the output with `jq` using `stats-to-user-down-up.jq`.
1. Reads the traffic data directory path from `/usr/local/etc/xray-stats/directory`.
1. Appends downlink and uplink values to files named with the current date in the respective directories.This organizes traffic data by user and date, with separate files for downlink and uplink data.
The file consists of multiple lines, each containing a traffic value in bytes. The script appends the traffic value to the file, creating a new file if it does not exist.
### Cron Job
The `install.sh` script installs a cron job from `xray-stats.cron`.
It runs the `stats-collect` script every 5 minutes, and sums the traffic data for each user on the current date every hour.
## Example directory structure
```
/var/local/xray-traffic/
├── user1/
│ ├── down/
│ │ └── 2024-01-01
│ └── up/
│ └── 2024-01-01
└── user2/
├── down/
│ └── 2024-01-01
└── up/
└── 2024-01-01
```