# [SOLVED] reading Squid Cache Manager info from command line?

## tnt

Is there any way to read info page like this:

```
Connection information for squid:

   Number of clients accessing cache:   10

   Number of HTTP requests received:   1346

   Number of ICP messages received:   3641

   Number of ICP messages sent:   3643

   Number of queued ICP replies:   0

   Request failure ratio:    0.00

   Average HTTP requests per minute since start:   10.5

   Average ICP messages per minute since start:   56.8

   Select loop called: 89345 times, 86.103 ms avg

Cache information for squid:

   Request Hit Ratios:   5min: 88.4%, 60min: 53.5%

   Byte Hit Ratios:   5min: 8.9%, 60min: 16.6%

   Request Memory Hit Ratios:   5min: 0.0%, 60min: 0.3%

   Request Disk Hit Ratios:   5min: 37.7%, 60min: 24.0%

   Storage Swap size:   13177440 KB

   Storage Mem size:   1528 KB

   Mean Object Size:   21.85 KB

   Requests given to unlinkd:   0

Median Service Times (seconds)  5 min    60 min:

   HTTP Requests (All):   0.04776  0.17711

   Cache Misses:          0.61549  0.46965

   Cache Hits:            0.09219  0.05633

   Near Hits:             0.00000  0.20843

   Not-Modified Replies:  0.02190  0.02317

   DNS Lookups:           0.00278  0.02809

   ICP Queries:           0.00000  0.00000

Resource usage for squid:

   UP Time:   7692.907 seconds

   CPU Time:   10.990 seconds

   CPU Usage:   0.14%

   CPU Usage, 5 minute avg:   0.05%

   CPU Usage, 60 minute avg:   0.07%

   Process Data Segment Size via sbrk(): 100232 KB

   Maximum Resident Size: 0 KB

   Page faults with physical i/o: 3172

Memory usage for squid via mallinfo():

   Total space in arena:  100232 KB

   Ordinary blocks:       100126 KB     29 blks

   Small blocks:               0 KB      0 blks

   Holding blocks:          1436 KB      3 blks

   Free Small blocks:          0 KB

   Free Ordinary blocks:     105 KB

   Total in use:          101562 KB 100%

   Total free:               105 KB 0%

   Total size:            101668 KB

Memory accounted for:

   Total accounted:        77887 KB

   memPoolAlloc calls: 3395178

   memPoolFree calls: 1579977

File descriptor usage for squid:

   Maximum number of file descriptors:   1024

   Largest file desc currently in use:     44

   Number of file desc currently in use:   41

   Files queued for open:                   0

   Available number of file descriptors:  983

   Reserved number of file descriptors:   100

   Store Disk files open:                   0

Internal Data Structures:

   603203 StoreEntries

      214 StoreEntries with MemObjects

      213 Hot Object Cache Items

   603167 on-disk objects
```

from command line (shell) to be able to grep it or gawk it for some statistics and rrdtooling?  :Very Happy: 

----------

## steveb

Why do it by your self, when tools exist for such stuff:

Squid Graph

Squid Analysis Report Generator

Or you could call the CGI script included in Squid and parse that output and generate your graph from that data.

cheers

SteveB

----------

## tnt

I like customizations like these:

http://titan.blok44.net/monitor/squid-day.cgi

 :Wink: 

I just can't get 5min memory and disk hit ratios from snmp so I need to parse Cache Manager output  :Sad: 

----------

## steveb

If I remember right, then you can get that info from SNMP. Did you looked inside /usr/lib/squid/mib.txt for the infos?

BTW: /usr/lib/squid/cachemgr.cgi is a binary you can even call from the command line.

BTW: If you have enabled the cache manager on your http host, then you could use the tools from libwww-perl to get that data off from cache manager.

cheers

SteveB

----------

## tnt

1. unpacked squid source

2. hardcoded host, port, action (info), username and password to cachemgr.c

3. compiled squid and got hacked cachemgr.cgi

4. changed cachemgr.c source to avoid checking if arguments on the command line are supplied (missing arguments would bring up auth_html page)

5. now ./cachemgr.cgi gives me something like:

```
...

<tr><td colspan="1" align="left">Current Time:</td><td colspan="1" align="left">Fri, 06 Jan 2006 05:21:10 GMT</td></tr>

</table>

<pre>Connection information for squid:

        Number of clients accessing cache:      13

        Number of HTTP requests received:       5490

        Number of ICP messages received:        5858

        Number of ICP messages sent:    5867

        Number of queued ICP replies:   0

        Request failure ratio:   0.02

        Average HTTP requests per minute since start:   15.4

        Average ICP messages per minute since start:    32.9

        Select loop called: 164318 times, 130.019 ms avg

Cache information for squid:

        Request Hit Ratios:     5min: 85.2%, 60min: 54.7%

        Byte Hit Ratios:        5min: 27.5%, 60min: 16.9%

        Request Memory Hit Ratios:      5min: 0.0%, 60min: 12.8%

        Request Disk Hit Ratios:        5min: 0.0%, 60min: 43.0%

        Storage Swap size:      13178480 KB

        Storage Mem size:       2300 KB

        Mean Object Size:       21.85 KB

        Requests given to unlinkd:      0

Median Service Times (seconds)  5 min    60 min:

        HTTP Requests (All):   0.04277  0.07409

        Cache Misses:          0.00102  0.44492

        Cache Hits:            0.00000  0.01648

        Near Hits:             0.00000  0.00000

        Not-Modified Replies:  0.04277  0.03829

        DNS Lookups:           0.00278  0.03532

        ICP Queries:           0.00000  0.00000

Resource usage for squid:

        UP Time:        21364.515 seconds

        CPU Time:       19.570 seconds

        CPU Usage:      0.09%

        CPU Usage, 5 minute avg:        0.01%

        CPU Usage, 60 minute avg:       0.03%

        Process Data Segment Size via sbrk(): 102008 KB

        Maximum Resident Size: 0 KB

        Page faults with physical i/o: 3406

Memory usage for squid via mallinfo():

        Total space in arena:  102008 KB

        Ordinary blocks:       100594 KB     44 blks

        Small blocks:               0 KB      0 blks

        Holding blocks:          1436 KB      3 blks

        Free Small blocks:          0 KB

        Free Ordinary blocks:    1413 KB

        Total in use:          102030 KB 99%

        Total free:              1413 KB 1%

        Total size:            103444 KB

Memory accounted for:

        Total accounted:        78985 KB

        memPoolAlloc calls: 3975692

        memPoolFree calls: 2156576

File descriptor usage for squid:

        Maximum number of file descriptors:   1024

        Largest file desc currently in use:     33

        Number of file desc currently in use:   30

        Files queued for open:                   0

        Available number of file descriptors:  994

        Reserved number of file descriptors:   100

        Store Disk files open:                   0

Internal Data Structures:

        603315 StoreEntries

           373 StoreEntries with MemObjects

           372 Hot Object Cache Items

        603252 on-disk objects

</table></PRE>

<HR noshade size="1px">

...
```

as output, so I can grep/gawk it to make statistics of Memory and Disk Hit Ratios.

A little bit ugly way to do that, but at least it works.   :Laughing: 

Thank you.

----------

## revertex

maybe calamaris is  what you are looking for.

----------

## tnt

calamaris looks fine, but it reads informations from squid log files and there are no info about location where file was found: memory or disk.

----------

## think4urs11

squid-rrd

----------

## revertex

 *tnt wrote:*   

> calamaris looks fine, but it reads informations from squid log files and there are no info about location where file was found: memory or disk.

 

you can use something like 

```
cat /var/log/squid/access.log | calamaris -F html > squid-log.html
```

----------

## think4urs11

 *revertex wrote:*   

> ...
> 
> you can use something like 
> 
> ```
> ...

 

what he means is that he wants to know whether or not a file squid sends to the requesting client was cached in memory or cached on disk. Makes quite some difference in 'felt response time' if squid needs to read from disk first.

This information can only be gathered from the cache manager online and does not get written to any kind of log file.

Maybe this info could also be gathered via SNMP but i'm not perfectly sure on that. Squids builtin SNMP server isn't providing all the infos within its MIB than you can get via cache_object://$host/$what

----------

## tnt

 *Think4UrS11 wrote:*   

> what he means is that he wants to know whether or not a file squid sends to the requesting client was cached in memory or cached on disk. Makes quite some difference in 'felt response time' if squid needs to read from disk first.
> 
> This information can only be gathered from the cache manager online and does not get written to any kind of log file.
> 
> Maybe this info could also be gathered via SNMP but i'm not perfectly sure on that. Squids builtin SNMP server isn't providing all the infos within its MIB than you can get via cache_object://$host/$what

 

you're absolutely right.

----------

