./install.sh: Installs the scripts and sets up the environment.
./install.sh <traffic-data-dir>: Installs the scripts and sets up the environment with the specified traffic data directory.
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.
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.
The stats-collect script collects and stores traffic data for each user:
- Runs
xray api statsquery -resetto get traffic stats. - Processes the output with
jqusingstats-to-user-down-up.jq. - Reads the traffic data directory path from
/usr/local/etc/xray-stats/directory. - 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.
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.
/var/local/xray-traffic/
├── user1/
│ ├── down/
│ │ └── 2024-01-01
│ └── up/
│ └── 2024-01-01
└── user2/
├── down/
│ └── 2024-01-01
└── up/
└── 2024-01-01