0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

サーバーのログから対象月の転送量を算出する方法

0
Posted at

概要

サーバーのログから対象月の転送量を算出する方法になります。

手順

grep "MM/YYYYY" /path/to/accesslog | awk '$10 != "-" {sum
 += $10} END {
  if (sum >= 1000*1000*1000) {
    printf "%.2f GB\n", sum / 1000 / 1000 / 1000
  } else if (sum >= 1000*1000) {
    printf "%.2f MB\n", sum / 1000 / 1000
  } else if (sum >= 1000) {
    printf "%.2f KB\n", sum / 1000
  } else {
    printf "%d B\n", sum
  }
}'

上記コマンドで対象月の転送量を算出できます。
どの範囲で、どういったログを指定するかは適宜調整してください。

# 実行例

[root@web01(alma) logs]# zgrep "Dec" access_log-202512* access_log-20260104.gz | awk '$10 != "-" {sum
 += $10} END {
  if (sum >= 1000*1000*1000) {
    printf "%.2f GB\n", sum / 1000 / 1000 / 1000
  } else if (sum >= 1000*1000) {
    printf "%.2f MB\n", sum / 1000 / 1000
  } else if (sum >= 1000) {
    printf "%.2f KB\n", sum / 1000
  } else {
    printf "%d B\n", sum
  }
}'
1264.73 GB
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?