Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/andrea-cavallo/go_grpc_temperature_monitoring
Real-Time Temperature Monitoring with Go and gRPC ( Twilio Integration, MongoDB, weatherAPI, Plot diagrams, Jaeger - Grafana - Loki ) π
https://github.com/andrea-cavallo/go_grpc_temperature_monitoring
dashboard golang grafana-dashboard grpc grpc-client grpc-go grpc-server jaeger loki mongodb plot protocol-buffers temperature-monitoring twilio weather
Last synced: 4 months ago
JSON representation
Real-Time Temperature Monitoring with Go and gRPC ( Twilio Integration, MongoDB, weatherAPI, Plot diagrams, Jaeger - Grafana - Loki ) π
- Host: GitHub
- URL: https://github.com/andrea-cavallo/go_grpc_temperature_monitoring
- Owner: Andrea-Cavallo
- License: apache-2.0
- Created: 2024-08-16T14:57:11.000Z (6 months ago)
- Default Branch: master
- Last Pushed: 2024-08-19T08:38:59.000Z (6 months ago)
- Last Synced: 2024-09-29T15:41:10.149Z (4 months ago)
- Topics: dashboard, golang, grafana-dashboard, grpc, grpc-client, grpc-go, grpc-server, jaeger, loki, mongodb, plot, protocol-buffers, temperature-monitoring, twilio, weather
- Language: Go
- Homepage: https://medium.com/@andreacavallo
- Size: 633 KB
- Stars: 6
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: changelog.md
- License: LICENSE
Awesome Lists containing this project
README
# Real-Time Temperature Monitoring with Go and gRPC
## Introduzione
Questo progetto dimostra l'integrazione di servizi gRPC con il linguaggio Go,
fornendo un esempio completo di un server gRPC che serve dati di temperatura e un client gRPC che li consuma,
il tutto con una gestione avanzata delle metriche, connessione a MongoDB per persistere i dati, funzionalitΓ di allerta tramite Twilio.
Il progetto utilizza Docker per facilitare l'impostazione dell'ambiente, inclusi la configurazione di MongoDB e altre dipendenze tipo jaeger.[Click here for the English version](#english-version)
# Struttura del progetto
```text
βββ api --> qua dentro il file .proto
β βββ protos
β β βββ temperature.proto
β βββ api.md
βββ docker ---> tutto cio' relativo a docker
β βββ docker-compose.yml
β βββ init-mongo.js
β βββ loki-config.yml
β βββ otel-collector-config.yaml
β βββ prometheus.yml
βββ extra --> immagini del progetto
βββ pkg --> pkg tutto quello che deve essere visibile e condiviso
β βββ telemetry
β βββ temperature
βββ temperature_grpc_client -> il Client GRPC
β βββ cmd
β βββ plot
β βββ service
β βββ client.md
βββ temperature_grpc_server --> il Server GRPC
β βββ alert_twilio
β β βββ alert.go
β βββ cmd
β β βββ server
β β β βββ main.go
β βββ mongodb --> connessione a MONGODB
β β βββ config
β β βββ temperature_repo
β βββ service
β β βββ server.go
β βββ server.md
βββ .editorconfig
βββ .gitignore
βββ changelog.md
βββ go.mod
βββ go.sum
```# Diagramma UML
# Esecuzione del Progetto
## 1. Prerequisiti
Prima di eseguire il progetto, Γ¨ necessario ottenere una chiave API per utilizzare il servizio WeatherAPI. Questo servizio Γ¨ completamente gratuito e puoi ottenere la tua chiave API seguendo questi passi:
1. Visita il sito [WeatherAPI](https://www.weatherapi.com/).
2. Registrati e segui le istruzioni per ottenere la tua chiave API.
3. Una volta ottenuta, salva la chiave API in un luogo sicuro.## 2. Configurare l'API Key come Variabile d'Ambiente
Per mantenere la tua chiave API sicura e fuori dal codice sorgente, configurala come una variabile d'ambiente. Segui questi passi:
### Su Linux/MacOS:
```bash
export WEATHER_API_KEY=la-tua-api-key
```### Su Windows (nel terminale PowerShell):
```powershell
$env:WEATHER_API_KEY="la-tua-api-key"
```Assicurati che la variabile d'ambiente `WEATHER_API_KEY` sia impostata correttamente prima di procedere.
## 3. Build del Docker Compose
Assicurati di avere Docker installato e di avere accesso al file `docker-compose.yml`:
- Posizionati nella directory che contiene `docker-compose.yml`
## 4. Opzionale - Configurazione di Twilio
Se desideri inviare avvisi tramite Twilio, segui i seguenti passi per creare un account su Twilio e configurare le variabili d'ambiente:
Consulta: [Twilio WhatsApp Quickstart (Go)](https://www.twilio.com/docs/whatsapp/quickstart/go)
Configurare le seguenti variabili d'ambiente:
```bash
export TWILIO_ACCOUNT_SID=il-tuo-account-sid
export TWILIO_AUTH_TOKEN=il-tuo-auth-token
export TWILIO_PHONE_NUMBER=il-tuo-numero-di-telefono
export ALERT_PHONE_NUMBER=il-numero-di-telefono-per-gli-avvisi
```## 5. Eseguire il Server
Una volta configurata la chiave API, puoi avviare il server:
1. Naviga alla directory `temperature_grpc_server`:
```bash
cd temperature_grpc_server/cmd/server
```2. Esegui il server:
```bash
go run main.go
```Il server inizierΓ ad ascoltare le richieste gRPC.
## 6. Eseguire il Client
Con il server in esecuzione, ora puoi avviare il client per inviare richieste al server:
1. Apri un nuovo terminale e naviga alla directory `temperature_grpc_client`:
```bash
cd temperature_grpc_client/cmd/client
```2. Esegui il client:
```bash
go run main.go
```Il client invierΓ una richiesta gRPC al server e riceverΓ una risposta con i dati di temperatura.
## Grafico della Temperatura
Ogni volta che arresti l'applicazione, in particolare il client, vedrai disegnato un grafico che mostrerΓ la variazione della temperatura.
![Grafico della Temperatura](extra/img/temp_graph.png)
## Per il dettaglio del client e del server
- temperature_grpc_client/client.md
- temperature_grpc_server/server.md## Approfondimenti sulla tecnologia scelta
gRPC puΓ² essere considerato un successore di RPC, ed Γ¨ leggero in termini di peso. Google lo ha sviluppato per la comunicazione tra microservizi e altri sistemi che necessitano di interagire. Ci sono diversi vantaggi nell'usare gRPC.
## Vantaggi di gRPC
- **Utilizza Protocol Buffers (Protobuf)** invece del JSON.
- **Costruito su HTTP/2** invece che su HTTP 1.1.
- **Generazione di codice incorporata**.
- **Alte prestazioni**.
- **Sicurezza SSL**.Oltre ai vantaggi chiave menzionati sopra, gRPC promuove un design migliore per la tua applicazione. gRPC Γ¨ orientato all'API, a differenza di REST che Γ¨ orientato alle risorse. Γ anche asincrono per impostazione predefinita, il che significa che non blocca il thread su richiesta e puΓ² servire milioni di richieste in parallelo, garantendo un'alta scalabilitΓ .
## Vantaggi di gRPC rispetto a REST
gRPC Γ¨ circa sette volte piΓΉ veloce di REST nel ricevere dati e circa dieci volte piΓΉ veloce di REST nel trasmettere dati per un payload specifico. Questo Γ¨ principalmente dovuto al pacchettamento compatto dei Protocol Buffers e all'uso di HTTP/2 da parte di gRPC.
## Autore
AndreaCavallo
-------------------------------------------------------------------------------------------------------------------
# English Version
# Super cool Go with GRPC
# Project Execution
## 1. Prerequisites
Before running the project, you need to obtain an API key to use the WeatherAPI service. This service is completely free, and you can get your API key by following these steps:
1. Visit the [WeatherAPI](https://www.weatherapi.com/) website.
2. Sign up and follow the instructions to get your API key.
3. Once obtained, save the API key in a safe place.## 2. Configure the API Key as an Environment Variable
To keep your API key secure and out of the source code, configure it as an environment variable. Follow these steps:
### On Linux/MacOS:
```bash
export WEATHER_API_KEY=your-api-key
```### On Windows (in PowerShell):
```powershell
$env:WEATHER_API_KEY="your-api-key"
```Ensure the `WEATHER_API_KEY` environment variable is set correctly before proceeding.
## 3. Docker Compose Build
Ensure you have Docker installed and access to the `docker-compose.yml` file:
- Navigate to the directory that contains `docker-compose.yml`.
## 4. Optional - Twilio Configuration
If you wish to send alerts via Twilio, follow these steps to create a Twilio account and set up the environment variables:
Consult: [Twilio WhatsApp Quickstart (Go)](https://www.twilio.com/docs/whatsapp/quickstart/go)
Set the following environment variables:
```bash
export TWILIO_ACCOUNT_SID=your-account-sid
export TWILIO_AUTH_TOKEN=your-auth-token
export TWILIO_PHONE_NUMBER=your-phone-number
export ALERT_PHONE_NUMBER=alert-phone-number
```## 5. Running the Server
Once the API key is configured, you can start the server:
1. Navigate to the `temperature_grpc_server` directory:
```bash
cd temperature_grpc_server/cmd/server
```2. Start the server:
```bash
go run main.go
```The server will start listening for gRPC requests.
## 6. Running the Client
With the server running, you can now start the client to send requests to the server:
1. Open a new terminal and navigate to the `temperature_grpc_client` directory:
```bash
cd temperature_grpc_client/cmd/client
```2. Start the client:
```bash
go run main.go
```The client will send a gRPC request to the server and receive a response with the temperature data.
## Temperature Graph
Whenever you shut down the application, especially the client, you will see a graph showing the temperature variation.
![Temperature Graph](extra/img/temp_graph.png)
## Detailed Client and Server Documentation
- temperature_grpc_client/client.md
- temperature_grpc_server/server.md## Insights into the Chosen Technology
gRPC can be considered a successor to RPC and is lightweight. Google developed it for communication between microservices and other systems that need to interact. There are several advantages to using gRPC.
## Advantages of gRPC
- **Uses Protocol Buffers (Protobuf)** instead of JSON.
- **Built on HTTP/2** instead of HTTP 1.1.
- **Built-in Code Generation**.
- **High Performance**.
- **SSL Security**.In addition to the key advantages mentioned above, gRPC promotes better design for your application. gRPC is API-oriented, unlike REST, which is resource-oriented. It is also asynchronous by default, meaning it does not block the thread on request and can serve millions of requests in parallel, ensuring high scalability.
## Advantages of gRPC over REST
gRPC is about seven times faster than REST in receiving data and about ten times faster than REST in transmitting data for a specific payload. This is primarily due to the compact packing of Protocol Buffers and the use of HTTP/2 by gRPC.
## Author
Andrea Cavallo