Skip to content

Commit

Permalink
chore: get rid of hostname by providing unique auth header
Browse files Browse the repository at this point in the history
  • Loading branch information
tanmoysrt committed Mar 19, 2024
1 parent 38db66a commit 91d8d82
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 10 deletions.
1 change: 0 additions & 1 deletion README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ It will collect system stats and usage stats of all running swarm services and w
- SUBMISSION_ENDPOINT: The endpoint to submit the stats to
- AUTHORIZATION_HEADER_VAL (optional): The value of the authorization header
- DOCKER_HOST: unix or tcp socket to connect to
- HOSTNAME: The hostname of the server (not the container)

**Volume Bind**
- bind **<host docker socket path>** to -> **provided path in env DOCKER_HOST**
Expand Down
8 changes: 0 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,20 @@ func main() {
* SUBMISSION_ENDPOINT: The endpoint to submit the stats to
* AUTHORIZATION_HEADER_VAL: The value of the authorization header
* DOCKER_HOST: unix or tcp socket to connect to
* HOSTNAME: The hostname of the host
* This will send the stats to the endpoint using the authorization header
*
* Configure Volume Mounts
* <docker socket of host>:/var/run/docker.sock
*/
submissionEndpoint := os.Getenv("SUBMISSION_ENDPOINT")
authorizationHeaderVal := os.Getenv("AUTHORIZATION_HEADER_VAL")
hostname := os.Getenv("HOSTNAME")
// reject if the submission endpoint is not set
if submissionEndpoint == "" {
panic("SUBMISSION_ENDPOINT is not set")
}
if os.Getenv("DOCKER_HOST") == "" {
panic("DOCKER_HOST is not set")
}
// if hostname is not set, fetch it from the system
if hostname == "" {
panic("HOSTNAME is not set")
}
_, _ = host.Stats() // intentionally called. just to initialize current network stats
// create a new docker client
dockerClient, err := client.NewClientWithOpts(client.FromEnv)
Expand All @@ -52,8 +46,6 @@ func main() {
log.Println("Error fetching stats: ", err)
continue
}
// set hostname
statsData.Hostname = hostname
// convert to json
jsonData, err := statsData.JSON()
if err != nil {
Expand Down
1 change: 0 additions & 1 deletion types.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
)

type StatsData struct {
Hostname string `json:"hostname"`
SystemStat host.ResourceStats `json:"system"`
ServiceStats map[string]*service.ResourceStats `json:"services"`
TimeStamp uint64 `json:"timestamp"`
Expand Down

0 comments on commit 91d8d82

Please sign in to comment.