Skip to content

Commit

Permalink
Merge pull request #1 from Kenits/dev
Browse files Browse the repository at this point in the history
add go mod, rework docker, some little fix and some style
  • Loading branch information
kenits authored Jun 14, 2019
2 parents 3094190 + 3472f96 commit 6d732ec
Show file tree
Hide file tree
Showing 11 changed files with 74 additions and 54 deletions.
23 changes: 0 additions & 23 deletions .travis.yml

This file was deleted.

11 changes: 8 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
FROM golang:1.12 as build
RUN go get -d -v github.com/Kenits/[email protected]
RUN go build -v github.com/Kenits/agent


FROM scratch
MAINTAINER Pavol Noha <pavol.noha@gmail.com>
LABEL maintainer="deimos.kenit@gmail.com"
EXPOSE 8080
WORKDIR /
COPY agent /
ENTRYPOINT ["./agent"]
COPY --from=build go/agent /
ENTRYPOINT ["./agent"]
7 changes: 0 additions & 7 deletions Makefile

This file was deleted.

3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

Swarmpit docker agent.

[![version](https://img.shields.io/github/release-pre/swarmpit/agent.svg)](https://github.com/swarmpit/agent/releases)
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/swarmpit/agent/pulls)
Fork for multi arch build.

## Run

Expand Down
19 changes: 19 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module github.com/Kenits/agent

go 1.12

require (
github.com/Microsoft/go-winio v0.4.12 // indirect
github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d // indirect
github.com/docker/distribution v2.7.1+incompatible // indirect
github.com/docker/docker v1.13.1
github.com/docker/go-connections v0.4.0 // indirect
github.com/docker/go-units v0.4.0 // indirect
github.com/go-ole/go-ole v1.2.4 // indirect
github.com/gorilla/mux v1.7.2
github.com/opencontainers/go-digest v1.0.0-rc1 // indirect
github.com/pkg/errors v0.8.1 // indirect
github.com/shirou/gopsutil v2.18.12+incompatible
golang.org/x/net v0.0.0-20190613194153-d28f0bde5980 // indirect
golang.org/x/sys v0.0.0-20190614160838-b47fdc937951 // indirect
)
29 changes: 29 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
github.com/Microsoft/go-winio v0.4.12 h1:xAfWHN1IrQ0NJ9TBC0KBZoqLjzDTr1ML+4MywiUOryc=
github.com/Microsoft/go-winio v0.4.12/go.mod h1:VhR8bwka0BXejwEJY73c50VrPtXAaKcyvVC4A4RozmA=
github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d h1:G0m3OIz70MZUWq3EgK3CesDbo8upS2Vm9/P3FtgI+Jk=
github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg=
github.com/docker/distribution v2.7.1+incompatible h1:a5mlkVzth6W5A4fOsS3D2EO5BUmsJpcB+cRlLU7cSug=
github.com/docker/distribution v2.7.1+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w=
github.com/docker/docker v1.13.1 h1:IkZjBSIc8hBjLpqeAbeE5mca5mNgeatLHBy3GO78BWo=
github.com/docker/docker v1.13.1/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
github.com/docker/go-connections v0.4.0 h1:El9xVISelRB7BuFusrZozjnkIM5YnzCViNKohAFqRJQ=
github.com/docker/go-connections v0.4.0/go.mod h1:Gbd7IOopHjR8Iph03tsViu4nIes5XhDvyHbTtUxmeec=
github.com/docker/go-units v0.4.0 h1:3uh0PgVws3nIA0Q+MwDC8yjEPf9zjRfZZWXZYDct3Tw=
github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
github.com/go-ole/go-ole v1.2.4 h1:nNBDSCOigTSiarFpYE9J/KtEA1IOW4CNeqT9TQDqCxI=
github.com/go-ole/go-ole v1.2.4/go.mod h1:XCwSNxSkXRo4vlyPy93sltvi/qJq0jqQhjqQNIwKuxM=
github.com/gorilla/mux v1.7.2 h1:zoNxOV7WjqXptQOVngLmcSQgXmgk4NMz1HibBchjl/I=
github.com/gorilla/mux v1.7.2/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
github.com/opencontainers/go-digest v1.0.0-rc1 h1:WzifXhOVOEOuFYOJAW6aQqW0TooG2iki3E3Ii+WN7gQ=
github.com/opencontainers/go-digest v1.0.0-rc1/go.mod h1:cMLVZDEM3+U2I4VmLI6N8jQYUd2OVphdqWwCJHrFt2s=
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/shirou/gopsutil v2.18.12+incompatible h1:1eaJvGomDnH74/5cF4CTmTbLHAriGFsTZppLXDX93OM=
github.com/shirou/gopsutil v2.18.12+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/net v0.0.0-20190613194153-d28f0bde5980 h1:dfGZHvZk057jK2MCeWus/TowKpJ8y4AmooUzdBSR9GU=
golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190614160838-b47fdc937951 h1:ZUgGZ7PSkne6oY+VgAvayrB16owfm9/DKAtgWubzgzU=
golang.org/x/sys v0.0.0-20190614160838-b47fdc937951/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
2 changes: 1 addition & 1 deletion handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"net/http"
"encoding/json"
"github.com/swarmpit/agent/setup"
"github.com/Kenits/agent/setup"
"github.com/docker/docker/client"
"github.com/docker/docker/api/types"
"github.com/gorilla/mux"
Expand Down
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"log"
"net/http"
"github.com/docker/docker/client"
"github.com/swarmpit/agent/swarmpit"
"github.com/swarmpit/agent/swarmpit/task"
"github.com/Kenits/agent/swarmpit"
"github.com/Kenits/agent/swarmpit/task"
)

func main() {
Expand Down
2 changes: 1 addition & 1 deletion swarmpit/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"bytes"
"net/http"
"encoding/json"
"github.com/swarmpit/agent/setup"
"github.com/Kenits/agent/setup"
)

var arg = setup.GetArgs()
Expand Down
2 changes: 1 addition & 1 deletion swarmpit/task/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"context"
"github.com/docker/docker/client"
"github.com/docker/docker/api/types"
"github.com/swarmpit/agent/swarmpit"
"github.com/Kenits/agent/swarmpit"
)

func HandleEvents(cli *client.Client) {
Expand Down
26 changes: 12 additions & 14 deletions swarmpit/task/stats.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
package task

import (
"context"
"encoding/json"
"io"
"log"
"time"
"sync"
"context"
"runtime"
"encoding/json"
"github.com/docker/docker/client"
"sync"
"time"

"github.com/Kenits/agent/setup"
"github.com/Kenits/agent/swarmpit"
"github.com/docker/docker/api/types"
"github.com/shirou/gopsutil/mem"
"github.com/shirou/gopsutil/disk"
"github.com/docker/docker/client"
"github.com/shirou/gopsutil/cpu"
"github.com/swarmpit/agent/setup"
"github.com/swarmpit/agent/swarmpit"
"github.com/shirou/gopsutil/disk"
"github.com/shirou/gopsutil/mem"
)

var arg = setup.GetArgs()
Expand Down Expand Up @@ -123,7 +124,7 @@ func ContainersUsage(cli *client.Client) (stats []ContainerStatus) {
for _, v := range resp {
go func(v types.Container) {
defer wg.Done()
var stat = ContainerUsage(cli, v.ID);
var stat = ContainerUsage(cli, v.ID)
mux.Lock()
stats = append(stats, stat)
mux.Unlock()
Expand Down Expand Up @@ -199,12 +200,9 @@ func calculateCPUPercentUnix(previousCPU, previousSystem uint64, v *types.StatsJ
cpuPercent = 0.0
cpuDelta = float64(v.CPUStats.CPUUsage.TotalUsage) - float64(previousCPU)
systemDelta = float64(v.CPUStats.SystemUsage) - float64(previousSystem)
onlineCPUs = float64(v.CPUStats.OnlineCPUs)
onlineCPUs = float64(len(v.CPUStats.CPUUsage.PercpuUsage))
)

if onlineCPUs == 0.0 {
onlineCPUs = float64(len(v.CPUStats.CPUUsage.PercpuUsage))
}
if systemDelta > 0.0 && cpuDelta > 0.0 {
cpuPercent = (cpuDelta / systemDelta) * onlineCPUs * 100.0
}
Expand Down

0 comments on commit 6d732ec

Please sign in to comment.