| 222 | } |
| 223 | |
| 224 | func (e *engineImpl) Collect(ns string, isSys bool, desire specv1.Desire) specv1.Report { |
| 225 | nodeInfo, err := e.ami.CollectNodeInfo() |
| 226 | if err != nil { |
| 227 | e.log.Warn("failed to collect node info", log.Error(err)) |
| 228 | } |
| 229 | nodeStats, err := e.ami.CollectNodeStats() |
| 230 | if err != nil { |
| 231 | e.log.Warn("failed to collect node stats", log.Error(err)) |
| 232 | } |
| 233 | appStats, err := e.ami.StatsApps(ns) |
| 234 | if err != nil { |
| 235 | e.log.Warn("failed to collect app stats", log.Error(err)) |
| 236 | } |
| 237 | modeInfo, err := e.ami.GetModeInfo() |
| 238 | if err != nil { |
| 239 | e.log.Warn("failed to get mode info", log.Error(err)) |
| 240 | } |
| 241 | apps := make([]specv1.AppInfo, 0) |
| 242 | filterStats := make([]specv1.AppStats, 0) |
| 243 | for _, info := range appStats { |
| 244 | app := specv1.AppInfo{ |
| 245 | Name: info.Name, |
| 246 | Version: info.Version, |
| 247 | } |
| 248 | apps = append(apps, app) |
| 249 | filterStats = append(filterStats, info) |
| 250 | } |
| 251 | if desire != nil { |
| 252 | apps = alignApps(apps, desire.AppInfos(isSys)) |
| 253 | } |
| 254 | r := specv1.Report{ |
| 255 | "time": time.Now(), |
| 256 | "modeinfo": modeInfo, |
| 257 | "node": nodeInfo, |
| 258 | "nodestats": nodeStats, |
| 259 | } |
| 260 | r.SetAppInfos(isSys, apps) |
| 261 | r.SetAppStats(isSys, filterStats) |
| 262 | return r |
| 263 | } |
| 264 | |
| 265 | func (e *engineImpl) reportAndApply(isSys, delete bool, desire specv1.Desire) error { |
| 266 | var ns string |