Skip to content

Commit 8a317e7

Browse files
authored
Merge pull request #3 from twstokes/develop
Docker goodies
2 parents 159ae42 + e033584 commit 8a317e7

File tree

12 files changed

+308
-9
lines changed

12 files changed

+308
-9
lines changed

.dockerignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
data
2+
docker-compose

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,5 @@ ENV/
9191
data/
9292
.DS_Store
9393
config.yml
94+
95+
.vscode

Dockerfile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
FROM python:3
2+
3+
WORKDIR /app
4+
5+
COPY requirements.txt /app
6+
RUN pip install --no-cache-dir -r requirements.txt
7+
8+
COPY healthdata_influx /app
9+
10+
CMD [ "python3", "import.py", "/data/export.xml" ]

README.md

Lines changed: 68 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,84 @@ Imports Apple Health Data into InfluxDB.
44
![Grafana Screenshot](https://www.tannr.com/wp-content/uploads/2017/03/grafana.png "Grafana Screenshot")
55
Visualizing InfluxDB using [Grafana](https://grafana.com/).
66

7-
### Requirements:
7+
## How to export iOS Health Data
8+
1. Go to the Health App
9+
2. Tap the profile image at the top right
10+
3. Tap "Export Health Data"
11+
4. Save the `export.zip` file and extract its XML contents (`export.xml`) somewhere accessible by this script.
812

9-
* [Python 3](https://www.python.org/)
10-
* [InfluxDB](https://www.influxdata.com/)
13+
## Running as a complete service with Docker Compose (bonus Grafana Graphs!)
1114

12-
### Installation:
15+
This is the easiest way to get up and running quickly. This will spin up the importer, an InfluxDB database, and Grafana with a default dashboard ready to go.
16+
17+
#### Requirements:
18+
19+
* [Docker](https://www.docker.com/) with [Docker Compose](https://docs.docker.com/compose/)
20+
21+
#### Installation:
22+
23+
* Create a `data` directory at the project root and add the `export.xml` inside it
24+
25+
#### Building:
26+
27+
`docker-compose build`
28+
29+
#### Running:
30+
31+
`docker-compose up` (add `-d` to run in daemon mode)
32+
33+
#### Refreshing data:
34+
35+
1. Replace `data/export.yml` with a new version
36+
2. `docker-compose run importer`
37+
38+
## Running as a Python module or stand-alone script.
39+
40+
#### Requirements:
41+
42+
* [Python 3](https://www.python.org/)
43+
* An accessible [InfluxDB](https://www.influxdata.com/) instance
44+
45+
#### Installation:
1346

1447
* `pip install -r requirements.txt`
1548
* Rename `config_sample.yml` to `config.yml`
1649

17-
### Configuration:
50+
#### Configuration:
1851

19-
* Edit `config.yml`
52+
* Edit `config.yml` to match your InfluxDB settings (host, auth, etc.)
2053

21-
### Usage:
54+
#### Usage:
2255

2356
1. Export Health Data from iOS device
2457
2. `python3 import.py export.xml`
2558

26-
### Notes:
59+
60+
#### See also:
61+
`python import.py --help`
62+
63+
## Running as a stand-alone Docker container
64+
65+
#### Requirements:
66+
67+
* [Docker](https://www.docker.com/)
68+
69+
#### Installation:
70+
71+
* Create a `data` directory at the repo root and add the `export.xml` inside it.
72+
* (note that this can be anywhere if the volume mount point on the `docker run` command is changed)
73+
74+
#### Configuration:
75+
76+
* Edit `config.yml` to match your InfluxDB settings (host, auth, etc.)
77+
78+
#### Building:
79+
80+
`docker build . -t twstokes/healthdata_influx`
81+
82+
#### Running (at the repo root):
83+
84+
`docker run -v $PWD/data:/data:ro -v $PWD/config.yml:/app/config.yml:ro twstokes/healthdata_influx`
85+
86+
## Todo / Notes:
2787
* Does not support "Mindful Sessions"

docker-compose.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
version: '3'
2+
3+
services:
4+
importer:
5+
build: .
6+
links:
7+
- influxdb
8+
volumes:
9+
- ./data:/data:ro
10+
- ./docker-compose/config.yml:/app/config.yml:ro
11+
12+
influxdb:
13+
image: influxdb
14+
env_file:
15+
- './docker-compose/env.influxdb'
16+
17+
grafana:
18+
image: grafana/grafana:latest
19+
volumes:
20+
- ./docker-compose/grafana_datasources:/etc/grafana/provisioning/datasources
21+
- ./docker-compose/grafana_dashboard_providers:/etc/grafana/provisioning/dashboards
22+
- ./docker-compose/grafana_dashboards:/var/lib/grafana/dashboards
23+
ports:
24+
- "3000:3000"
25+
env_file:
26+
- './docker-compose/env.grafana'
27+
links:
28+
- influxdb

docker-compose/env.grafana

Whitespace-only changes.

docker-compose/env.influxdb

Whitespace-only changes.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
apiVersion: 1
2+
3+
providers:
4+
- name: 'default'
5+
orgId: 1
6+
folder: ''
7+
type: file
8+
disableDeletion: false
9+
updateIntervalSeconds: 3 #how often Grafana will scan for changed dashboards
10+
options:
11+
path: /var/lib/grafana/dashboards
Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
{
2+
"annotations": {
3+
"list": [
4+
{
5+
"builtIn": 1,
6+
"datasource": "-- Grafana --",
7+
"enable": true,
8+
"hide": true,
9+
"iconColor": "rgba(0, 211, 255, 1)",
10+
"name": "Annotations & Alerts",
11+
"type": "dashboard"
12+
}
13+
]
14+
},
15+
"editable": true,
16+
"gnetId": null,
17+
"graphTooltip": 0,
18+
"id": 1,
19+
"links": [],
20+
"panels": [
21+
{
22+
"aliasColors": {},
23+
"bars": false,
24+
"dashLength": 10,
25+
"dashes": false,
26+
"datasource": "InfluxDB",
27+
"fill": 1,
28+
"gridPos": {
29+
"h": 10,
30+
"w": 24,
31+
"x": 0,
32+
"y": 0
33+
},
34+
"id": 2,
35+
"legend": {
36+
"avg": false,
37+
"current": false,
38+
"max": false,
39+
"min": false,
40+
"show": true,
41+
"total": false,
42+
"values": false
43+
},
44+
"lines": true,
45+
"linewidth": 1,
46+
"links": [],
47+
"nullPointMode": "null",
48+
"percentage": false,
49+
"pointradius": 5,
50+
"points": false,
51+
"renderer": "flot",
52+
"seriesOverrides": [],
53+
"spaceLength": 10,
54+
"stack": false,
55+
"steppedLine": false,
56+
"targets": [
57+
{
58+
"$$hashKey": "object:172",
59+
"groupBy": [
60+
{
61+
"params": [
62+
"24h"
63+
],
64+
"type": "time"
65+
},
66+
{
67+
"params": [
68+
"null"
69+
],
70+
"type": "fill"
71+
}
72+
],
73+
"measurement": "HKQuantityTypeIdentifierStepCount",
74+
"orderByTime": "ASC",
75+
"policy": "default",
76+
"refId": "A",
77+
"resultFormat": "time_series",
78+
"select": [
79+
[
80+
{
81+
"params": [
82+
"value"
83+
],
84+
"type": "field"
85+
},
86+
{
87+
"params": [],
88+
"type": "sum"
89+
}
90+
]
91+
],
92+
"tags": []
93+
}
94+
],
95+
"thresholds": [],
96+
"timeFrom": null,
97+
"timeShift": null,
98+
"title": "Steps",
99+
"tooltip": {
100+
"shared": true,
101+
"sort": 0,
102+
"value_type": "individual"
103+
},
104+
"type": "graph",
105+
"xaxis": {
106+
"buckets": null,
107+
"mode": "time",
108+
"name": null,
109+
"show": true,
110+
"values": []
111+
},
112+
"yaxes": [
113+
{
114+
"format": "short",
115+
"label": null,
116+
"logBase": 1,
117+
"max": null,
118+
"min": null,
119+
"show": true
120+
},
121+
{
122+
"format": "short",
123+
"label": null,
124+
"logBase": 1,
125+
"max": null,
126+
"min": null,
127+
"show": true
128+
}
129+
],
130+
"yaxis": {
131+
"align": false,
132+
"alignLevel": null
133+
}
134+
}
135+
],
136+
"refresh": "5s",
137+
"schemaVersion": 16,
138+
"style": "dark",
139+
"tags": [],
140+
"templating": {
141+
"list": []
142+
},
143+
"time": {
144+
"from": "now-2y",
145+
"to": "now"
146+
},
147+
"timepicker": {
148+
"refresh_intervals": [
149+
"5s",
150+
"10s",
151+
"30s",
152+
"1m",
153+
"5m",
154+
"15m",
155+
"30m",
156+
"1h",
157+
"2h",
158+
"1d"
159+
],
160+
"time_options": [
161+
"5m",
162+
"15m",
163+
"1h",
164+
"6h",
165+
"12h",
166+
"24h",
167+
"2d",
168+
"7d",
169+
"30d"
170+
]
171+
},
172+
"timezone": "",
173+
"title": "Health Data",
174+
"uid": "k0lVpINmz",
175+
"version": 1
176+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
apiVersion: 1
2+
3+
datasources:
4+
- name: InfluxDB
5+
type: influxdb
6+
access: proxy
7+
database: health
8+
user: grafana
9+
password: grafana
10+
url: http://influxdb:8086

0 commit comments

Comments
 (0)