Exemplo n.º 1
0
int
reconnect(void)
{
    int	    		sts;
    int			ctx;
    __pmContext		*ctxp;

    if ((ctx = pmWhichContext()) >= 0)
	ctxp = __pmHandleToPtr(ctx);
    if (ctx < 0 || ctxp == NULL) {
	fprintf(stderr, "%s: reconnect botch: cannot get context: %s\n", pmProgname, pmErrStr(ctx));
	exit(1);
    }
    sts = pmReconnectContext(ctx);
    if (sts >= 0) {
	time_t      now;
	time(&now);
	fprintf(stderr, "%s: re-established connection to PMCD on \"%s\" at %s\n",
		pmProgname, pmcd_host, ctime(&now));
	pmcdfd = ctxp->c_pmcd->pc_fd;
	__pmFD_SET(pmcdfd, &fds);
	numfds = maxfd() + 1;
    }
    PM_UNLOCK(ctxp->c_lock);
    return sts;
}
Exemplo n.º 2
0
int
reconnect(void)
{
    int	    		sts;
    int			ctx;
    time_t		now;
    __pmContext		*ctxp;

    if ((ctx = pmWhichContext()) >= 0)
	ctxp = __pmHandleToPtr(ctx);
    if (ctx < 0 || ctxp == NULL) {
	fprintf(stderr, "%s: reconnect botch: cannot get context: %s\n",
		pmProgname, pmErrStr(ctx));
	exit(1);
    }
    sts = pmReconnectContext(ctx);
    if (sts >= 0) {
	pmcdfd = ctxp->c_pmcd->pc_fd;
	__pmFD_SET(pmcdfd, &fds);
	numfds = maxfd() + 1;
    }
    PM_UNLOCK(ctxp->c_lock);
    if (sts < 0)
	return sts;

    time(&now);
    fprintf(stderr, "%s: re-established connection to PMCD on \"%s\" at %s",
	    pmProgname, pmcd_host, ctime(&now));

    /*
     * Metrics may have changed while PMCD was unreachable, so we
     * need to recheck each metric to make sure that its PMID and
     * semantics have not changed.  We cannot recover if there is
     * an incompatible change - must defer to controlling scripts
     * or processes (a new-named archive will have to be created,
     * from a new pmlogger process, and pmlogrewrite/pmlogextract
     * will need to become involved if they need to be merged).
     */
    validate_metrics();

    /*
     * All metrics have been validated, however, this state change
     * represents a potential gap in the stream of metrics.  So we
     * must store a <mark> record at this point.
     */
     if ((sts = putmark()) < 0) {
	fprintf(stderr, "putmark: %s\n", pmErrStr(sts));
	exit(1);
    }

    return 0;
}
Exemplo n.º 3
0
/* reconnect attempt to host */
int
reconnect(Host *h)
{
    Fetch	*f;

    f = h->fetches;
    while (f) {
	if (pmReconnectContext(f->handle) < 0)
	    return 0;
	if (clientid != NULL)
	    /* re-register client id with pmcd */
	    __pmSetClientId(clientid);
	f = f->next;
    }
    return 1;
}
Exemplo n.º 4
0
int
QmcContext::fetch(bool update)
{
    int i, sts;
    pmResult *result;

    for (i = 0; i < my.metrics.size(); i++) {
        QmcMetric *metric = my.metrics[i];
        if (metric->status() < 0)
            continue;
        metric->shiftValues();
    }

    // Inform each indom that we are about to do a new fetch so any
    // indom changes are now irrelevant
    for (i = 0; i < my.indoms.size(); i++)
        my.indoms[i]->newFetch();

    sts = pmUseContext(my.context);
    if (sts >= 0) {
        for (i = 0; i < my.indoms.size(); i++) {
            if (my.indoms[i]->diffProfile())
                sts = my.indoms[i]->genProfile();
        }
    }
    else if (pmDebug & DBG_TRACE_OPTFETCH) {
        QTextStream cerr(stderr);
        cerr << "QmcContext::fetch: Unable to switch to this context: "
             << pmErrStr(sts) << endl;
    }

    if (sts >= 0 && my.needReconnect) {
        sts = pmReconnectContext(my.context);
        if (sts >= 0) {
            my.needReconnect = false;
            if (pmDebug & DBG_TRACE_PMC) {
                QTextStream cerr(stderr);
                cerr << "QmcContext::fetch: Reconnected context \""
                     << *my.source << endl;
            }
        }
        else if (pmDebug & DBG_TRACE_PMC) {
            QTextStream cerr(stderr);
            cerr << "QmcContext::fetch: Reconnect failed: "
                 << pmErrStr(sts) << endl;
        }
    }

    if (sts >= 0 && my.pmids.size()) {
        if (pmDebug & DBG_TRACE_OPTFETCH) {
            QTextStream cerr(stderr);
            cerr << "QmcContext::fetch: fetching context " << *this << endl;
        }

        sts = pmFetch(my.pmids.size(),
                      (pmID *)(my.pmids.toVector().data()), &result);
        if (sts >= 0) {
            my.previousTime = my.currentTime;
            my.currentTime = result->timestamp;
            my.delta = __pmtimevalSub(&my.currentTime, &my.previousTime);
            for (i = 0; i < my.metrics.size(); i++) {
                QmcMetric *metric = my.metrics[i];
                if (metric->status() < 0)
                    continue;
                Q_ASSERT((int)metric->idIndex() < result->numpmid);
                metric->extractValues(result->vset[metric->idIndex()]);
            }
            pmFreeResult(result);
        }
        else {
            if (pmDebug & DBG_TRACE_OPTFETCH) {
                QTextStream cerr(stderr);
                cerr << "QmcContext::fetch: pmFetch: " << pmErrStr(sts) << endl;
            }
            for (i = 0; i < my.metrics.size(); i++) {
                QmcMetric *metric = my.metrics[i];
                if (metric->status() < 0)
                    continue;
                metric->setError(sts);
            }
            if (sts == PM_ERR_IPC || sts == PM_ERR_TIMEOUT)
                my.needReconnect = true;
        }

        if (update) {
            if (pmDebug & DBG_TRACE_OPTFETCH) {
                QTextStream cerr(stderr);
                cerr << "QmcContext::fetch: Updating metrics" << endl;
            }
            for (i = 0; i < my.metrics.size(); i++) {
                QmcMetric *metric = my.metrics[i];
                if (metric->status() < 0)
                    continue;
                metric->update();
            }
        }
    }
    else if (pmDebug & DBG_TRACE_OPTFETCH) {
        QTextStream cerr(stderr);
        cerr << "QmcContext::fetch: nothing to fetch" << endl;
    }

    return sts;
}