garmin grafana部署教程

-
-
2025-11-24

garmin-grafana:一键获取 Garmin 数据并进行可视化展示

Garmin Grafana 是一个开源项目,通过 Docker 容器从 Garmin 服务器获取数据,并将其存储在本地的 influxdb 数据库中,进而利用 Grafana 进行吸引人的数据可视化。

如果你是 Fitbit 用户,可以查看专为 Fitbit 设计的 sister project

项目介绍

Garmin Grafana 的核心功能是自动从 Garmin 服务器获取数据,并将其存储在本地数据库中,以便用户能够通过 Grafana 进行详细的数据分析和可视化展示。该项目不仅提供了实时的健康数据监控,还支持历史数据的回填,使得用户可以全面了解自己的健康状态。

项目技术分析

该项目使用了 Docker 容器技术,通过自动化脚本从 Garmin 服务器定期获取健康数据。具体技术构成如下:

  • 数据获取:使用 Python 脚本 python-garminconnect 从 Garmin Connect 获取数据。
  • 数据存储:采用 influxdb 作为时间序列数据库存储数据,便于后续分析和查询。
  • 数据展示:利用 Grafana 进行数据可视化,通过 Dashboard 展示各种健康指标。

项目及应用场景

Garmin Grafana 的主要应用场景包括:

  1. 个人健康管理:用户可以通过该项目实时监控自己的心率、步数、睡眠质量等健康指标,从而更好地管理自己的健康状况。
  2. 运动数据分析:运动爱好者可以使用该项目记录和分析运动数据,如 GPS 轨迹、配速、海拔高度等,以优化运动计划。
  3. 科学研究:科研人员可以收集大量的健康数据,用于研究健康趋势、疾病预防等领域。

项目特点

Garmin Grafana 项目具有以下特点:

  • 自动化数据收集:项目可以自动从 Garmin 服务器获取数据,用户无需手动干预。
  • 全面的数据指标:支持收集多种健康指标,包括心率、步数、睡眠数据、压力水平等。
  • 定期更新:支持自动化定期更新数据,用户可以设置更新间隔。
  • 历史数据回填:项目支持历史数据的回填,用户可以查看过去的数据。
  • 易于部署:使用 Docker 容器,使得部署过程简单便捷。

以下为详细的推荐文章内容:


Garmin Grafana:让 Garmin 数据可视化更简单

在数字化健康管理的今天,如何有效地收集和分析个人健康数据变得越来越重要。Garmin Grafana 项目正是为了满足这一需求而诞生,它通过自动化的方式从 Garmin 服务器获取数据,并在本地 influxdb 数据库中存储,最终通过 Grafana 进行可视化展示。本文将详细介绍这一项目的核心功能、技术构成、应用场景以及特点。

Garmin Grafana:项目的核心功能

Garmin Grafana 的核心功能是自动化数据收集和可视化。用户可以通过该项目实时监控自己的心率、步数、睡眠质量等健康指标,并通过 Grafana 的 Dashboard 进行直观的展示。

项目介绍

Garmin Grafana 是一个开源项目,它通过 Docker 容器从 Garmin 服务器获取数据,并将其存储在本地的 influxdb 数据库中。用户可以通过 Grafana 进行详细的数据分析和可视化展示,从而更好地管理自己的健康状况。

项目技术分析

Garmin Grafana 项目采用了多种技术实现其功能:

  1. 数据获取:使用 Python 脚本 python-garminconnect 从 Garmin Connect 获取数据。该脚本通过模拟登录,自动获取用户的健康数据。
  2. 数据存储:项目采用 influxdb 作为时间序列数据库存储数据。influxdb 优异的性能使其非常适合处理大量的时间序列数据。
  3. 数据展示:利用 Grafana 进行数据可视化。Grafana 提供了丰富的 Dashboard 模板,用户可以根据自己的需求进行定制。

项目应用场景

Garmin Grafana 可以应用于多种场景:

  1. 个人健康管理:用户可以通过该项目实时监控自己的心率、步数、睡眠质量等健康指标,从而更好地管理自己的健康状况。
  2. 运动数据分析:运动爱好者可以使用该项目记录和分析运动数据,如 GPS 轨迹、配速、海拔高度等,以优化运动计划。
  3. 科学研究:科研人员可以收集大量的健康数据,用于研究健康趋势、疾病预防等领域。

项目特点

Garmin Grafana 项目具有以下显著特点:

  • 自动化数据收集:项目可以自动从 Garmin 服务器获取数据,用户无需手动干预,节省了大量的时间和精力。
  • 全面的数据指标:Garmin Grafana 支持收集多种健康指标,包括心率、步数、睡眠数据、压力水平、身体电量等,为用户提供了全面的数据支持。
  • 定期更新:项目支持自动化定期更新数据。用户可以设置更新间隔,确保数据的实时性。
  • 历史数据回填:Garmin Grafana 支持历史数据的回填,用户可以查看过去的数据,更好地了解自己的健康状况变化。
  • 易于部署:项目使用 Docker 容器进行部署,使得安装和配置过程变得简单快捷。

部署方法

使用docker-compose部署:

# There is support for influxdb v3 (core) OSS, but it's highly recommended to use Influxdb 1.x versions with this project. 

services:
  garmin-fetch-data:
    restart: unless-stopped
    image: thisisarpanghosh/garmin-fetch-data:latest
    container_name: garmin-fetch-data
    # user: root # Runs the container as root user, uncomment this line if you are getting permission issues which can't be resolved otherwise. For this, you also need to change the below volume mount from './garminconnect-tokens:/home/appuser/.garminconnect' to './garminconnect-tokens:/root/.garminconnect' to ensure the token files persist during container rebuilding. 
    depends_on:
      - influxdb
    volumes:
      - /share/Container/garmin-grafana/garminconnect-tokens:/home/appuser/.garminconnect # (persistent tokens storage - garminconnect-tokens folder must be owned by 1000:1000) - should be './garminconnect-tokens:/root/.garminconnect' instead if you are using using user: root
    environment:
      - INFLUXDB_HOST=influxdb
      - INFLUXDB_PORT=8086 # Influxdb V3 maps to 8181 instead of 8086 of V1
      - INFLUXDB_USERNAME=influxdb_user # user should have read/write access to INFLUXDB_DATABASE (Required for influxdb 1.x, ignore for influxdb 3.x - set the 3.x specific variables)
      - INFLUXDB_PASSWORD=influxdb_secret_password # (Required for influxdb 1.x, ignore for influxdb 3.x - set the 3.x specific variables)
      - INFLUXDB_DATABASE=GarminStats
      - GARMINCONNECT_IS_CN=True # Set this to True if you are in mainland China or use Garmin-cn (Default False)
      #####################################################################################
      - GARMINCONNECT_EMAIL=XXXXXXX # optional, read the setup docs. (remove or comment out this line altogether if not used)
      - GARMINCONNECT_BASE64_PASSWORD=XXXXXXXX # optional, must be Base64 encoded, read setup docs. (remove or comment out this line altogether if not used)
      #####################################################################################
      # The following ENV variables are required only if you are using influxdb V3 (You won't have to set the above )
      #####################################################################################
      # - INFLUXDB_VERSION=1 # Required for influxdb V3, Default is 1, must be overridden with 3 if using Influxdb V3
      # - INFLUXDB_V3_ACCESS_TOKEN=your_influxdb_admin_access_token # Required for influxdb V3 (ignored for V1), Set this to your admin access token (or a token that has database R/W access) - You can generate this by following step 3 notes in the README installation
      #####################################################################################
      # The following ENV variables will override some default settings. 
      # Please read the README guide before using them as they may change how the script behaves
      #####################################################################################
      # - LOG_LEVEL=INFO # change to DEBUG to get DEBUG logs
      # - UPDATE_INTERVAL_SECONDS=300 # Default update check interval is set to 5 minutes
      # - FETCH_SELECTION=daily_avg,sleep,steps,heartrate,stress,breathing,hrv,vo2,activity,race_prediction,body_composition # This enables selection of fetch data : Check Discussion #119 to know what additional options are available (add them seperated by , but without a space)
      # - KEEP_FIT_FILES=False # Stores the FIT files (downloads and saves them) when set to True - read docs for more details
      # - ALWAYS_PROCESS_FIT_FILES=False # Enables processing FIT files even if GPS data is not present in it when set to True, default False
      # - USER_TIMEZONE= # Can hardcode user's timezone - must be a valid TZ identifier like Europe/Budapest without quotes, fetches timezone automatically and dynamically on each run if set to empty (default) - Read docs
      # - INFLUXDB_ENDPOINT_IS_HTTP=True # Set this to False if you are using HTTPS for your influxdb connection (over the internet)
      # - FORCE_REPROCESS_ACTIVITIES=True # Enables re-processing of FIT files on iterative updates when set to True (default), setting to False may save processing time but known for skipping activities

  influxdb:
    restart: unless-stopped
    container_name: influxdb
    hostname: influxdb
    environment:
      - INFLUXDB_DB=GarminStats
      - INFLUXDB_USER=influxdb_user
      - INFLUXDB_USER_PASSWORD=influxdb_secret_password
      - INFLUXDB_DATA_INDEX_VERSION=tsi1
      #############################################################
      # The following ENV variables are applicable for InfluxDB V3
      #############################################################
      # - INFLUXDB3_MAX_HTTP_REQUEST_SIZE=10485760
      # - INFLUXDB3_NODE_IDENTIFIER_PREFIX=Influxdb-node1
      # - INFLUXDB3_BUCKET=GarminStats
      # - INFLUXDB3_OBJECT_STORE=file
      # - INFLUXDB3_DB_DIR=/data
      # - INFLUXDB3_QUERY_FILE_LIMIT=5000 # this set to be a very high value if you want to view long term data
    expose:
      - '8086' # Influxdb V3 should expose "8181" (Change INFLUXDB_PORT on garmin-fetch-data appropriately for InfluxDB V3)
    volumes:
      - /share/Container/garmin-grafana/influxdb:/var/lib/influxdb # InfluxDB V3 bind mount should be set like - influxdb_data:/data if you set INFLUXDB3_DB_DIR=/data (instead of /var/lib/influxdb)
    image: 'influxdb:1.11' # You must change this to 'quay.io/influxdb/influxdb3-core:latest' for influxdb V3

  grafana:
    restart: unless-stopped
    container_name: grafana
    hostname: grafana
    environment:
      - GF_SECURITY_ADMIN_USER=admin
      - GF_SECURITY_ADMIN_PASSWORD=admin
      - GF_PLUGINS_PREINSTALL=marcusolsson-hourly-heatmap-panel
      - GF_DATE_FORMATS_FULL_DATE=MMM Do, YYYY - hh:mm:ss a
      - GF_DATE_FORMATS_INTERVAL_SECOND=hh:mm:ss a
      - GF_DATE_FORMATS_INTERVAL_MINUTE=hh:mm a
      - GF_DATE_FORMATS_INTERVAL_HOUR=MMM DD hh:mm a
      - GF_DATE_FORMATS_INTERVAL_DAY=MMM DD
      - GF_DATE_FORMATS_INTERVAL_MONTH=YYYY-MM
      - GF_DATE_FORMATS_INTERVAL_YEAR=YYYY
    volumes:
      - grafana_data:/var/lib/grafana
      - /share/Container/garmin-grafana/Grafana_Datasource:/etc/grafana/provisioning/datasources # (optional) Self provisioning influxdb datasource
      - /share/Container/garmin-grafana/Grafana_Dashboard:/etc/grafana/provisioning/dashboards # (optional) self provisioning grafana dashboard
    ports:
      - '3000:3000'
    image: 'grafana/grafana:latest'

volumes:
  influxdb_data:
  grafana_data:

部署过程中踩坑以及涉及到的部分优化措施

  1. garmin账户不要开双重验证,docker-compose文件中以ENV的方式写明登录账号以及密码(base64)——测试过程中使用双重验证并不会弹出登录窗,另外,base64格式的密码注意不要有换行符;
  2. 需要将github主业的所有内容git到本地——内包含面板的json文件等,相关的容器地址也需要映射到本地;
  3. influxdb的存储位置要隐射到本地
  4. 需要将json文件中的所有${DS_GARMIN_STATS} 替换为garmin_influxdb,否则面板数据报错,具体如下:

    If you are using self provisioning provided with this project for Grafana setup, then you should run sed -i 's/${DS_GARMIN_STATS}/garmin_influxdb/g' Grafana_Dashboard/Garmin-Grafana-Dashboard.json (assuming you are currently in the root garmin-grafana directory) to update the placeholder variable name ${DS_GARMIN_STATS} (for supporting external import) in the dashboard JSON to static garmin_influxdb as it is the uid set during the self provisioning of the dashboard.

  5. 取得历史数据需要在garmin-fetch-data中增加以下环境变量:MANUAL_START_DATE=YYYY-MM-DD以及MANUAL_END_DATE=YYYY-MM-DD,运行成功后删除此两项环境变量
  6. garmin-fetch-data的docker中需要写入TZ=Asia/Shanghai的ENV,避免出现日志或者统计数据因为市区问题错误的情况

“您的支持是我持续分享的动力”

微信收款码
微信
支付宝收款码
支付宝

目录