{
  "$schema": "./.schemas/page.schema.json",
  "title": "Processes",
  "icon": "cpu",
  "sidebar": false,
  "sources": {
    "programs": {
      "hosts": {
        "list": "glances-hosts",
        "only": "{param.box}"
      },
      "secret": "glances",
      "secret_optional": true,
      "auth": {
        "type": "basic"
      },
      "every": "1m",
      "requests": {
        "list": "/api/4/programlist"
      },
      "derive": [
        {
          "name": "rows",
          "value": {
            "each": "list",
            "fields": {
              "name": "name",
              "cpu": {
                "path": "cpu_percent",
                "round": 1,
                "default": 0
              },
              "mem": {
                "path": "memory_percent",
                "round": 1,
                "default": 0
              },
              "rss": {
                "path": "memory_info.rss",
                "default": 0
              },
              "procs": {
                "if": {
                  "path": "nprocs",
                  "gt": 1
                },
                "then": {
                  "template": "{nprocs} processes"
                },
                "else": {
                  "template": "1 process"
                }
              }
            }
          }
        },
        {
          "name": "count",
          "value": {
            "count": "rows"
          }
        }
      ]
    }
  },
  "cards": [
    {
      "id": "programs",
      "type": "tabs",
      "tabs": [
        {
          "label": "CPU",
          "cards": [
            {
              "id": "by-cpu",
              "type": "list",
              "max_items": 15,
              "items": [],
              "source": {
                "ref": "programs",
                "empty": {
                  "when": {
                    "path": "count",
                    "equals": 0
                  },
                  "text": "Glances sent no processes"
                },
                "map": {
                  "label": {
                    "if": {
                      "path": "count",
                      "gt": 40
                    },
                    "then": {
                      "template": "40 of {count}"
                    }
                  },
                  "items": {
                    "each": "rows",
                    "sort": {
                      "by": "cpu",
                      "order": "desc"
                    },
                    "limit": 40,
                    "fields": {
                      "text": {
                        "template": "{name} · {cpu}%"
                      },
                      "detail": {
                        "template": "{procs}"
                      }
                    }
                  }
                }
              }
            }
          ]
        },
        {
          "label": "Memory",
          "cards": [
            {
              "id": "by-memory",
              "type": "list",
              "max_items": 15,
              "items": [],
              "source": {
                "ref": "programs",
                "empty": {
                  "when": {
                    "path": "count",
                    "equals": 0
                  },
                  "text": "Glances sent no processes"
                },
                "map": {
                  "label": {
                    "if": {
                      "path": "count",
                      "gt": 40
                    },
                    "then": {
                      "template": "40 of {count}"
                    }
                  },
                  "items": {
                    "each": "rows",
                    "sort": {
                      "by": "rss",
                      "order": "desc"
                    },
                    "limit": 40,
                    "fields": {
                      "text": {
                        "template": "{name} · {rss|bytes}"
                      },
                      "detail": {
                        "template": "{procs}"
                      }
                    }
                  }
                }
              }
            }
          ]
        }
      ]
    }
  ],
  "params": {
    "box": {
      "list_key": "glances-hosts",
      "example": "h0000000000000000"
    }
  }
}
