Browse Source

make the setup_metrics configurable

setup_metrics always try to send messages in batch. this patch set
will allow the program sending messages either in batch or singles

Change-Id: I0d15eb3172b1ba7307a02e13a1a69b7d77dac052
Tong Li 3 years ago
parent
commit
fbfa441d1f
1 changed files with 20 additions and 18 deletions
  1. 20
    18
      kiloeyes/tests/setup_metrics.py

+ 20
- 18
kiloeyes/tests/setup_metrics.py View File

@@ -75,32 +75,34 @@ def setup_metrics(argv):
75 75
                         print(json.dumps(MOLD))
76 76
                         print('StatusCode is %s' % res.status_code)
77 77
                         exit(0)
78
-                # multiple messages
79
-                for k in range(3):
80
-                    msg = "["
81
-                    factor = round(random.random(), 2) * 100
82
-                    MOLD['timestamp'] = the_time + k * 50000 * factor
83
-                    MOLD['value'] = i * j * k * random.random()
84
-                    msg += json.dumps(MOLD)
85
-
86
-                    for l in range(9):
78
+                # multiple messages in one request
79
+                if argv[2] == 'true':
80
+                    for k in range(3):
81
+                        msg = "["
87 82
                         factor = round(random.random(), 2) * 100
88 83
                         MOLD['timestamp'] = the_time + k * 50000 * factor
89 84
                         MOLD['value'] = i * j * k * random.random()
90
-                        msg += ',' + json.dumps(MOLD)
91
-                    msg += "]"
92
-                    res = requests.post(argv[1], data=msg)
85
+                        msg += json.dumps(MOLD)
86
+
87
+                        for l in range(9):
88
+                            factor = round(random.random(), 2) * 100
89
+                            MOLD['timestamp'] = the_time + k * 50000 * factor
90
+                            MOLD['value'] = i * j * k * random.random()
91
+                            msg += ',' + json.dumps(MOLD)
92
+                        msg += "]"
93
+                        res = requests.post(argv[1], data=msg)
94
+
95
+                        if res.status_code != 201 and res.status_code != 204:
96
+                            print(json.dumps(MOLD))
97
+                            print('StatusCode is %s' % res.status_code)
98
+                            exit(0)
93 99
 
94
-                    if res.status_code != 201 and res.status_code != 204:
95
-                        print(json.dumps(MOLD))
96
-                        print('StatusCode is %s' % res.status_code)
97
-                        exit(0)
98 100
         del MOLD_DIMENSIONS['key_' + str(a)]
99 101
         print('round finished %s' % a)
100 102
 
101 103
 if __name__ == '__main__':
102
-    if len(sys.argv) == 2:
104
+    if len(sys.argv) == 3:
103 105
         setup_metrics(sys.argv)
104 106
     else:
105 107
         print('Usage: setup_metrics endpoint. For example:')
106
-        print('       setup_metrics http://<host_ip>:9090/v20/metrics')
108
+        print('       setup_metrics http://<host_ip>:9090/v2.0/metrics false')

Loading…
Cancel
Save