systemadmin.es > LAMP y web > Estado de varnish con varnishstat

Estado de varnish con varnishstat

Una vez instalado el varnish, debemos monitorizar su uso para saber si estamos ganando algo o no con su instalación.

Si ejecutamos varnishstat obtendremos una salida similar a la siguiente:

Salida varnishstat

Salida varnishstat

Arriba del todo veremos los datos más relevantes:

Hitrate ratio:       10      104      104
Hitrate avg:     0.3101   0.3091   0.3171

Nos esta indicando el hitratio (servido desde cache vs servido desde backend) de los últimos 10, 100 y 1000 segundos. Como que del varnish se obtienen contadores deberemos esperarnos este tiempo para tener los datos. Mientras tanto obtendremos la media con los datos intermedios.

El hitratio debería ser cercano al 100% (por lo tanto el valor debería ser cercano a 1), por lo que en este caso, un valor de 31 nos indica que estamos utilizando muy poco la cache. Deberíamos ver si la debemos augmentar la memoria porque no caben todos los contenidos o se ve invalidada por el TTL demasiado bajo.

El resto de valores que nos muesta varnishstat estan divididos en las siguientes columnas:

  • El contador tal como lo devuelve el varnish
  • Media por segundo desde el último update del varnishstat (por defecto 1 segundo)
  • Media por segundo desde el inicio del varnish
  • Finalmente nos indica una descripción del valor

En el caso que queramos utilizar varnishstat en algún script para obtener datos podemos utilizar la opción -1 para obtener los valores sin la columna de la media desde el último update (ya que no existe):

# varnishstat -1
client_conn         176382665         6.76 Client connections accepted
client_drop                 0         0.00 Connection dropped, no sess/wrk
client_req          477137634        18.30 Client requests received
cache_hit            10349407         0.40 Cache hits
cache_hitpass         1046917         0.04 Cache hits for pass
cache_miss           28204652         1.08 Cache misses
backend_conn         20208831         0.77 Backend conn. success
backend_unhealthy            0         0.00 Backend conn. not attempted
backend_busy                0         0.00 Backend conn. too many
backend_fail              433         0.00 Backend conn. failures
backend_reuse       446487249        17.12 Backend conn. reuses
backend_toolate       6484614         0.25 Backend conn. was closed
backend_recycle     453060018        17.37 Backend conn. recycles
backend_unused              0         0.00 Backend conn. unused
fetch_head            1934840         0.07 Fetch head
fetch_length        453227314        17.38 Fetch with Length
fetch_chunked         5683113         0.22 Fetch chunked
fetch_eof                   0         0.00 Fetch EOF
fetch_bad                   0         0.00 Fetch had bad headers
fetch_close           1117030         0.04 Fetch wanted close
fetch_oldhttp               0         0.00 Fetch pre HTTP/1.1 closed
fetch_zero                  0         0.00 Fetch zero len
fetch_failed                0         0.00 Fetch failed
n_sess_mem              24913          .   N struct sess_mem
n_sess                  24811          .   N struct sess
n_object                 6239          .   N struct object
n_vampireobject             0          .   N unresurrected objects
n_objectcore             6243          .   N struct objectcore
n_objecthead             6554          .   N struct objecthead
n_smf                       0          .   N struct smf
n_smf_frag                  0          .   N small free smf
n_smf_large                 0          .   N large free smf
n_vbe_conn                  6          .   N struct vbe_conn
n_wrk                      21          .   N worker threads
n_wrk_create            32366         0.00 N worker threads created
n_wrk_failed                0         0.00 N worker threads not created
n_wrk_max                6179         0.00 N worker threads limited
n_wrk_queue                 0         0.00 N queued work requests
n_wrk_overflow         846623         0.03 N overflowed work requests
n_wrk_drop                  0         0.00 N dropped work requests
n_backend                   1          .   N backends
n_expired            28195274          .   N expired objects
n_lru_nuked                 0          .   N LRU nuked objects
n_lru_saved                 0          .   N LRU saved objects
n_lru_moved           9520237          .   N LRU moved objects
n_deathrow                  0          .   N objects on deathrow
losthdr                    30         0.00 HTTP header overflows
n_objsendfile               0         0.00 Objects sent with sendfile
n_objwrite          469620374        18.01 Objects sent with write
n_objoverflow               0         0.00 Objects overflowing workspace
s_sess              176382665         6.76 Total Sessions
s_req               477137634        18.30 Total Requests
s_pipe                    958         0.00 Total pipe
s_pass              438582568        16.82 Total pass
s_fetch             466780253        17.90 Total fetch
s_hdrbytes       169699292475      6507.81 Total header bytes
s_bodybytes      1840354031027     70575.83 Total body bytes
sess_closed          19358909         0.74 Session Closed
sess_pipeline          340639         0.01 Session Pipeline
sess_readahead         317312         0.01 Session Read Ahead
sess_linger         470920031        18.06 Session Linger
sess_herd           458790086        17.59 Session herd
shm_records       38676391331      1483.20 SHM records
shm_writes         2439290990        93.54 SHM writes
shm_flushes                 0         0.00 SHM flushes due to overflow
shm_cont              5241604         0.20 SHM MTX contention
shm_cycles              16599         0.00 SHM cycles through buffer
sm_nreq                     0         0.00 allocator requests
sm_nobj                     0          .   outstanding allocations
sm_balloc                   0          .   bytes allocated
sm_bfree                    0          .   bytes free
sma_nreq            487720518        18.70 SMA allocator requests
sma_nobj                12474          .   SMA outstanding allocations
sma_nbytes           50052523          .   SMA outstanding bytes
sma_balloc       2492686194975          .   SMA bytes allocated
sma_bfree        2492636142452          .   SMA bytes free
sms_nreq                 6997         0.00 SMS allocator requests
sms_nobj                    0          .   SMS outstanding allocations
sms_nbytes                  0          .   SMS outstanding bytes
sms_balloc            2924026          .   SMS bytes allocated
sms_bfree             2924026          .   SMS bytes freed
backend_req         466778121        17.90 Backend requests made
n_vcl                       1         0.00 N vcl total
n_vcl_avail                 1         0.00 N vcl available
n_vcl_discard               0         0.00 N vcl discarded
n_purge                156266          .   N total active purges
n_purge_add            674377         0.03 N new purges added
n_purge_retire         518111         0.02 N old purges deleted
n_purge_obj_test      9594080         0.37 N objects tested
n_purge_re_test     728341627        27.93 N regexps tested against
n_purge_dups           466204         0.02 N duplicate purges removed
hcb_nolock           39599796         1.52 HCB Lookups without lock
hcb_lock             27088194         1.04 HCB Lookups with lock
hcb_insert           27088101         1.04 HCB Inserts
esi_parse                   0         0.00 Objects ESI parsed (unlock)
esi_errors                  0         0.00 ESI parse errors (unlock)
accept_fail                 0         0.00 Accept failures
client_drop_late            0         0.00 Connection dropped late
uptime               26076266         1.00 Client uptime
backend_retry            4839         0.00 Backend conn. retry
dir_dns_lookups             0         0.00 DNS director lookups
dir_dns_failed              0         0.00 DNS director failed lookups
dir_dns_hit                 0         0.00 DNS director cached lookups hit
dir_dns_cache_full            0         0.00 DNS director full dnscache
fetch_1xx                   0         0.00 Fetch no body (1xx)
fetch_204                   0         0.00 Fetch no body (204)
fetch_304             4817956         0.18 Fetch no body (304)

Es lo mismo que conectarnos al puerto de control del varnish y ejecutamos el comando stats:

[root@caronte ~]# telnet localhost 2000
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
200 194     
-----------------------------
Varnish Cache CLI 1.0
-----------------------------
Linux,2.6.18-194.el5,x86_64,-smalloc,-hcritbit

Type 'help' for command list.
Type 'quit' to close CLI session.

stats
200 2231    
   176388114  Client connections accepted
   477151352  Client requests received
    10349669  Cache hits
     1046932  Cache hits for pass
    28205704  Cache misses
    20209494  Backend conn. success
         433  Backend conn. failures
   446500044  Backend conn. reuses
(...)

Mediante la opción -l podemos obtener el listado de contadores y su descripción:

# varnishstat -l 
Varnishstat -f option fields:
Field name           Description
----------           -----------
client_conn          Client connections accepted
client_drop          Connection dropped, no sess/wrk
client_req           Client requests received
cache_hit            Cache hits
cache_hitpass        Cache hits for pass
cache_miss           Cache misses
backend_conn         Backend conn. success
backend_unhealthy    Backend conn. not attempted
backend_busy         Backend conn. too many
backend_fail         Backend conn. failures
backend_reuse        Backend conn. reuses
backend_toolate      Backend conn. was closed
backend_recycle      Backend conn. recycles
backend_unused       Backend conn. unused
(...)

En el caso que queramos obtener únicamente un determinado valor podemos usar la opción -1 combinado con la opción -f indicando el valor a obtener:

# varnishstat -f cache_hit -1
cache_hit            10349461         0.40 Cache hits

Deja un comentario:

XHTML - Tags permitidos:<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>