1

I am developing a dashboard for system monitoring. I have been using ceilometer's python API before. But I have noticed that every time I run the program it sends the data from the start this way same data is repeated many time. Is there a way in Ceilometer that when I query for my data It sends me the current value of the system. My code is below

auth=v2.Password(auth_url="url", username="username", password="pass", tenant_id='009867')


sess = session.Session(auth=auth,verify=False)    
token = auth.get_token(sess)

cclient = client.get_client(2, ceilometer_url="http://orbit1.ds.cs.umu.se:8777/", token=token,verify=False)


data = cclient.samples.list(meter_name ='cpu_util')


thing = {}
msg = {}
cols = []

for row in data:
    col = {}
    col = {"x": row.timestamp, "y": row.counter_volume}
    cols.append(col)



msg['columns'] = cols

thing['message'] = msg

print json.dumps(thing, indent=4)
Imo
  • 1,455
  • 4
  • 28
  • 53

2 Answers2

1

You can get the latest entry in the ceilometer database by adding limit parameter into the query like :

data = cclient.samples.list(meter_name ='cpu_util', limit=1)
Stephen Rauch
  • 47,830
  • 31
  • 106
  • 135
Deepika
  • 41
  • 3
0

You can use filtering queries to get samples list in an interval of time. Keep the last sample you got somewhere so each time you fetch samples starting from that timestamp.

query = [dict(field='timestamp', op='gt', value=start_timestamp), dict(field='timestamp', op='lt', value=end_timestamp)]                          
print cclient.statistics.list(meter_name='cpu_util', q = query)
AhlyM
  • 510
  • 1
  • 6
  • 16