-
Notifications
You must be signed in to change notification settings - Fork 1
/
neutron-timings.py
executable file
·56 lines (42 loc) · 1.17 KB
/
neutron-timings.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env python
import re
import os
import time
import sys
import socket
from neutronclient.v2_0 import client as neutronclient
STATS_PREFIX = "openstack.neutron"
if not re.match(".$", STATS_PREFIX):
STATS_PREFIX += "."
USER=os.environ['OS_USERNAME']
PASS=os.environ['OS_PASSWORD']
TENANT_NAME=os.environ['OS_TENANT_NAME']
OS_AUTH_URL=os.environ['OS_AUTH_URL']
GRAPHITE_HOST="10.64.140.42"
def neutronConnect():
return neutronclient.Client(username=USER, password=PASS, tenant_name=TENANT_NAME, auth_url=OS_AUTH_URL)
def collect_metric(name, value, timestamp):
sock = socket.socket()
sock.settimeout(5)
sock.connect( (GRAPHITE_HOST, 2003) )
print "%s %s %d" % (STATS_PREFIX + name, value, timestamp)
sock.send("%s %s %d\n" % (STATS_PREFIX + name, value, timestamp))
sock.close()
def now():
return time.time()
#main
neutron = neutronConnect()
# network timings/counts
try:
start = now()
networks = neutron.list_networks()
end = now()
if networks:
networkstime = round(end - start, 4)
collect_metric("timings.networks.list", networkstime, now())
except:
print "networks.list failed"
# exit cleanly
sys.stdout.flush()
sys.stderr.flush()
sys.exit(0)