diff --git a/Dockerfile b/Dockerfile index 3262f8b..bc93dd5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -19,9 +19,7 @@ RUN swagger generate server RUN sh ./convertpaths.sh FROM golang:latest as builder2 -COPY . /go/src/github.com/elastest/elastest-monitoring-service WORKDIR /go -COPY --from=swaggerbuilder /go/src/swagger-go ./ RUN go get github.com/go-openapi/analysis RUN go get github.com/go-openapi/errors @@ -36,20 +34,21 @@ RUN go get github.com/jessevdk/go-flags RUN go get github.com/golang/protobuf/proto RUN go get google.golang.org/grpc RUN go get google.golang.org/grpc/reflection + +COPY . /go/src/github.com/elastest/elastest-monitoring-service +COPY --from=swaggerbuilder /go/src/swagger-go ./ RUN CGO_ENABLED=0 GOOS=linux go build -o swagger cmd/monitoring-as-a-service-server/main.go FROM golang:latest as builder WORKDIR /go/src/github.com/elastest/elastest-monitoring-service -COPY . /go/src/github.com/elastest/elastest-monitoring-service RUN go get github.com/golang/protobuf/proto RUN go get google.golang.org/grpc RUN go get google.golang.org/grpc/reflection +COPY . /go/src/github.com/elastest/elastest-monitoring-service RUN CGO_ENABLED=0 GOOS=linux go build -o ems ./go_EMS FROM docker.elastic.co/logstash/logstash:5.4.0 WORKDIR /root/ -COPY --from=builder /go/src/github.com/elastest/elastest-monitoring-service/ems /usr/local/bin/go_EMS -COPY --from=builder2 /go/swagger /usr/local/bin/swagger COPY new_startmeup.sh /startmeup.sh COPY logstashcfgs/* /usr/share/logstash/pipeline/ COPY logstash.yml /usr/share/logstash/config/logstash.yml @@ -65,4 +64,7 @@ RUN mkdir /usr/share/logstash/in_data RUN mkdir /usr/share/logstash/out_data RUN mkdir /usr/share/logstash/outstatic_data +COPY --from=builder /go/src/github.com/elastest/elastest-monitoring-service/ems /usr/local/bin/go_EMS +COPY --from=builder2 /go/swagger /usr/local/bin/swagger + ENTRYPOINT ["/startmeup.sh"] diff --git a/demo/ems-tests/test5/main.go b/demo/ems-tests/test5/main.go index 6423cb6..71e2514 100644 --- a/demo/ems-tests/test5/main.go +++ b/demo/ems-tests/test5/main.go @@ -13,21 +13,13 @@ import ( ) type event struct { + Type string `yaml:"type,omitempty"` Message string `yaml:"message,omitempty"` - System system `yaml:"system,omitempty"` -} - -type system struct { - Process process `yaml:"process,omitempty"` - CPU cpu `yaml:"cpu,omitempty"` -} - -type process struct { - CWD string `yaml:"cwd,omitempty"` + CPU cpu `yaml:"cpu,omitempty"` } type cpu struct { - User user `yaml:"user,omitempty"` + TotalUsage float64 `yaml:"totalUsage,omitempty"` } type user struct { @@ -79,7 +71,7 @@ func main() { } var e event json.Unmarshal(input, &e) - if strings.Contains(e.Message, "STATUS_ON") { + if e.Type == "sutlogs" && strings.Contains(e.Message, "STATUS_ON") { if state == "" { state = "on" } else { @@ -94,7 +86,7 @@ func main() { } log.Println("Starting ON state") } - if strings.Contains(e.Message, "STATUS_OFF") { + if e.Type == "sutlogs" && strings.Contains(e.Message, "STATUS_OFF") { if state == "" { state = "off" } else { @@ -109,9 +101,9 @@ func main() { } log.Println("Starting OFF state") } - if e.System.CPU.User.Pct != 0.0 && state != "" { - fmt.Printf("CPU: %f\n", e.System.CPU.User.Pct) - cpu += e.System.CPU.User.Pct + if e.Type == "cpu" { + fmt.Printf("CPU: %f\n", e.CPU.TotalUsage) + cpu += e.CPU.TotalUsage items++ } } diff --git a/new_startmeup.sh b/new_startmeup.sh index e7a0844..265037c 100755 --- a/new_startmeup.sh +++ b/new_startmeup.sh @@ -2,7 +2,7 @@ logstash -f /usr/share/logstash/pipeline/inlogstash.conf --path.data /usr/share/logstash/in_data &>/inlogs.txt & logstash -f /usr/share/logstash/pipeline/outlogstash.conf --config.reload.automatic --path.data /usr/share/logstash/out_data &>/outlogs.txt & -logstash -f /usr/share/logstash/pipeline/staticoutlogstash.conf --path.data /usr/share/logstash/outstatic_data &>/outsaticlogs.txt & +logstash -f /usr/share/logstash/pipeline/staticoutlogstash.conf --path.data /usr/share/logstash/outstatic_data &>/outstaticlogs.txt & swagger --port=8888 --host=0.0.0.0 &>/swaggerlogs.txt &