简体   繁体   中英

Programmatically determine number of cores and amount of memory available to Spark

The Spark Web UI shows some interesting information about the resources available to the cluster as a whole.

Spark Web UI

I'm specifically interested in the values for:

  • Workers
  • Cores
  • Memory

How can I query these pieces of information about the overall cluster programmatically?

Spark doesn't really expose this kind of info, it's all hidden in the Master and transferred to the WebUI.

You can however use a small hack, the WebUI supports JSON by appending /json/ to a page.

So, going to http://<master-host>:<master-port>/json/ will return just the info you're looking for:

{
  url: "spark://<host>:<port>",
  workers: [ ],
  cores: 0,
  coresused: 0,
  memory: 0,
  memoryused: 0,
  activeapps: [ ],
  completedapps: [ ],
  activedrivers: [ ],
  status: "ALIVE"
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM