Skip to content

Commit

Permalink
Merge pull request #15 from instana/better_announce_under_kubernetes
Browse files Browse the repository at this point in the history
Improved Announce Under Kubernetes
  • Loading branch information
pglombardo authored Mar 27, 2017
2 parents 09e5bc9 + 3bfbfcc commit d7a6c4b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
7 changes: 3 additions & 4 deletions fsm.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,9 @@ func (r *fsmS) announceSensor(e *f.Event) {

go func(cb func(b bool, from *FromS)) {

d := &Discovery{
PID: os.Getpid(),
Name: os.Args[0],
Args: os.Args[1:]}
d := &Discovery{PID: os.Getpid()}

d.Name, d.Args = getCommandLine()

var socket net.Conn
if _, err := os.Stat("/proc"); err == nil {
Expand Down
24 changes: 24 additions & 0 deletions util.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package instana

import (
"io/ioutil"
"math/rand"
"os"
"strconv"
"strings"
"sync"
"time"
)
Expand All @@ -16,3 +20,23 @@ func randomID() uint64 {
defer seededIDLock.Unlock()
return uint64(seededIDGen.Int63())
}

func getCommandLine() (string, []string) {
var cmdline_path string = "/proc/" + strconv.Itoa(os.Getpid()) + "/cmdline"

cmdline, err := ioutil.ReadFile(cmdline_path)

if err != nil {
log.debug("No /proc. Returning OS reported cmdline")
return os.Args[0], os.Args[1:]
}

parts := strings.FieldsFunc(string(cmdline), func(c rune) bool {
if c == '\u0000' {
return true
}
return false
})
log.debug("cmdline says:", parts[0], parts[1:])
return parts[0], parts[1:]
}

0 comments on commit d7a6c4b

Please sign in to comment.