-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support new gnmi config interface in telemetry container.
Signed-off-by: Gang Lv ganglv@microsoft.com
- Loading branch information
Showing
40 changed files
with
4,689 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
package common_utils | ||
|
||
const GNMI_WORK_PATH = "/etc/sonic/gnmi" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package common_utils | ||
|
||
import ( | ||
"fmt" | ||
"syscall" | ||
"unsafe" | ||
) | ||
|
||
// Use share memory to dump GNMI internal counters, | ||
// GNMI server and gnmi_dump should use memKey to access the share memory, | ||
// memSize is 1024 bytes, so we can support 128 counters | ||
// memMode is 0x380, this value is O_RDWR|IPC_CREAT, | ||
// O_RDWR means: Owner can write and read the file, everyone else can't. | ||
// IPC_CREAT means: Create a shared memory segment if a shared memory identifier does not exist for memKey. | ||
var ( | ||
memKey = 7749 | ||
memSize = 1024 | ||
memMode = 0x380 | ||
) | ||
|
||
func SetMemCounters(counters *[len(CountersName)]uint64) error { | ||
shmid, _, err := syscall.Syscall(syscall.SYS_SHMGET, uintptr(memKey), uintptr(memSize), uintptr(memMode)) | ||
if int(shmid) == -1 { | ||
return fmt.Errorf("syscall error, err: %v\n", err) | ||
} | ||
|
||
shmaddr, _, err := syscall.Syscall(syscall.SYS_SHMAT, shmid, 0, 0) | ||
if int(shmaddr) == -1 { | ||
return fmt.Errorf("syscall error, err: %v\n", err) | ||
} | ||
defer syscall.Syscall(syscall.SYS_SHMDT, shmaddr, 0, 0) | ||
|
||
const size = unsafe.Sizeof(uint64(0)) | ||
addr := uintptr(unsafe.Pointer(shmaddr)) | ||
|
||
for i := 0; i < len(counters); i++ { | ||
*(*uint64)(unsafe.Pointer(addr)) = counters[i] | ||
addr += size | ||
} | ||
return nil | ||
} | ||
|
||
func GetMemCounters(counters *[len(CountersName)]uint64) error { | ||
shmid, _, err := syscall.Syscall(syscall.SYS_SHMGET, uintptr(memKey), uintptr(memSize), uintptr(memMode)) | ||
if int(shmid) == -1 { | ||
return fmt.Errorf("syscall error, err: %v\n", err) | ||
} | ||
|
||
shmaddr, _, err := syscall.Syscall(syscall.SYS_SHMAT, shmid, 0, 0) | ||
if int(shmaddr) == -1 { | ||
return fmt.Errorf("syscall error, err: %v\n", err) | ||
} | ||
defer syscall.Syscall(syscall.SYS_SHMDT, shmaddr, 0, 0) | ||
|
||
const size = unsafe.Sizeof(uint64(0)) | ||
addr := uintptr(unsafe.Pointer(shmaddr)) | ||
|
||
for i := 0; i < len(counters); i++ { | ||
counters[i] = *(*uint64)(unsafe.Pointer(addr)) | ||
addr += size | ||
} | ||
return nil | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"github.com/sonic-net/sonic-gnmi/common_utils" | ||
) | ||
|
||
const help = ` | ||
gnmi_dump is used to dump internal counters for debugging purpose, | ||
including GNMI request counter, GNOI request counter and DBUS request counter. | ||
` | ||
|
||
func main() { | ||
flag.Usage = func() { | ||
fmt.Print(help) | ||
} | ||
flag.Parse() | ||
var counters [len(common_utils.CountersName)]uint64 | ||
err := common_utils.GetMemCounters(&counters) | ||
if err != nil { | ||
fmt.Printf("Error: Fail to read counters, %v", err) | ||
return | ||
} | ||
fmt.Printf("Dump GNMI counters\n") | ||
for i := 0; i < len(common_utils.CountersName); i++ { | ||
fmt.Printf("%v---%v\n", common_utils.CountersName[i], counters[i]) | ||
} | ||
} |
Oops, something went wrong.