コード例 #1
0
def get_time_series(metric_name):
    """Sends an HTTP query to the tsdb getting a single
        time_series corresponding to a metric
    """
    series = odb.ts_get(metric_name, dt.datetime(2016, 1, 18, 14, 10),
                        dt.datetime(2016, 12, 24, 11, 30))
    return series
コード例 #2
0
def gatherOpenTsdSubnetStats(openTsdHost, subnetItem, startTime, endTime, fields):
    statList = []

    if fields is None or len(fields)==0:
        return None, "No fields provided"

    for field in fields:
        try:
            print 'Subnet ID: %s' % (subnetItem['subnet_id'])
            data = opd.ts_get(field, startTime, endTime, 'subnetId=%s' % (subnetItem['subnet_id']), hostname=openTsdHost)
        except :
            data = None
            pass

        if data is not None:
            #print list(data)

            if data.empty:
                pass
            else:
                #Convert to DataFrame
                df = data.to_frame(name=field)

                #Generate Time Delta
                df['time'] = df.index
                df['delta'] = ((df['time'] - df['time'].shift()).fillna(60))
                df['deltas'] = df['delta'].apply(lambda x: int( x.total_seconds() ) )
                df['bits'] = df[field].apply(lambda x: x*8)
                df['bps'] = df.apply(lambda row: (int(row['bits'] * 1.0 / row['deltas']) if row['deltas'] >0 else 0), axis=1)

                print "Panda: df.ix=%s\n field:%s\n\n" %  (df.ix[:,'bps':'bps'], field)

    return statList, ""
コード例 #3
0
def get_host_series(metric_name, host, ts, tdelta):
    """Sends an HTTP query to the tsdb getting a single
        time_series corresponding to a (host) metric using a start datetime
        and a delta in seconds
    """
    series = odb.ts_get(metric_name,
                        ts,
                        ts + dt.timedelta(0, tdelta),
                        tags=host)
    return series
コード例 #4
0
def test_wrong_host():
  with pytest.raises(urllib2.URLError):
    ts1 = opd.ts_get('cipsi.seeds.test1.temperature', dt.datetime(2013, 04, 03), dt.datetime(2013, 04, 10), 'nodes=0013A2004061646F', hostname='haisen23.ux.ui.no', trim=False)
コード例 #5
0
def test_wrong_time_span():
  ts1 = opd.ts_get('cipsi.seeds.test1.temperature', dt.datetime(2015, 04, 03), dt.datetime(2015, 04, 10), 'node=0013A2004061646F', hostname='haisen23.ux.uis.no')
  assert len(ts1) == 0
コード例 #6
0
def test_basic_without_trim():
  ts1 = opd.ts_get('cipsi.seeds.test1.temperature', dt.datetime(2013, 04, 03), dt.datetime(2013, 04, 10), 'node=0013A2004061646F', hostname='haisen23.ux.uis.no', trim=False)
  assert len(ts1) == 5728
コード例 #7
0
def test_basic_with_trim(): #assumes all default values except hostname and tag: agg='avg', rate=False, downsample='', port=4242, trim=True
  ts1 = opd.ts_get('cipsi.seeds.test1.temperature', dt.datetime(2013, 04, 03), dt.datetime(2013, 04, 10), 'node=0013A2004061646F', hostname='haisen23.ux.uis.no')
  assert len(ts1) == 5607
コード例 #8
0
ファイル: entryPoint.py プロジェクト: BobString/openTSDBnode
import opentsdb_pandas as opd
import datetime as dt
import urllib2
import json

# Large amount of points (4567)
# ts1 = opd.ts_get('cipsi.weather.TA', dt.datetime(2014, 4, 4, 12, 00), dt.datetime(2014, 5, 6, 12, 00), 'station=44640', hostname='haisen36.ux.uis.no')

# Medium amount of points (2435)
# ts1 = opd.ts_get('cipsi.weather.TA', dt.datetime(2014, 4, 4, 12, 00), dt.datetime(2014, 4, 21, 12, 00), 'station=44640', hostname='haisen36.ux.uis.no')

# Small amount of points (1284)
ts1 = opd.ts_get(
    "cipsi.weather.TA",
    dt.datetime(2014, 4, 4, 12, 00),
    dt.datetime(2014, 4, 13, 12, 00),
    "station=44640",
    hostname="haisen36.ux.uis.no",
)

aux = json.dumps(ts1.T.as_matrix().tolist(), indent=4)
print aux