Skip to content

Commit

Permalink
Merge pull request #3 from twstokes/develop
Browse files Browse the repository at this point in the history
Docker goodies
  • Loading branch information
twstokes authored Jun 16, 2018
2 parents 159ae42 + e033584 commit 8a317e7
Show file tree
Hide file tree
Showing 12 changed files with 308 additions and 9 deletions.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
data
docker-compose
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,5 @@ ENV/
data/
.DS_Store
config.yml

.vscode
10 changes: 10 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM python:3

WORKDIR /app

COPY requirements.txt /app
RUN pip install --no-cache-dir -r requirements.txt

COPY healthdata_influx /app

CMD [ "python3", "import.py", "/data/export.xml" ]
76 changes: 68 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,84 @@ Imports Apple Health Data into InfluxDB.
![Grafana Screenshot](https://www.tannr.com/wp-content/uploads/2017/03/grafana.png "Grafana Screenshot")
Visualizing InfluxDB using [Grafana](https://grafana.com/).

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

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

### Installation:
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.

#### Requirements:

* [Docker](https://www.docker.com/) with [Docker Compose](https://docs.docker.com/compose/)

#### Installation:

* Create a `data` directory at the project root and add the `export.xml` inside it

#### Building:

`docker-compose build`

#### Running:

`docker-compose up` (add `-d` to run in daemon mode)

#### Refreshing data:

1. Replace `data/export.yml` with a new version
2. `docker-compose run importer`

## Running as a Python module or stand-alone script.

#### Requirements:

* [Python 3](https://www.python.org/)
* An accessible [InfluxDB](https://www.influxdata.com/) instance

#### Installation:

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

### Configuration:
#### Configuration:

* Edit `config.yml`
* Edit `config.yml` to match your InfluxDB settings (host, auth, etc.)

### Usage:
#### Usage:

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

### Notes:

#### See also:
`python import.py --help`

## Running as a stand-alone Docker container

#### Requirements:

* [Docker](https://www.docker.com/)

#### Installation:

* Create a `data` directory at the repo root and add the `export.xml` inside it.
* (note that this can be anywhere if the volume mount point on the `docker run` command is changed)

#### Configuration:

* Edit `config.yml` to match your InfluxDB settings (host, auth, etc.)

#### Building:

`docker build . -t twstokes/healthdata_influx`

#### Running (at the repo root):

`docker run -v $PWD/data:/data:ro -v $PWD/config.yml:/app/config.yml:ro twstokes/healthdata_influx`

## Todo / Notes:
* Does not support "Mindful Sessions"
28 changes: 28 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
version: '3'

services:
importer:
build: .
links:
- influxdb
volumes:
- ./data:/data:ro
- ./docker-compose/config.yml:/app/config.yml:ro

influxdb:
image: influxdb
env_file:
- './docker-compose/env.influxdb'

grafana:
image: grafana/grafana:latest
volumes:
- ./docker-compose/grafana_datasources:/etc/grafana/provisioning/datasources
- ./docker-compose/grafana_dashboard_providers:/etc/grafana/provisioning/dashboards
- ./docker-compose/grafana_dashboards:/var/lib/grafana/dashboards
ports:
- "3000:3000"
env_file:
- './docker-compose/env.grafana'
links:
- influxdb
Empty file added docker-compose/env.grafana
Empty file.
Empty file added docker-compose/env.influxdb
Empty file.
11 changes: 11 additions & 0 deletions docker-compose/grafana_dashboard_providers/default.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: 1

providers:
- name: 'default'
orgId: 1
folder: ''
type: file
disableDeletion: false
updateIntervalSeconds: 3 #how often Grafana will scan for changed dashboards
options:
path: /var/lib/grafana/dashboards
176 changes: 176 additions & 0 deletions docker-compose/grafana_dashboards/default.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
{
"annotations": {
"list": [
{
"builtIn": 1,
"datasource": "-- Grafana --",
"enable": true,
"hide": true,
"iconColor": "rgba(0, 211, 255, 1)",
"name": "Annotations & Alerts",
"type": "dashboard"
}
]
},
"editable": true,
"gnetId": null,
"graphTooltip": 0,
"id": 1,
"links": [],
"panels": [
{
"aliasColors": {},
"bars": false,
"dashLength": 10,
"dashes": false,
"datasource": "InfluxDB",
"fill": 1,
"gridPos": {
"h": 10,
"w": 24,
"x": 0,
"y": 0
},
"id": 2,
"legend": {
"avg": false,
"current": false,
"max": false,
"min": false,
"show": true,
"total": false,
"values": false
},
"lines": true,
"linewidth": 1,
"links": [],
"nullPointMode": "null",
"percentage": false,
"pointradius": 5,
"points": false,
"renderer": "flot",
"seriesOverrides": [],
"spaceLength": 10,
"stack": false,
"steppedLine": false,
"targets": [
{
"$$hashKey": "object:172",
"groupBy": [
{
"params": [
"24h"
],
"type": "time"
},
{
"params": [
"null"
],
"type": "fill"
}
],
"measurement": "HKQuantityTypeIdentifierStepCount",
"orderByTime": "ASC",
"policy": "default",
"refId": "A",
"resultFormat": "time_series",
"select": [
[
{
"params": [
"value"
],
"type": "field"
},
{
"params": [],
"type": "sum"
}
]
],
"tags": []
}
],
"thresholds": [],
"timeFrom": null,
"timeShift": null,
"title": "Steps",
"tooltip": {
"shared": true,
"sort": 0,
"value_type": "individual"
},
"type": "graph",
"xaxis": {
"buckets": null,
"mode": "time",
"name": null,
"show": true,
"values": []
},
"yaxes": [
{
"format": "short",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": true
},
{
"format": "short",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": true
}
],
"yaxis": {
"align": false,
"alignLevel": null
}
}
],
"refresh": "5s",
"schemaVersion": 16,
"style": "dark",
"tags": [],
"templating": {
"list": []
},
"time": {
"from": "now-2y",
"to": "now"
},
"timepicker": {
"refresh_intervals": [
"5s",
"10s",
"30s",
"1m",
"5m",
"15m",
"30m",
"1h",
"2h",
"1d"
],
"time_options": [
"5m",
"15m",
"1h",
"6h",
"12h",
"24h",
"2d",
"7d",
"30d"
]
},
"timezone": "",
"title": "Health Data",
"uid": "k0lVpINmz",
"version": 1
}
10 changes: 10 additions & 0 deletions docker-compose/grafana_datasources/grafana_influx.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: 1

datasources:
- name: InfluxDB
type: influxdb
access: proxy
database: health
user: grafana
password: grafana
url: http://influxdb:8086
File renamed without changes.
2 changes: 1 addition & 1 deletion import.py → healthdata_influx/import.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def parse_and_upload(config_path, export_path, dry_run=False):


if __name__ == '__main__':
PARSER = argparse.ArgumentParser(description='Uploads Apple Health Data to InfluxDB')
PARSER = argparse.ArgumentParser(description='Imports Apple Health Data to InfluxDB')

PARSER.add_argument('--config_path', help='InfluxDB config file path', default='./config.yml')
PARSER.add_argument('--dry', help='Dry run - no DB changes', action='store_true', default=False)
Expand Down

0 comments on commit 8a317e7

Please sign in to comment.