github.com/instana/go-sensor@v1.62.2-0.20240520081010-4919868049e1/acceptor/runtime.go (about)

     1  // (c) Copyright IBM Corp. 2021
     2  // (c) Copyright Instana Inc. 2020
     3  
     4  package acceptor
     5  
     6  import "strconv"
     7  
     8  // RuntimeInfo represents Go runtime info to be sent to com.insana.plugin.golang
     9  type RuntimeInfo struct {
    10  	Name          string `json:"name"`
    11  	Version       string `json:"version"`
    12  	Root          string `json:"goroot"`
    13  	MaxProcs      int    `json:"maxprocs"`
    14  	Compiler      string `json:"compiler"`
    15  	NumCPU        int    `json:"cpu"`
    16  	SensorVersion string `json:"iv,omitempty"`
    17  }
    18  
    19  // MemoryStats represents Go runtime memory stats to be sent to com.insana.plugin.golang
    20  type MemoryStats struct {
    21  	Alloc         uint64  `json:"alloc"`
    22  	TotalAlloc    uint64  `json:"total_alloc"`
    23  	Sys           uint64  `json:"sys"`
    24  	Lookups       uint64  `json:"lookups"`
    25  	Mallocs       uint64  `json:"mallocs"`
    26  	Frees         uint64  `json:"frees"`
    27  	HeapAlloc     uint64  `json:"heap_alloc"`
    28  	HeapSys       uint64  `json:"heap_sys"`
    29  	HeapIdle      uint64  `json:"heap_idle"`
    30  	HeapInuse     uint64  `json:"heap_in_use"`
    31  	HeapReleased  uint64  `json:"heap_released"`
    32  	HeapObjects   uint64  `json:"heap_objects"`
    33  	PauseTotalNs  uint64  `json:"pause_total_ns"`
    34  	PauseNs       uint64  `json:"pause_ns"`
    35  	NumGC         uint32  `json:"num_gc"`
    36  	GCCPUFraction float64 `json:"gc_cpu_fraction"`
    37  }
    38  
    39  // Metrics represents Go process metrics to be sent to com.insana.plugin.golang
    40  type Metrics struct {
    41  	CgoCall     int64 `json:"cgo_call"`
    42  	Goroutine   int   `json:"goroutine"`
    43  	MemoryStats `json:"memory"`
    44  }
    45  
    46  // GoProcessData is a representation of a Go process for com.instana.plugin.golang plugin
    47  type GoProcessData struct {
    48  	PID      int          `json:"pid"`
    49  	Snapshot *RuntimeInfo `json:"snapshot,omitempty"`
    50  	Metrics  Metrics      `json:"metrics"`
    51  }
    52  
    53  // NewGoProcessPluginPayload returns payload for the Go process plugin of Instana acceptor
    54  func NewGoProcessPluginPayload(data GoProcessData) PluginPayload {
    55  	const pluginName = "com.instana.plugin.golang"
    56  
    57  	return PluginPayload{
    58  		Name:     pluginName,
    59  		EntityID: strconv.Itoa(data.PID),
    60  		Data:     data,
    61  	}
    62  }