67
67
Measurement : "Memory" ,
68
68
Unit : metric .Unit_BYTES ,
69
69
}
70
+ metaGoLimitBytes = metric.Metadata {
71
+ Name : "sys.go.limitbytes" ,
72
+ Help : "Go soft memory limit" ,
73
+ Measurement : "Memory" ,
74
+ Unit : metric .Unit_BYTES ,
75
+ }
70
76
metaGoMemStackSysBytes = metric.Metadata {
71
77
Name : "sys.go.stack.systembytes" ,
72
78
Help : "Stack memory obtained from the OS." ,
@@ -591,13 +597,17 @@ const runtimeMetricMemStackOSBytes = "/memory/classes/os-stacks:bytes"
591
597
// metrics in /memory/classes.
592
598
const runtimeMetricGoTotal = "/memory/classes/total:bytes"
593
599
600
+ // Current soft memory limit (see debug.SetMemoryLimit).
601
+ const runtimeMetricGoLimit = "/gc/gomemlimit:bytes"
602
+
594
603
// Count of all completed GC cycles.
595
604
const runtimeMetricGCCount = "/gc/cycles/total:gc-cycles"
596
605
597
606
var runtimeMetrics = []string {
598
607
runtimeMetricGCAssist ,
599
608
runtimeMetricGoTotal ,
600
609
runtimeMetricHeapAlloc ,
610
+ runtimeMetricGoLimit ,
601
611
runtimeMetricHeapFragmentBytes ,
602
612
runtimeMetricHeapReservedBytes ,
603
613
runtimeMetricHeapReleasedBytes ,
@@ -774,6 +784,7 @@ type RuntimeStatSampler struct {
774
784
RunnableGoroutinesPerCPU * metric.GaugeFloat64
775
785
GoAllocBytes * metric.Gauge
776
786
GoTotalBytes * metric.Gauge
787
+ GoLimitBytes * metric.Gauge
777
788
GoMemStackSysBytes * metric.Gauge
778
789
GoHeapFragmentBytes * metric.Gauge
779
790
GoHeapReservedBytes * metric.Gauge
@@ -875,6 +886,7 @@ func NewRuntimeStatSampler(ctx context.Context, clock hlc.WallClock) *RuntimeSta
875
886
RunnableGoroutinesPerCPU : metric .NewGaugeFloat64 (metaRunnableGoroutinesPerCPU ),
876
887
GoAllocBytes : metric .NewGauge (metaGoAllocBytes ),
877
888
GoTotalBytes : metric .NewGauge (metaGoTotalBytes ),
889
+ GoLimitBytes : metric .NewGauge (metaGoLimitBytes ),
878
890
GoMemStackSysBytes : metric .NewGauge (metaGoMemStackSysBytes ),
879
891
GoHeapFragmentBytes : metric .NewGauge (metaGoHeapFragmentBytes ),
880
892
GoHeapReservedBytes : metric .NewGauge (metaGoHeapReservedBytes ),
@@ -1136,6 +1148,10 @@ func (rsr *RuntimeStatSampler) SampleEnvironment(ctx context.Context, cs *CGoMem
1136
1148
goAlloc := rsr .goRuntimeSampler .uint64 (runtimeMetricHeapAlloc )
1137
1149
goTotal := rsr .goRuntimeSampler .uint64 (runtimeMetricGoTotal ) -
1138
1150
rsr .goRuntimeSampler .uint64 (runtimeMetricHeapReleasedBytes )
1151
+ goLimit := rsr .goRuntimeSampler .uint64 (runtimeMetricGoLimit )
1152
+ if goLimit == math .MaxInt64 {
1153
+ goLimit = 0
1154
+ }
1139
1155
stackTotal := rsr .goRuntimeSampler .uint64 (runtimeMetricMemStackHeapBytes ) +
1140
1156
osStackBytes
1141
1157
heapFragmentBytes := rsr .goRuntimeSampler .uint64 (runtimeMetricHeapFragmentBytes )
@@ -1147,6 +1163,7 @@ func (rsr *RuntimeStatSampler) SampleEnvironment(ctx context.Context, cs *CGoMem
1147
1163
MemStackSysBytes : stackTotal ,
1148
1164
GoAllocBytes : goAlloc ,
1149
1165
GoTotalBytes : goTotal ,
1166
+ GoLimitBytes : goLimit ,
1150
1167
HeapFragmentBytes : heapFragmentBytes ,
1151
1168
HeapReservedBytes : heapReservedBytes ,
1152
1169
HeapReleasedBytes : heapReleasedBytes ,
@@ -1168,6 +1185,7 @@ func (rsr *RuntimeStatSampler) SampleEnvironment(ctx context.Context, cs *CGoMem
1168
1185
1169
1186
rsr .GoAllocBytes .Update (int64 (goAlloc ))
1170
1187
rsr .GoTotalBytes .Update (int64 (goTotal ))
1188
+ rsr .GoLimitBytes .Update (int64 (goLimit ))
1171
1189
rsr .GoMemStackSysBytes .Update (int64 (osStackBytes ))
1172
1190
rsr .GoHeapFragmentBytes .Update (int64 (heapFragmentBytes ))
1173
1191
rsr .GoHeapReservedBytes .Update (int64 (heapReservedBytes ))
0 commit comments