Skip to content

Commit

Permalink
update front and ana haut level
Browse files Browse the repository at this point in the history
  • Loading branch information
YvannPONCE committed Nov 1, 2024
1 parent 12f04e9 commit c315154
Show file tree
Hide file tree
Showing 15 changed files with 111 additions and 17 deletions.
2 changes: 1 addition & 1 deletion charts/poulet/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.1.40
version: 0.1.41

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ image:
repository: ghcr.io/startupnationlabs/poulet/analyse-haut-niveau-management
pullPolicy: IfNotPresent
# Overrides the image tag whose default is the chart appVersion.
tag: "f42dcea109984b2e7a133a37762dc07f24f16eca"
tag: "12f04e9fe10440f6e3d2a26b017d4fc11839447d"

imagePullSecrets: []
nameOverride: ""
Expand Down
4 changes: 3 additions & 1 deletion charts/poulet/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -213,11 +213,13 @@ patient-management:
tls: [ ]
analyse-haut-niveau-management:
enabled: true
image:
tag: "12f04e9fe10440f6e3d2a26b017d4fc11839447d"

frontend:
enabled: true
image:
tag: c59d6a8feb6346b8e10182d6891775dd9b8f8d11
tag: 12f04e9fe10440f6e3d2a26b017d4fc11839447d
environment:
ALERT_MANAGEMENT_BASE_URL: "http://doctor.al.apoorva64.com"
PATIENT_MANAGEMENT_BASE_URL: "http://doctor.al.apoorva64.com"
Expand Down
11 changes: 10 additions & 1 deletion gateway/adapter/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,13 @@ go 1.22.2

require github.com/streadway/amqp v1.0.0 // or the latest version

require github.com/rabbitmq/amqp091-go v1.10.0 // indirect
require (
github.com/newrelic/go-agent/v3 v3.35.1 // indirect
github.com/rabbitmq/amqp091-go v1.10.0 // indirect
golang.org/x/net v0.25.0 // indirect
golang.org/x/sys v0.20.0 // indirect
golang.org/x/text v0.15.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240528184218-531527333157 // indirect
google.golang.org/grpc v1.65.0 // indirect
google.golang.org/protobuf v1.34.2 // indirect
)
14 changes: 14 additions & 0 deletions gateway/adapter/go.sum
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
github.com/newrelic/go-agent/v3 v3.35.1 h1:N43qBNDILmnwLDCSfnE1yy6adyoVEU95nAOtdUgG4vA=
github.com/newrelic/go-agent/v3 v3.35.1/go.mod h1:GNTda53CohAhkgsc7/gqSsJhDZjj8vaky5u+vKz7wqM=
github.com/rabbitmq/amqp091-go v1.10.0 h1:STpn5XsHlHGcecLmMFCtg7mqq0RnD+zFr4uzukfVhBw=
github.com/rabbitmq/amqp091-go v1.10.0/go.mod h1:Hy4jKW5kQART1u+JkDTF9YYOQUHXqMuhrgxOEeS7G4o=
github.com/streadway/amqp v1.0.0 h1:kuuDrUJFZL1QYL9hUNuCxNObNzB0bV/ZG5jV3RWAQgo=
github.com/streadway/amqp v1.0.0/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw=
golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac=
golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=
golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y=
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk=
golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240528184218-531527333157 h1:Zy9XzmMEflZ/MAaA7vNcoebnRAld7FsPW1EeBB7V0m8=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240528184218-531527333157/go.mod h1:EfXuqaE1J41VCDicxHzUDm+8rk+7ZdXzHV0IhO/I6s0=
google.golang.org/grpc v1.65.0 h1:bs/cUb4lp1G5iImFFd3u5ixQzweKizoZJAwBNLR42lc=
google.golang.org/grpc v1.65.0/go.mod h1:WgYC2ypjlB0EiQi6wdKixMqukr6lBc0Vo+oOgjrM5ZQ=
google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg=
google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw=
20 changes: 19 additions & 1 deletion gateway/adapter/main.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,30 @@
// main.go
package main

import(
"github.com/newrelic/go-agent/v3/newrelic"
"log"
"time"
)

func main() {

app, err := newrelic.NewApplication(
newrelic.ConfigAppName("DataManager"),
newrelic.ConfigLicense("eu01xx66792eeb67035b3ccc1fb4ee54FFFFNRAL"),
newrelic.ConfigAppLogForwardingEnabled(true),
)
if err != nil {
log.Println("Error:","Newrelic: %w", err)
return
}


rabbitMQClient := &RabbitMQClient{}
rabbitMQClient.init()
StartServer(rabbitMQClient)
StartServer(rabbitMQClient, app)

rabbitMQClient.close()
app.Shutdown(10 * time.Second)
}

6 changes: 4 additions & 2 deletions gateway/adapter/webServer.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"log"
"net/http"
"os"
"github.com/newrelic/go-agent/v3/newrelic"
)

type RequestData struct {
Expand Down Expand Up @@ -47,7 +48,7 @@ func handleData(metric string, client *RabbitMQClient) http.HandlerFunc {
}

// StartServer starts the HTTP server
func StartServer(client *RabbitMQClient) {
func StartServer(client *RabbitMQClient, app *newrelic.Application) {
metrics := []string{
"acceleration",
"heartrate",
Expand All @@ -56,7 +57,8 @@ func StartServer(client *RabbitMQClient) {
}

for _, value := range metrics {
http.HandleFunc("/api/data/"+value, handleData(value, client))
http.HandleFunc(newrelic.WrapHandleFunc(app, "/api/data/"+value, handleData(value, client)))

}
serverPort := "8081"
if os.Getenv("SERVER_PORT") != "" {
Expand Down
6 changes: 3 additions & 3 deletions gateway/dataManager/alerter.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,16 @@ func (alerter *Alerter) CheckHealthParameter(param string, sample Sample) bool {

switch param {
case "temperature":
isAbnormal = sample.Value < 36.0 || sample.Value > 37.5
isAbnormal = sample.Value < 36.0 || sample.Value > 38
message = fmt.Sprintf("Alert! Abnormal %s: %.2f°C", param, sample.Value)
case "acceleration":
isAbnormal = sample.Value > 100
message = fmt.Sprintf("Alert! Abnormal %s: %.2f m/s²", param, sample.Value)
case "glucose":
isAbnormal = sample.Value < 70 || sample.Value > 140
isAbnormal = sample.Value < 50 || sample.Value > 140
message = fmt.Sprintf("Alert! Abnormal %s: %.2f mg/dL", param, sample.Value)
case "heartrate":
isAbnormal = sample.Value < 60 || sample.Value > 100
isAbnormal = sample.Value < 50 || sample.Value > 120
message = fmt.Sprintf("Alert! Abnormal %s: %.2f BPM", param, sample.Value)
default:
fmt.Println("Unknown parameter:", param)
Expand Down
5 changes: 5 additions & 0 deletions gateway/dataManager/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,13 @@ require (
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/grafana/regexp v0.0.0-20240518133315-a468a5bfb3bc // indirect
github.com/joho/godotenv v1.5.1 // indirect
github.com/newrelic/go-agent/v3 v3.35.1 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.55.0 // indirect
golang.org/x/net v0.27.0 // indirect
golang.org/x/sys v0.22.0 // indirect
golang.org/x/text v0.16.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240708141625-4ad9e859172b // indirect
google.golang.org/grpc v1.65.0 // indirect
google.golang.org/protobuf v1.34.2 // indirect
)
10 changes: 10 additions & 0 deletions gateway/dataManager/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/newrelic/go-agent/v3 v3.35.1 h1:N43qBNDILmnwLDCSfnE1yy6adyoVEU95nAOtdUgG4vA=
github.com/newrelic/go-agent/v3 v3.35.1/go.mod h1:GNTda53CohAhkgsc7/gqSsJhDZjj8vaky5u+vKz7wqM=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p8ais2e9E=
Expand All @@ -39,12 +41,16 @@ golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.27.0 h1:5K3Njcw06/l2y9vpGCSdcxWOYHOUk3dVNGDXN+FvAys=
golang.org/x/net v0.27.0/go.mod h1:dDi0PyhWNoiUOrAS8uXv/vnScO4wnHQO4mj9fn/RytE=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI=
golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4=
Expand All @@ -57,6 +63,10 @@ golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8T
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240708141625-4ad9e859172b h1:04+jVzTs2XBnOZcPsLnmrTGqltqJbZQ1Ey26hjYdQQ0=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240708141625-4ad9e859172b/go.mod h1:Ue6ibwXGpU+dqIcODieyLOcgj7z8+IcskoNIgZxtrFY=
google.golang.org/grpc v1.65.0 h1:bs/cUb4lp1G5iImFFd3u5ixQzweKizoZJAwBNLR42lc=
google.golang.org/grpc v1.65.0/go.mod h1:WgYC2ypjlB0EiQi6wdKixMqukr6lBc0Vo+oOgjrM5ZQ=
google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg=
google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
Expand Down
17 changes: 16 additions & 1 deletion gateway/dataManager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,22 @@ package main
import(
"log"
"os"
"github.com/newrelic/go-agent/v3/newrelic"
"time"

)

func main() {
app, err := newrelic.NewApplication(
newrelic.ConfigAppName("DataManager"),
newrelic.ConfigLicense("eu01xx66792eeb67035b3ccc1fb4ee54FFFFNRAL"),
newrelic.ConfigAppLogForwardingEnabled(true),
)
if err != nil {
log.Println("Error:","Newrelic: %w", err)
return
}

gatewayID := os.Getenv("GATEWAY_ID")
if gatewayID == "" {
log.Fatal("GATEWAY_ID environment variable is not set")
Expand All @@ -23,9 +36,11 @@ func main() {
alerter.init(downSampler)
rabbitMQClient.init(alerter)

rabbitMQClient.consume("sensor.#")
rabbitMQClient.consume("sensor.#", app)

// prometheusClient.close()
rabbitMQClient.close()

app.Shutdown(10 * time.Second)
}

8 changes: 5 additions & 3 deletions gateway/dataManager/mqttClient.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"strings"
"os"
"strconv"

"github.com/newrelic/go-agent/v3/newrelic"
amqp "github.com/rabbitmq/amqp091-go"
)
type RabbitMQClient struct {
Expand Down Expand Up @@ -77,7 +77,7 @@ func (rabbitMQClient *RabbitMQClient) publish(topic string, message string) {
}


func (rabbitMQClient *RabbitMQClient) consume(topic string){
func (rabbitMQClient *RabbitMQClient) consume(topic string, app *newrelic.Application){
ch, err := rabbitMQClient.conn.Channel()
failOnError(err, "Failed to open a channel")
defer ch.Close()
Expand Down Expand Up @@ -133,8 +133,10 @@ func (rabbitMQClient *RabbitMQClient) consume(topic string){
value, _ := strconv.ParseFloat(string(d.Body), 64)

sample := Sample{Time: time.Now(), Value: value}


txn := app.StartTransaction("Get data")
rabbitMQClient.alerter.sendSample(metric, sample)
defer txn.End()
}
}()

Expand Down
18 changes: 16 additions & 2 deletions gateway/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ services:
- RABBITMQ_PASSWORD=guest
- NOTIFICATION_SERVER=http://doctor.al.apoorva64.com
- CLIENT_INFO_SERVER=http://doctor.al.apoorva64.com
- GATEWAY_ID=671954d2490bd363cd077544
- GATEWAY_ID=671ec1f0c368aa3dd8f66649
volumes:
- /etc/localtime:/etc/localtime:ro
depends_on:
Expand All @@ -47,7 +47,21 @@ services:
- 127.0.0.1:8080:15672
networks:
- internal


agent:
container_name: newrelic-infra
image: newrelic/infrastructure:latest
cap_add:
- SYS_PTRACE
network_mode: host
pid: host
privileged: true
volumes:
- "/:/host:ro"
- "/var/run/docker.sock:/var/run/docker.sock"
- "./newrelic-infra.yml:/etc/newrelic-infra.yml"
restart: unless-stopped

networks:
internal:
#poulet_internal:
Expand Down
1 change: 1 addition & 0 deletions gateway/newrelic-infra.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
license_key: eu01xx27ed92867e52dd4686fea1ff1aFFFFNRAL
4 changes: 3 additions & 1 deletion gateway/simulate.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
"http://"+ADAPTER_URL+"/api/data/acceleration",
]



value_ranges = [
(0, 100), # acceleration range
(50, 120), # heartrate range
Expand Down Expand Up @@ -53,7 +55,7 @@ def get_acceleration():
# Minor random variations with occasional spikes for movement
return baseline_values["acceleration"] + random.gauss(0, 1) + (5 * random.choice([0, 1]) if random.random() < 0.1 else 0)

data_generators = [get_acceleration, get_heartrate, get_temperature, get_glucose]
data_generators = [get_temperature, get_heartrate, get_glucose, get_acceleration]

# Function to send POST request to an endpoint with a random number
def send_post_request(url, interval, data_function):
Expand Down

0 comments on commit c315154

Please sign in to comment.