示例#1
0
    def g_copy_history(self, endclock):
        lastclock = self._get_lastcopyclock()
        startclock = cf.clockaddminutes(endclock, -D_HISTORY_COPY_CLOCK_RANGE)
        if lastclock <= 0:
            lastclock = startclock
        if startclock > lastclock and lastclock > 0:
            endclock2 = cf.clockaddminutes(lastclock, +D_HISTORY_COPY_CLOCK_RANGE*2)
            endclock = min(endclock, endclock2)
        startclock = startclock

        condlist = ["itemid in (%s)" % ",".join(cf.list2strlist(self._itemids))]
        condlist.append("clock >= %s" % str(startclock))
        condlist.append("clock <= %s" % str(endclock))
        strwhere = sf.list2where(condlist)

        strsql = "select itemid, clock, value from history %s;" % (strwhere)
        if DEBUG:
            print strsql
            cf.log(strsql)

        g_zbx = sf.g_get_data(MYSQL_ZBX, strsql)
        strsql = ""
        for row in g_zbx:
            (itemid, clock, value) = row
            yield row
            strsql = "%sreplace into history (itemid, clock, value) values(%s,%s,%s);\n" \
                % (strsql, itemid, clock, value)
        sf.exec_updsql(MYSQL_JUBATUS, strsql)
        self._upd_lastcopyclock(endclock)
示例#2
0
    def remove_history(self, basendclock):
        limitclock = basendclock - D_DATA_KEEP_PERIOD*60
        condlist = ["itemid in (%s)" % ",".join(cf.list2strlist(self._itemids))]
        condlist.append("clock <= %s" % str(limitclock))
        strwhere = sf.list2where(condlist)

        strsql = "delete from history %s;" % (strwhere)

        sf.exec_updsql(MYSQL_JUBATUS, strsql)
示例#3
0
    def g_get_history(self, endclock):
        itemids = self._itemids
        startclock = cf.clockaddminutes(endclock, -LEARN_PERIOD)
        condlist = ["itemid in (%s)" % ",".join(cf.list2strlist(itemids))]
        condlist.append("clock >= %d" % int(startclock))
        condlist.append("clock <= %d" % int(endclock))
        strwhere = sf.list2where(condlist)

        # Get history data from Zabbix
        strsql = "select itemid, clock, value from history %s order by clock, itemid;" % (strwhere)
        if DEBUG:
            cf.log(strsql)

        g_data = sf.g_get_data(MYSQL_JUBATUS, strsql)
        for row in g_data:
            (itemid, clock, value) = row
            yield (itemid, clock, value)