Skip to content

Commit 7892c8b

Browse files
authored
Merge pull request #10 from Netuitive/feature/dockerfile
Example Script Dockerfile
2 parents a41e27b + 0779310 commit 7892c8b

4 files changed

Lines changed: 62 additions & 29 deletions

File tree

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
docs

Dockerfile

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
FROM python:2-slim
2+
3+
RUN mkdir -p /opt/app/
4+
WORKDIR /opt/app/
5+
6+
RUN ln -sf /usr/share/zoneinfo/America/New_York /etc/localtime
7+
8+
ADD requirements.txt /opt/app/
9+
ADD test_requirements.txt /opt/app/
10+
11+
RUN pip install -r /opt/app/requirements.txt
12+
RUN pip install -r /opt/app/test_requirements.txt
13+
14+
ADD . /opt/app/
15+
16+
RUN python setup.py test
17+
RUN python setup.py install
18+
19+
RUN ln -sf /usr/share/zoneinfo/UTC /etc/localtime
20+
21+
ENV API_URL https://api.app.netuitive.com/ingest
22+
ENV CUSTOM_API_KEY change-me-apikey
23+
24+
CMD python example/example.py

README.rst

Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -112,40 +112,18 @@ Check that our local time is set correctly (returns True/False)
112112

113113
``ApiClient.time_insync()``
114114

115-
Example
115+
Docker Example
116116
----------
117-
The below example sets up the Netuitive Python client, creates an element ("MyElement") with attributes, a relationship, and tags and then passes in some samples. After the element is posted, the samples are cleared, an event is created and posted.
118-
::
119-
120-
import netuitive
121-
import time
122-
123-
ApiClient = netuitive.Client(api_key='aaaa9956110211e594444697f922ec7b')
124-
125-
MyElement = netuitive.Element()
126-
127-
MyElement.add_attribute('Language', 'Python')
128-
MyElement.add_attribute('app_version', '7.0')
129-
130-
MyElement.add_relation('my_child_element')
117+
Included in this project is an example python script (`example/example.py`) which can be built and run within a Docker container. To send test data into your Netuitive environment run the following:
131118

132-
MyElement.add_tag('Production', 'True')
133-
MyElement.add_tag('app_tier', 'True')
134-
135-
timestamp = int(time.mktime(time.gmtime()))
136-
MyElement.add_sample('app.error', timestamp, 1, host='appserver01')
137-
MyElement.add_sample('app.request', timestamp, 10, host='appserver01')
138-
139-
ApiClient.post(MyElement)
140-
141-
MyElement.clear_samples()
119+
::
142120

143-
MyEvent = netuitive.Event('appserver01', 'INFO', 'test event','this is a test message', 'INFO')
121+
docker build -t netuitive-client-python .
122+
docker run -e CUSTOM_API_KEY=<custom-api-key> netuitive-client-python
144123

145-
ApiClient.post_event(MyEvent)
124+
::
146125

147-
if ApiClient.time_insync():
148-
print('we have time sync with the server')
126+
Make sure to use your **Custom** Netuitive datasource API key.
149127

150128
Copyright and License
151129
---------------------

example/example.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import netuitive
2+
import time
3+
import os
4+
5+
ApiClient = netuitive.Client(url=os.environ.get('API_URL'), api_key=os.environ.get('CUSTOM_API_KEY'))
6+
7+
MyElement = netuitive.Element()
8+
9+
MyElement.add_attribute('Language', 'Python')
10+
MyElement.add_attribute('app_version', '7.0')
11+
12+
MyElement.add_relation('my_child_element')
13+
14+
MyElement.add_tag('Production', 'True')
15+
MyElement.add_tag('app_tier', 'True')
16+
17+
timestamp = int(time.mktime(time.gmtime()))
18+
MyElement.add_sample('app.error', timestamp, 1, host='appserver01')
19+
MyElement.add_sample('app.request', timestamp, 10, host='appserver01')
20+
21+
ApiClient.post(MyElement)
22+
23+
MyElement.clear_samples()
24+
25+
MyEvent = netuitive.Event('appserver01', 'INFO', 'test event','this is a test message', 'INFO')
26+
27+
ApiClient.post_event(MyEvent)
28+
29+
if ApiClient.time_insync():
30+
print('we have time sync with the server')

0 commit comments

Comments
 (0)