Skip to content

Commit e428aee

Browse files
get_metrics()
1 parent f58b172 commit e428aee

File tree

3 files changed

+53
-0
lines changed

3 files changed

+53
-0
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,3 +172,11 @@ You can use this method you use to send an event to Sysdig Cloud. The events you
172172
A dictionary describing the new event.
173173
**Example**
174174
[examples/post_event.py](examples/post_event.py).
175+
176+
#### get_metrics(self)
177+
**Description**
178+
Return the metric list that can be used for data requests/alerts/dashboards.
179+
**Success Return Value**
180+
A dictionary containing the list of available metrics.
181+
**Example**
182+
[examples/list_metrics.py](examples/list_metrics.py).

examples/list_metrics.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/usr/bin/env python
2+
#
3+
# Print the list of dashboards.
4+
#
5+
6+
import sys
7+
sys.path.insert(0, '../')
8+
from sdcclient import SdcClient
9+
10+
#
11+
# Parse arguments
12+
#
13+
if len(sys.argv) != 2:
14+
print 'usage: %s <sysdig-token>' % sys.argv[0]
15+
print 'You can find your token at https://app.sysdigcloud.com/#/settings/user'
16+
sys.exit(0)
17+
18+
sdc_token = sys.argv[1]
19+
20+
#
21+
# Instantiate the SDC client
22+
#
23+
sdclient = SdcClient(sdc_token)
24+
25+
#
26+
# Fire the request.
27+
#
28+
res = sdclient.get_metrics()
29+
30+
#
31+
# Show the list of metrics
32+
#
33+
if res[0]:
34+
data = res[1]
35+
else:
36+
print res[1]
37+
sys.exit(0)
38+
39+
print data

sdcclient/_client.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,3 +504,9 @@ def get_data(self, metrics, start_ts, end_ts=0, sampling_s=0,
504504
if not self.__checkResponse(r):
505505
return [False, self.lasterr]
506506
return [True, r.json()]
507+
508+
def get_metrics(self):
509+
r = requests.get(self.url + '/api/data/metrics', headers=self.hdrs)
510+
if not self.__checkResponse(r):
511+
return [False, self.lasterr]
512+
return [True, r.json()]

0 commit comments

Comments
 (0)