Monitoring Diabetes with Google Cloud Platform

Monitoring blood glucose levels, generating graphs, and creating alerts using Google Cloud services.

Leonardo Lima
Google Cloud - Community
4 min readAug 23, 2021

--

I’m a type one diabetic since I was four. Monitoring my blood sugar and keeping track of my exams results has always been a problem for me, mainly for having to do it before every meal and multiple times a day. Today I’m 22 years old, taking insulin and blood glucose tests have always been part of my routine. I’ve never had diabetes-related problems, but last week I went to the ICU because of a case of ketoacidosis.

Due to this incident and all the manual effort from glucose monitoring and general diabetes care, I decided to build a dashboard for monitoring my blood sugar, with real-time values, a history of my diabetes, alerts on Telegram and Google Assistant for critical situations, and easy monitoring for me and endocrinologist.

For glucose measurement, I use FreeStyle Libre coupled with a MiaoMiao device. The FreeStyle Libre has a probe on my arm that collects glycemic values, ​​and MiaoMiao reads those values from Libre with NFC and sends it to my phone through Bluetooth. On my phone, I have the Glimp app (recommended by the MiaoMiao company) that connects with MiaoMiao and saves all measured values to Dropbox. And I can check everything in real-time on my SmartWatch, which receives data from Glimp.

Since all values ​​get stored in Dropbox, I created a system that reads this data, processes it, persists in a time-series database, and generates alerts if necessary, making it available to a data visualization tool with a login system.

The system is divided into four services, which are:

  • Glucose Measure API: gets the Dropbox file with all the glucose measures, parses its info, and exposes them through an API.
  • Glucose Gap API: gets the value of the last and penultimate measure and identifying how fast the blood sugar level is increasing or decreasing.
  • Persistent Glucose Service: saves the last measure and the gap on InfluxDB.
  • Alert Service: sends alerts on Telegram and to the Google Home in my room, then saves the last alert timestamp on Redis.

A Google Workflows defines the order in which the services will be executed. Through a cron job using Google Cloud Scheduler, they get activated every 2 minutes.

Workflows get the response from a service and, use it as a parameter for calling the next service, and is responsible for deciding if an alert must be triggered. All APIs are under API Gateway and they need a token to be accessed. Every service is running on Docker, hosted on Clod Run. I’ve opted for Golang and Python for familiarity and ease to use.

Once we have the last blood glucose value and the gap, those data are persisted on InfluxDB as a time-series format. Grafana uses InfluxDB as a data source and shows metrics like the actual glucose, a range between a timestamp, history in graphs format, etc.

After the data is stored, Workflows analyzes if the glycemic level is within a safe range, and if not, it sends messages on Telegram to me and my parents and activates a voice alert in the Google Nest that is in my room (in case I’m sleeping). I can ask my Google Assistant: "ok Google, what's my blood sugar right now?" and she will consult the Glucose API and give me the last result.

All the codebase is coverage by unit and integration tests, running on pipelines on Cloud Build. After a merge is made on the main branch, and all the tests pass, a new container version is pushed to Container Register, updating the production version of the service.

At this point, my parents, girlfriend, and medic have access to the Grafana dashboard. My medic can analyze my glucose history easily, at any time, and adjust my insulin units with more precision.

And this is how I develop a diabetes monitoring system, using Google Cloud services to host my ideas. Some of the tools I used I intended to use to test, integrate and learn from them.

--

--

Leonardo Lima
Google Cloud - Community

Computer Engineering student, Golang and Python developer, robotics and astronautics enthusiast, and open source defender