Exemplo n.º 1
0
static void
netdbPurgeLRU(void)
{
    netdbEntry *n;
    netdbEntry **list;
    int k = 0;
    int list_count = 0;
    int removed = 0;
    list = xcalloc(memInUse(MEM_NETDBENTRY), sizeof(netdbEntry *));
    hash_first(addr_table);
    while ((n = (netdbEntry *) hash_next(addr_table))) {
        assert(list_count < memInUse(MEM_NETDBENTRY));
        *(list + list_count) = n;
        list_count++;
    }
    qsort((char *) list,
          list_count,
          sizeof(netdbEntry *),
          netdbLRU);
    for (k = 0; k < list_count; k++) {
        if (memInUse(MEM_NETDBENTRY) < Config.Netdb.low)
            break;
        netdbRelease(*(list + k));
        removed++;
    }
    xfree(list);
}
Exemplo n.º 2
0
void
netdbDump(StoreEntry * sentry)
{
    netdbEntry *n;
    netdbEntry **list;
    net_db_name *x;
    int k;
    int i;
    int j;
    net_db_peer *p;
    storeAppendPrintf(sentry, "Network DB Statistics:\n");
    storeAppendPrintf(sentry, "%-16.16s %9s %7s %5s %s\n",
                      "Network",
                      "recv/sent",
                      "RTT",
                      "Hops",
                      "Hostnames");
    list = xcalloc(memInUse(MEM_NETDBENTRY), sizeof(netdbEntry *));
    i = 0;
    hash_first(addr_table);
    while ((n = (netdbEntry *) hash_next(addr_table)))
        *(list + i++) = n;
    if (i != memInUse(MEM_NETDBENTRY))
        debug(38, 0) ("WARNING: netdb_addrs count off, found %d, expected %d\n",
                      i, memInUse(MEM_NETDBENTRY));
    qsort((char *) list,
          i,
          sizeof(netdbEntry *),
          sortByRtt);
    for (k = 0; k < i; k++) {
        n = *(list + k);
        storeAppendPrintf(sentry, "%-16.16s %4d/%4d %7.1f %5.1f",
                          n->network,
                          n->pings_recv,
                          n->pings_sent,
                          n->rtt,
                          n->hops);
        for (x = n->hosts; x; x = x->next)
            storeAppendPrintf(sentry, " %s", hashKeyStr(&x->hash));
        storeAppendPrintf(sentry, "\n");
        p = n->peers;
        for (j = 0; j < n->n_peers; j++, p++) {
            storeAppendPrintf(sentry, "    %-22.22s %7.1f %5.1f\n",
                              p->peername,
                              p->rtt,
                              p->hops);
        }
    }
    xfree(list);
}
Exemplo n.º 3
0
static netdbEntry *
netdbAdd(struct in_addr addr)
{
    netdbEntry *n;
    if (memInUse(MEM_NETDBENTRY) > Config.Netdb.high)
        netdbPurgeLRU();
    if ((n = netdbLookupAddr(addr)) == NULL) {
        n = memAllocate(MEM_NETDBENTRY);
        netdbHashInsert(n, addr);
    }
    return n;
}
Exemplo n.º 4
0
void
storeDirStats(StoreEntry * sentry)
{
    storeAppendPrintf(sentry, "Store Directory Statistics:\n");
    storeAppendPrintf(sentry, "Store Entries          : %d\n",
	memInUse(MEM_STOREENTRY));
    storeAppendPrintf(sentry, "Maximum Swap Size      : %8d KB\n",
	Config.Swap.maxSize);
    storeAppendPrintf(sentry, "Current Store Swap Size: %8d KB\n",
	store_swap_size);
    storeAppendPrintf(sentry, "Current Capacity       : %d%% used, %d%% free\n",
	percent((int) store_swap_size, (int) Config.Swap.maxSize),
	percent((int) (Config.Swap.maxSize - store_swap_size), (int) Config.Swap.maxSize));
    storeUfsDirStats(sentry);	/* XXX */
}
Exemplo n.º 5
0
/* calculates digest capacity */
static int
storeDigestCalcCap(void)
{
    /*
     * To-Do: Bloom proved that the optimal filter utilization is 50% (half of
     * the bits are off). However, we do not have a formula to calculate the 
     * number of _entries_ we want to pre-allocate for.
     */
    const int hi_cap = Config.Swap.maxSize / Config.Store.avgObjectSize;
    const int lo_cap = 1 + store_swap_size / Config.Store.avgObjectSize;
    const int e_count = memInUse(MEM_STOREENTRY);
    int cap = e_count ? e_count : hi_cap;
    debug(71, 2) ("storeDigestCalcCap: have: %d, want %d entries; limits: [%d, %d]\n",
	e_count, cap, lo_cap, hi_cap);
    if (cap < lo_cap)
	cap = lo_cap;
    /* do not enforce hi_cap limit, average-based estimation may be wrong
     *if (cap > hi_cap)
     *  cap = hi_cap; 
     */
    return cap;
}
Exemplo n.º 6
0
variable_list *
snmp_prfSysFn(variable_list * Var, snint * ErrP)
{
    variable_list *Answer = NULL;
    static struct rusage rusage;
    debug(49, 5) ("snmp_prfSysFn: Processing request with magic %d!\n", Var->name[LEN_SQ_PRF + 1]);
    *ErrP = SNMP_ERR_NOERROR;
    switch (Var->name[LEN_SQ_PRF + 1]) {
    case PERF_SYS_PF:
	squid_getrusage(&rusage);
	Answer = snmp_var_new_integer(Var->name, Var->name_length,
	    rusage_pagefaults(&rusage),
	    SMI_COUNTER32);
	break;
    case PERF_SYS_NUMR:
	Answer = snmp_var_new_integer(Var->name, Var->name_length,
	    IOStats.Http.reads,
	    SMI_COUNTER32);
	break;
    case PERF_SYS_MEMUSAGE:
	Answer = snmp_var_new_integer(Var->name, Var->name_length,
	    (snint) statMemoryAccounted() >> 10,
	    ASN_INTEGER);
	break;
    case PERF_SYS_CPUTIME:
	squid_getrusage(&rusage);
	Answer = snmp_var_new_integer(Var->name, Var->name_length,
	    (snint) rusage_cputime(&rusage),
	    ASN_INTEGER);
	break;
    case PERF_SYS_CPUUSAGE:
	squid_getrusage(&rusage);
	Answer = snmp_var_new_integer(Var->name, Var->name_length,
	    (snint) dpercent(rusage_cputime(&rusage), tvSubDsec(squid_start, current_time)),
	    ASN_INTEGER);
	break;
    case PERF_SYS_MAXRESSZ:
	squid_getrusage(&rusage);
	Answer = snmp_var_new_integer(Var->name, Var->name_length,
	    (snint) rusage_maxrss(&rusage),
	    ASN_INTEGER);
	break;
    case PERF_SYS_CURLRUEXP:
	/* No global LRU info anymore */
	Answer = snmp_var_new_integer(Var->name, Var->name_length,
	    0,
	    SMI_TIMETICKS);
	break;
    case PERF_SYS_CURUNLREQ:
	Answer = snmp_var_new_integer(Var->name, Var->name_length,
	    (snint) statCounter.unlink.requests,
	    SMI_COUNTER32);
	break;
    case PERF_SYS_CURUNUSED_FD:
	Answer = snmp_var_new_integer(Var->name, Var->name_length,
	    (snint) Squid_MaxFD - Number_FD,
	    SMI_GAUGE32);
	break;
    case PERF_SYS_CURRESERVED_FD:
	Answer = snmp_var_new_integer(Var->name, Var->name_length,
	    (snint) RESERVED_FD,
	    SMI_GAUGE32);
	break;
    case PERF_SYS_NUMOBJCNT:
	Answer = snmp_var_new_integer(Var->name, Var->name_length,
	    (snint) memInUse(MEM_STOREENTRY),
	    SMI_GAUGE32);
	break;
    default:
	*ErrP = SNMP_ERR_NOSUCHNAME;
	break;
    }
    return Answer;
}
void
netdbDump(StoreEntry * sentry)
{
#if USE_ICMP
    netdbEntry *n;
    netdbEntry **list;
    net_db_name *x;
    int k;
    int i;
    int j;
    net_db_peer *p;
    storeAppendPrintf(sentry, "Network DB Statistics:\n");
    storeAppendPrintf(sentry, "%-16.16s %9s %7s %5s %s\n",
	"Network",
	"recv/sent",
	"RTT",
	"Hops",
	"Hostnames");
    list = xcalloc(memInUse(MEM_NETDBENTRY), sizeof(netdbEntry *));
    i = 0;
    hash_first(addr_table);
    while ((n = (netdbEntry *) hash_next(addr_table)))
	*(list + i++) = n;
    if (i != memInUse(MEM_NETDBENTRY))
	debug(38, 0) ("WARNING: netdb_addrs count off, found %d, expected %d\n",
	    i, memInUse(MEM_NETDBENTRY));
    qsort((char *) list,
	i,
	sizeof(netdbEntry *),
	sortByRtt);
    for (k = 0; k < i; k++) {
	n = *(list + k);
	storeAppendPrintf(sentry, "%-16.16s %4d/%4d %7.1f %5.1f",
	    n->network,
	    n->pings_recv,
	    n->pings_sent,
	    n->rtt,
	    n->hops);
	for (x = n->hosts; x; x = x->next)
	    storeAppendPrintf(sentry, " %s", hashKeyStr(&x->hash));
	storeAppendPrintf(sentry, "\n");
	p = n->peers;
	for (j = 0; j < n->n_peers; j++, p++) {
	    storeAppendPrintf(sentry, "    %-22.22s %7.1f %5.1f\n",
		p->peername,
		p->rtt,
		p->hops);
	}
    }
    xfree(list);
#else
    http_reply *reply = sentry->mem_obj->reply;
    http_version_t version;
    httpReplyReset(reply);
    httpBuildVersion(&version, 1, 0);
    httpReplySetHeaders(reply, version, HTTP_BAD_REQUEST, "Bad Request",
	NULL, -1, squid_curtime, -2);
    httpReplySwapOut(reply, sentry);
    storeAppendPrintf(sentry,
	"NETDB support not compiled into this Squid cache.\n");
#endif
}