Skip to content

Commit

Permalink
Optimize dockerfile (#124)
Browse files Browse the repository at this point in the history
* Optimize dockerfile

* Fix typo

* Update test5 to use elastest metrics
  • Loading branch information
pchico83 authored Apr 17, 2018
1 parent 23aa6d1 commit 4c10e42
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 22 deletions.
12 changes: 7 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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"]
24 changes: 8 additions & 16 deletions demo/ems-tests/test5/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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++
}
}
Expand Down
2 changes: 1 addition & 1 deletion new_startmeup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 &

Expand Down

0 comments on commit 4c10e42

Please sign in to comment.