pslaboが試したことの記録

はてなダイヤリーからはてなブログに引っ越してきました

この日記は現在実行中の減量記録を含む個人的なメモとして始めましたが、最近はコンピュータやガジェット、ハック、セキュリティネタのほうがメインになっております。

iPad3のSIMロックに関する考察とSIM下駄による解除の試みはSoftbank版iPad3にiPhone用のSIM下駄を履かせてみるにいろいろ書いてます。

はてなダイヤリー時代はカテゴリ分けが適当だったのですが、これはそのうち直します。


Squidの動作状況をシェル上で取得する

Squidの動作状況を調べるには cachemgr.cgi を使うのが基本だと思いますが、シェル上からも見れると便利な場合もあるかと思います。

そういう場合向けのTipsです。

まず、以下のように実行してみます。すると閲覧可能な項目が出てきます。

$ squidclient -h 127.0.0.1 -p 3128  cache_object://menu/
HTTP/1.1 200 OK
Server: squid/3.5.19
Mime-Version: 1.0
Date: Wed, 27 Jul 2016 01:12:01 GMT
Content-Type: text/plain;charset=utf-8
Connection: close

 index                  Cache Manager Interface                 public
 menu                   Cache Manager Menu                      public
 offline_toggle         Toggle offline_mode setting             hidden
 shutdown               Shut Down the Squid Process             hidden
 reconfigure            Reconfigure Squid                       hidden
 rotate                 Rotate Squid Logs                       hidden
 cached_ssl_cert        Statistic of cached generated ssl certificates  public
 pconn                  Persistent Connection Utilization Histograms    public
 mem                    Memory Utilization                      public
 squidaio_counts        Async IO Function Counters              public
 config                 Current Squid Configuration             hidden
 client_list            Cache Client List                       public
 comm_poll_incoming     comm_incoming() stats                   public
 ipcache                IP Cache Stats and Contents             public
 fqdncache              FQDN Cache Stats and Contents           public
 idns                   Internal DNS Statistics                 public
 redirector             URL Redirector Stats                    public
 store_id               StoreId helper Stats                    public
 external_acl           External ACL stats                      public
 http_headers           HTTP Header Statistics                  public
 info                   General Runtime Information             public
 service_times          Service Times (Percentiles)             public
 filedescriptors        Process Filedescriptor Allocation       public
 objects                All Cache Objects                       public
 vm_objects             In-Memory and In-Transit Objects        public
 io                     Server-side network read() size histograms      public
 counters               Traffic and Resource Counters           public
 peer_select            Peer Selection Algorithms               public
 digest_stats           Cache Digest and ICP blob               public
 5min                   5 Minute Average of Counters            public
 60min                  60 Minute Average of Counters           public
 utilization            Cache Utilization                       public
 histograms             Full Histogram Counts                   public
 active_requests        Client-side Active Requests             public
 username_cache         Active Cached Usernames                 public
 openfd_objects         Objects with Swapout files open         public
 store_digest           Store Digest                            public
 store_log_tags         Histogram of store.log tags             public
 storedir               Store Directory Stats                   public
 store_io               Store IO Interface Stats                public
 store_check_cachable_stats     storeCheckCachable() Stats              public
 refresh                Refresh Algorithm Statistics            public
 delay                  Delay Pool Levels                       public
 forward                Request Forwarding Statistics           public
 cbdata                 Callback Data Registry Contents         public
 sbuf                   String-Buffer statistics                public
 events                 Event Queue                             public
 asndb                  AS Number Database                      public
 carp                   CARP information                        public
 userhash               peer userhash information               public
 sourcehash             peer sourcehash information             public
 server_list            Peer Cache Statistics                   public

$


ここで先ほどのコマンドにつづけて info などと入力して実行してみると、以下のような情報が得られます。これは実は cachemgr.cgi で入手可能な情報と同じです。(この機材は試験用に立てたので、リクエストがほとんどありません)

$ squidclient -h 127.0.0.1 -p 3128  cache_object://menu/info
HTTP/1.1 200 OK
Server: squid/3.5.19
()
Connection: close

Squid Object Cache: Version 3.5.19
Build Info:
Service Name: squid
Start Time:     Wed, 27 Jul 2016 00:47:18 GMT
Current Time:   Wed, 27 Jul 2016 01:13:59 GMT
Connection information for squid:
        Number of clients accessing cache:      1
        Number of HTTP requests received:       195
        Number of ICP messages received:        0
        Number of ICP messages sent:    0
        Number of queued ICP replies:   0
        Number of HTCP messages received:       0
        Number of HTCP messages sent:   0
        Request failure ratio:   0.00
        Average HTTP requests per minute since start:   7.3
        Average ICP messages per minute since start:    0.0
        Select loop called: 4395 times, 364.392 ms avg
Cache information for squid:
        Hits as % of all requests:      5min: 0.0%, 60min: 60.0%
        Hits as % of bytes sent:        5min: 100.0%, 60min: 70.4%
        Memory hits as % of hit requests:       5min: 0.0%, 60min: 66.7%
        Disk hits as % of hit requests: 5min: 0.0%, 60min: 0.9%
        Storage Swap size:      42820 KB
        Storage Swap capacity:   1.4% used, 98.6% free
        Storage Mem size:       860 KB
        Storage Mem capacity:    0.3% used, 99.7% free
        Mean Object Size:       13.24 KB
        Requests given to unlinkd:      28
Median Service Times (seconds)  5 min    60 min:
        HTTP Requests (All):   0.00000  0.00000
        Cache Misses:          0.00000  0.00000
        Cache Hits:            0.00000  0.00000
        Near Hits:             0.00000  0.00000
        Not-Modified Replies:  0.00000  0.00000
        DNS Lookups:           0.00000  0.24351
        ICP Queries:           0.00000  0.00000
Resource usage for squid:
        UP Time:        1601.501 seconds
        CPU Time:       0.389 seconds
        CPU Usage:      0.02%
        CPU Usage, 5 minute avg:        0.00%
        CPU Usage, 60 minute avg:       0.02%
        Maximum Resident Size: 1950208 KB
        Page faults with physical i/o: 9680
Memory accounted for:
        Total accounted:         2235 KB
        memPoolAlloc calls:     45650
        memPoolFree calls:      46572
File descriptor usage for squid:
        Maximum number of file descriptors:   3200
        Largest file desc currently in use:     16
        Number of file desc currently in use:    9
        Files queued for open:                   0
        Available number of file descriptors: 3191
        Reserved number of file descriptors:   100
        Store Disk files open:                   0
Internal Data Structures:
          3286 StoreEntries
           113 StoreEntries with MemObjects
           112 Hot Object Cache Items
          3234 on-disk objects

要するに cache_object://menu/[command] という形式でリクエストを投げればいろいろな情報がとれるわけです。


なお、この操作は squid.conf にて以下のような設定が有効な場合だけ利用できます。manager を無効化している場合は利用できません。(これは cachemgr.cgi でも同じですが。)

http_access allow localhost manager
http_access deny manager