(ctx context.Context, engineStateRootDir string, eng *server.Server)
| 121 | } |
| 122 | |
| 123 | func logMetrics(ctx context.Context, engineStateRootDir string, eng *server.Server) { |
| 124 | for range time.Tick(60 * time.Second) { |
| 125 | l := bklog.G(ctx) |
| 126 | |
| 127 | // controller stats |
| 128 | l = eng.LogMetrics(l) |
| 129 | |
| 130 | // goroutine stats |
| 131 | l = l.WithField("goroutine-count", runtime.NumGoroutine()) |
| 132 | |
| 133 | // system cpu stats |
| 134 | cpuStats, err := cpu.Get() |
| 135 | if err == nil { |
| 136 | l = withUnsignedIntField(l, "cpu-total", cpuStats.Total) |
| 137 | l = withUnsignedIntField(l, "cpu-user", cpuStats.User) |
| 138 | l = withUnsignedIntField(l, "cpu-nice", cpuStats.Nice) |
| 139 | l = withUnsignedIntField(l, "cpu-system", cpuStats.System) |
| 140 | l = withUnsignedIntField(l, "cpu-idle", cpuStats.Idle) |
| 141 | l = withUnsignedIntField(l, "cpu-iowait", cpuStats.Iowait) |
| 142 | l = withUnsignedIntField(l, "cpu-irq", cpuStats.Irq) |
| 143 | l = withUnsignedIntField(l, "cpu-softirq", cpuStats.Softirq) |
| 144 | l = withUnsignedIntField(l, "cpu-steal", cpuStats.Steal) |
| 145 | l = withSignedIntField(l, "cpu-count", cpuStats.CPUCount) |
| 146 | } else { |
| 147 | l = l.WithField("cpu-error", err.Error()) |
| 148 | } |
| 149 | |
| 150 | // system loadavg stats |
| 151 | loadAvgStats, err := loadavg.Get() |
| 152 | if err == nil { |
| 153 | l = withFloatField(l, "loadavg-1", loadAvgStats.Loadavg1) |
| 154 | l = withFloatField(l, "loadavg-5", loadAvgStats.Loadavg5) |
| 155 | l = withFloatField(l, "loadavg-15", loadAvgStats.Loadavg15) |
| 156 | } else { |
| 157 | l = l.WithField("loadavg-error", err.Error()) |
| 158 | } |
| 159 | |
| 160 | // system memory stats |
| 161 | memStats, err := memory.Get() |
| 162 | if err == nil { |
| 163 | l = withUnsignedIntField(l, "mem-total", memStats.Total) |
| 164 | l = withUnsignedIntField(l, "mem-free", memStats.Free) |
| 165 | l = withUnsignedIntField(l, "mem-available", memStats.Available) |
| 166 | l = withUnsignedIntField(l, "mem-buffers", memStats.Buffers) |
| 167 | l = withUnsignedIntField(l, "mem-cached", memStats.Cached) |
| 168 | l = withUnsignedIntField(l, "mem-active", memStats.Active) |
| 169 | l = withUnsignedIntField(l, "mem-inactive", memStats.Inactive) |
| 170 | l = withUnsignedIntField(l, "mem-swap-cached", memStats.SwapCached) |
| 171 | l = withUnsignedIntField(l, "mem-swap-total", memStats.SwapTotal) |
| 172 | l = withUnsignedIntField(l, "mem-swap-free", memStats.SwapFree) |
| 173 | l = withUnsignedIntField(l, "mem-mapped", memStats.Mapped) |
| 174 | l = withUnsignedIntField(l, "mem-shmem", memStats.Shmem) |
| 175 | l = withUnsignedIntField(l, "mem-slab", memStats.Slab) |
| 176 | l = withUnsignedIntField(l, "mem-page-tables", memStats.PageTables) |
| 177 | l = withUnsignedIntField(l, "mem-committed", memStats.Committed) |
| 178 | l = withUnsignedIntField(l, "mem-vmalloc-used", memStats.VmallocUsed) |
| 179 | } else { |
| 180 | l = l.WithField("mem-error", err.Error()) |
no test coverage detected