Exemplo n.º 1
0
	def readall(self):
		"""Take a snapshot of all variables from a connection.
		
		This is much more efficient than reading all variables
		individually.  Currently, for local agents, it also guarantees
		consistency between all read-only variables.
		"""
		
		if libweb100.web100_snap(self._readsnap) != libweb100.WEB100_ERR_SUCCESS:
			libweb100_err()
		if libweb100.web100_snap(self._tunesnap) != libweb100.WEB100_ERR_SUCCESS:
			libweb100_err()
		snap = {}
		for (name, var) in self.agent.read_vars.items():
			if var._group == self.agent._read_group:
				if libweb100.web100_snap_read(var._var, self._readsnap, self.agent.bufp) != \
				   libweb100.WEB100_ERR_SUCCESS:
					libweb100_err()
			else:
				if libweb100.web100_snap_read(var._var, self._tunesnap, self.agent.bufp) != \
				   libweb100.WEB100_ERR_SUCCESS:
					libweb100_err()
			val = var.val(self.agent.bufp)
			snap[name] = val
		return snap
Exemplo n.º 2
0
    def readall(self):
        """Take a snapshot of all variables from a connection.
		
		This is much more efficient than reading all variables
		individually.  Currently, for local agents, it also guarantees
		consistency between all read-only variables.
		"""

        if libweb100.web100_snap(
                self._readsnap) != libweb100.WEB100_ERR_SUCCESS:
            libweb100_err()
        if libweb100.web100_snap(
                self._tunesnap) != libweb100.WEB100_ERR_SUCCESS:
            libweb100_err()
        snap = {}
        for (name, var) in self.agent.read_vars.items():
            if var._group == self.agent._read_group:
                if libweb100.web100_snap_read(var._var, self._readsnap, self.agent.bufp) != \
                   libweb100.WEB100_ERR_SUCCESS:
                    libweb100_err()
            else:
                if libweb100.web100_snap_read(var._var, self._tunesnap, self.agent.bufp) != \
                   libweb100.WEB100_ERR_SUCCESS:
                    libweb100_err()
            val = var.val(self.agent.bufp)
            snap[name] = val
        return snap
Exemplo n.º 3
0
def mkdict(ctl, new, old):
    """
    Convert a tctrl and two snaps into a dictionary.   This parallels John Heffners
    new python API for Web100, but handles deltas differently.

    Don't compute deltas, if there is no prior (old) sample.

    """
    r = {}

    # process the control structure
    # eeeewww clearly this is lame XXX
    r["flag"]=ctl.flag
    r["basemss"]=ctl.basemss
    r["win"]=ctl.win
    r["burstwin"]=ctl.burstwin
    r["duration"]=ctl.duration
    r["obswin"]=ctl.obswin
    r["SSbursts"]=ctl.SSbursts
    r["SSbully"]=ctl.SSbully
    r["SSbullyStall"]=ctl.SSbullyStall
    r["SSsumAwnd"]=ctl.SSsumAwnd
    r["SScntAwnd"]=ctl.SScntAwnd
    r["SSpoll"]=ctl.SSpoll

    # Process the snaps
    # This interim version violates clean layering:
    # it uses a hybrid of libweb100 and PyWeb100

    v = libweb100.web100_var_head(cvar.gread)
    while v:
	vv = PyWeb100.Web100Var(v, cvar.gread)   # ugly

        n = libweb100.web100_get_var_name(v)
        t = libweb100.web100_get_var_type(v)
	if libweb100.web100_snap_read(v, new, cvar.nbuf) != libweb100.WEB100_ERR_SUCCESS:
	    raise "snap read fail"
	if old:
	    if libweb100.web100_snap_read(v, old, cvar.obuf) != libweb100.WEB100_ERR_SUCCESS:
		raise "snap read fail"
        if   ( t == libweb100.WEB100_TYPE_COUNTER32 ):
	    r["abs_"+n]=rntohl(vv.val(cvar.nbuf))	# abs_ is absolute magnitude
	    if old:
		delta = rntohl(vv.val(cvar.nbuf)) - rntohl(vv.val(cvar.obuf))
		if delta < 0:
		    delta = delta + 4294967296
		r[n] = delta
        elif   ( t == libweb100.WEB100_TYPE_COUNTER64 ):
	    r["abs_"+n]=rntohll(vv.val(cvar.nbuf))	# abs_ is absolute magnitude
	    if old:
		# rntohl() is wrong
		delta = rntohll(vv.val(cvar.nbuf)) - rntohll(vv.val(cvar.obuf))
		if delta < 0:
		    delta = delta + 18446744073709551616
		r[n] = delta
        elif ( t == libweb100.WEB100_TYPE_GAUGE32 or
	       t == libweb100.WEB100_TYPE_INTEGER32 or
	       t == libweb100.WEB100_TYPE_UNSIGNED32 or
	       t == libweb100.WEB100_TYPE_TIME_TICKS or
	       t == libweb100.WEB100_TYPE_INTEGER ):
	    r[n] = rntohl(vv.val(cvar.nbuf))
        else:
            r[n] = vv.val(cvar.nbuf)
        v = libweb100.web100_var_next(v)
#	vv.free()
    return(r)
Exemplo n.º 4
0
def mkdict(ctl, new, old):
    """
    Convert a tctrl and two snaps into a dictionary.   This parallels John Heffners
    new python API for Web100, but handles deltas differently.

    Don't compute deltas, if there is no prior (old) sample.

    """
    r = {}

    # process the control structure
    # eeeewww clearly this is lame XXX
    r["flag"] = ctl.flag
    r["basemss"] = ctl.basemss
    r["win"] = ctl.win
    r["burstwin"] = ctl.burstwin
    r["duration"] = ctl.duration
    r["obswin"] = ctl.obswin
    r["SSbursts"] = ctl.SSbursts
    r["SSbully"] = ctl.SSbully
    r["SSbullyStall"] = ctl.SSbullyStall
    r["SSsumAwnd"] = ctl.SSsumAwnd
    r["SScntAwnd"] = ctl.SScntAwnd
    r["SSpoll"] = ctl.SSpoll

    # Process the snaps
    # This interim version violates clean layering:
    # it uses a hybrid of libweb100 and PyWeb100

    v = libweb100.web100_var_head(cvar.gread)
    while v:
        vv = PyWeb100.Web100Var(v, cvar.gread)  # ugly

        n = libweb100.web100_get_var_name(v)
        t = libweb100.web100_get_var_type(v)
        if libweb100.web100_snap_read(
                v, new, cvar.nbuf) != libweb100.WEB100_ERR_SUCCESS:
            raise "snap read fail"
        if old:
            if libweb100.web100_snap_read(
                    v, old, cvar.obuf) != libweb100.WEB100_ERR_SUCCESS:
                raise "snap read fail"
        if (t == libweb100.WEB100_TYPE_COUNTER32):
            r["abs_" + n] = rntohl(vv.val(
                cvar.nbuf))  # abs_ is absolute magnitude
            if old:
                delta = rntohl(vv.val(cvar.nbuf)) - rntohl(vv.val(cvar.obuf))
                if delta < 0:
                    delta = delta + 4294967296
                r[n] = delta
        elif (t == libweb100.WEB100_TYPE_COUNTER64):
            r["abs_" + n] = rntohll(vv.val(
                cvar.nbuf))  # abs_ is absolute magnitude
            if old:
                # rntohl() is wrong
                delta = rntohll(vv.val(cvar.nbuf)) - rntohll(vv.val(cvar.obuf))
                if delta < 0:
                    delta = delta + 18446744073709551616
                r[n] = delta
        elif (t == libweb100.WEB100_TYPE_GAUGE32
              or t == libweb100.WEB100_TYPE_INTEGER32
              or t == libweb100.WEB100_TYPE_UNSIGNED32
              or t == libweb100.WEB100_TYPE_TIME_TICKS
              or t == libweb100.WEB100_TYPE_INTEGER):
            r[n] = rntohl(vv.val(cvar.nbuf))
        else:
            r[n] = vv.val(cvar.nbuf)
        v = libweb100.web100_var_next(v)
#	vv.free()
    return (r)