add machineId, gofmt

pull/3/head
Simon Let 7 years ago
parent 4d8d7efa4d
commit abcd44e108
  1. 22
      collect/resh-collect.go
  2. 1
      common/resh-common.go

@ -3,17 +3,18 @@ package main
import ( import (
"bytes" "bytes"
"encoding/json" "encoding/json"
"flag"
"github.com/BurntSushi/toml"
common "github.com/curusarn/resh/common"
"io/ioutil"
"log"
"net/http"
"os" "os"
"os/exec" "os/exec"
"os/user" "os/user"
"path/filepath" "path/filepath"
"flag"
"log"
"net/http"
"strconv" "strconv"
"strings" "strings"
common "github.com/curusarn/resh/common"
"github.com/BurntSushi/toml"
) )
func main() { func main() {
@ -84,7 +85,6 @@ func main() {
realtimeBeforeLocal := realtimeBefore + timezoneBeforeOffset realtimeBeforeLocal := realtimeBefore + timezoneBeforeOffset
realtimeAfterLocal := realtimeAfter + timezoneAfterOffset realtimeAfterLocal := realtimeAfter + timezoneAfterOffset
rec := common.Record{ rec := common.Record{
// core // core
CmdLine: *cmdLine, CmdLine: *cmdLine,
@ -127,6 +127,7 @@ func main() {
RealtimeSinceBoot: realtimeSinceBoot, RealtimeSinceBoot: realtimeSinceBoot,
GitWorkTree: getGitDir(), GitWorkTree: getGitDir(),
MachineId: getMachineId(),
} }
sendRecord(rec, strconv.Itoa(config.Port)) sendRecord(rec, strconv.Itoa(config.Port))
} }
@ -151,6 +152,14 @@ func sendRecord(r common.Record, port string) {
} }
} }
func getMachineId() string {
dat, err := ioutil.ReadFile("/etc/machine-id")
if err != nil {
log.Fatal("failed to open /etc/machine-id")
}
return string(dat)
}
func getGitDir() string { func getGitDir() string {
// assume we are in pwd // assume we are in pwd
gitWorkTree := os.Getenv("GIT_WORK_TREE") gitWorkTree := os.Getenv("GIT_WORK_TREE")
@ -189,4 +198,3 @@ func getTimezoneOffsetInSeconds(zone string) float64 {
secs := ((hours * 60) + mins) * 60 secs := ((hours * 60) + mins) * 60
return float64(secs) return float64(secs)
} }

@ -42,6 +42,7 @@ type Record struct {
//Logs []string `json: "logs"` //Logs []string `json: "logs"`
GitWorkTree string `json:"gitWorkTree"` GitWorkTree string `json:"gitWorkTree"`
MachineId string `json:"machineId"`
} }
type Config struct { type Config struct {

Loading…
Cancel
Save