• YARN REST API 总结


    01 引言

    Yarn其实是有REST Api的,很多接口无需使用爬虫去爬页面,具体的接口使用在官网可以看到。

    接口地址https://hadoop.apache.org/docs/current/hadoop-yarn/hadoop-yarn-site/ResourceManagerRest.html

    在这里插入图片描述

    API 目录索引如下:

    02 常用接口

    注意Yarn REST API同时支持返回JSON或者XML格式的文本,只需要在请求头声明即可,比如需要返回XML(默认返回JSON,不需要显示声明),则请求头如下:

    Accept: application/xml
    GET http://rm-http-address:port/ws/v1/cluster/info
    
    • 1
    • 2

    2.1 指标接口

    请求地址:

    GET http://rm-http-address:port/ws/v1/cluster/metrics
    
    • 1

    响应接口:

    {
      "clusterMetrics":
      {
        "appsSubmitted":0,
        "appsCompleted":0,
        "appsPending":0,
        "appsRunning":0,
        "appsFailed":0,
        "appsKilled":0,
        "reservedMB":0,
        "availableMB":17408,
        "allocatedMB":0,
        "reservedVirtualCores":0,
        "availableVirtualCores":7,
        "allocatedVirtualCores":1,
        "containersAllocated":0,
        "containersReserved":0,
        "containersPending":0,
        "totalMB":17408,
        "totalVirtualCores":8,
        "totalNodes":1,
        "lostNodes":0,
        "unhealthyNodes":0,
        "decommissioningNodes":0,
        "decommissionedNodes":0,
        "rebootedNodes":0,
        "activeNodes":1,
        "shutdownNodes":0
      }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30

    2.2 应用接口

    2.2.1 应用列表接口

    请求地址:

    GET http://rm-http-address:port/ws/v1/cluster/apps
    
    • 1

    返回内容:

    {
      "apps":
      {
        "app":
        [
          {
            "id": "application_1476912658570_0002",
            "user": "user2",
            "name": "word count",
            "queue": "default",
            "state": "FINISHED",
            "finalStatus": "SUCCEEDED",
            "progress": 100,
            "trackingUI": "History",
            "trackingUrl": "http://host.domain.com:8088/cluster/app/application_1476912658570_0002",
            "diagnostics": "...",
            "clusterId": 1476912658570,
            "applicationType": "MAPREDUCE",
            "applicationTags": "",
            "priority": -1,
            "startedTime": 1476913457320,
            "finishedTime": 1476913761898,
            "elapsedTime": 304578,
            "amContainerLogs": "http://host.domain.com:8042/node/containerlogs/container_1476912658570_0002_02_000001/user2",
            "amHostHttpAddress": "host.domain.com:8042",
            "allocatedMB": 0,
            "allocatedVCores": 0,
            "runningContainers": 0,
            "memorySeconds": 206464,
            "vcoreSeconds": 201,
            "queueUsagePercentage": 0,
            "clusterUsagePercentage": 0,
            "preemptedResourceMB": 0,
            "preemptedResourceVCores": 0,
            "numNonAMContainerPreempted": 0,
            "numAMContainerPreempted": 0,
            "logAggregationStatus": "DISABLED",
            "unmanagedApplication": false,
            "appNodeLabelExpression": "",
            "amNodeLabelExpression": "",
            "resourceRequests": [
            {
                "capability": {
                    "memory": 4096,
                    "virtualCores": 1
                },
                "nodeLabelExpression": "",
                "numContainers": 0,
                "priority": {
                    "priority": 0
                },
                "relaxLocality": true,
                "resourceName": "*"
            },
            {
                "capability": {
                    "memory": 4096,
                    "virtualCores": 1
                },
                "nodeLabelExpression": "",
                "numContainers": 0,
                "priority": {
                    "priority": 20
                },
                "relaxLocality": true,
                "resourceName": "host1.domain.com"
            },
            {
                "capability": {
                    "memory": 4096,
                    "virtualCores": 1
                },
                "nodeLabelExpression": "",
                "numContainers": 0,
                "priority": {
                    "priority": 20
                },
                "relaxLocality": true,
                "resourceName": "host2.domain.com"
            }]
          },
          {
            "id": "application_1476912658570_0001",
            "user": "user1",
            "name": "Sleep job",
            "queue": "default",
            "state": "FINISHED",
            "finalStatus": "SUCCEEDED",
            "progress": 100,
            "trackingUI": "History",
            "trackingUrl": "http://host.domain.com:8088/cluster/app/application_1476912658570_0001",
            "diagnostics": "...",
            "clusterId": 1476912658570,
            "applicationType": "YARN",
            "applicationTags": "",
            "priority": -1,
            "startedTime": 1476913464750,
            "finishedTime": 1476913863175,
            "elapsedTime": 398425,
            "amContainerLogs": "http://host.domain.com:8042/node/containerlogs/container_1476912658570_0001_02_000001/user1",
            "amHostHttpAddress": "host.domain.com:8042",
            "allocatedMB": 0,
            "allocatedVCores": 0,
            "runningContainers": 0,
            "memorySeconds": 205410,
            "vcoreSeconds": 200,
            "queueUsagePercentage": 0,
            "clusterUsagePercentage": 0,
            "preemptedResourceMB": 0,
            "preemptedResourceVCores": 0,
            "numNonAMContainerPreempted": 0,
            "numAMContainerPreempted": 0,
            "logAggregationStatus": "DISABLED",
            "unmanagedApplication": false,
            "appNodeLabelExpression": "",
            "amNodeLabelExpression": "",
            "resourceRequests": [
            {
                "capability": {
                    "memory": 4096,
                    "virtualCores": 1
                },
                "nodeLabelExpression": "",
                "numContainers": 0,
                "priority": {
                    "priority": 0
                },
                "relaxLocality": true,
                "resourceName": "*"
            },
            {
                "capability": {
                    "memory": 4096,
                    "virtualCores": 1
                },
                "nodeLabelExpression": "",
                "numContainers": 0,
                "priority": {
                    "priority": 20
                },
                "relaxLocality": true,
                "resourceName": "host3.domain.com"
            },
            {
                "capability": {
                    "memory": 4096,
                    "virtualCores": 1
                },
                "nodeLabelExpression": "",
                "numContainers": 0,
                "priority": {
                    "priority": 20
                },
                "relaxLocality": true,
                "resourceName": "host4.domain.com"
            }]
          }
        ]
      }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122
    • 123
    • 124
    • 125
    • 126
    • 127
    • 128
    • 129
    • 130
    • 131
    • 132
    • 133
    • 134
    • 135
    • 136
    • 137
    • 138
    • 139
    • 140
    • 141
    • 142
    • 143
    • 144
    • 145
    • 146
    • 147
    • 148
    • 149
    • 150
    • 151
    • 152
    • 153
    • 154
    • 155
    • 156
    • 157
    • 158
    • 159
    • 160

    2.2.2 应用统计接口

    请求地址:

    GET http://rm-http-address:port/ws/v1/cluster/appstatistics?states=accepted,running,finished&applicationTypes=mapreduce
    
    • 1

    响应内容:

    {
      "appStatInfo":
      {
        "statItem":
        [
           {
              "state" : "accepted",
              "type" : "mapreduce",
              "count" : 4
           },
           {
              "state" : "running",
              "type" : "mapreduce",
              "count" : 1
           },
           {
              "state" : "finished",
              "type" : "mapreduce",
              "count" : 7
           }
        ]
      }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23

    2.2.3 应用详情

    请求地址:

    GET http://rm-http-address:port/ws/v1/cluster/apps/application_1476912658570_0002
    
    • 1

    响应内容:

    {
      "app": {
        "id": "application_1476912658570_0002",
        "user": "user2",
        "name": "word count",
        "queue": "default",
        "state": "FINISHED",
        "finalStatus": "SUCCEEDED",
        "progress": 100,
        "trackingUI": "History",
        "trackingUrl": "http://host.domain.com:8088/cluster/app/application_1476912658570_0002",
        "diagnostics": "...",
        "clusterId": 1476912658570,
        "applicationType": "YARN",
        "applicationTags": "",
        "priority": -1,
        "startedTime": 1476913457320,
        "finishedTime": 1476913761898,
        "elapsedTime": 304578,
        "amContainerLogs": "http://host.domain.com:8042/node/containerlogs/container_1476912658570_0002_02_000001/dr.who",
        "amHostHttpAddress": "host.domain.com:8042",
        "allocatedMB": -1,
        "allocatedVCores": -1,
        "runningContainers": -1,
        "memorySeconds": 206464,
        "vcoreSeconds": 201,
        "queueUsagePercentage": 0,
        "clusterUsagePercentage": 0,
        "preemptedResourceMB": 0,
        "preemptedResourceVCores": 0,
        "numNonAMContainerPreempted": 0,
        "numAMContainerPreempted": 0,
        "logAggregationStatus": "DISABLED",
        "unmanagedApplication": false,
        "appNodeLabelExpression": "",
        "amNodeLabelExpression": ""
      }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38

    2.3 队列接口

    请求地址:

    GET http://rm-http-address:port/ws/v1/cluster/apps/application_1399397633663_0003/queue
    
    • 1

    响应内容:

    {
      "queue":"default"
    }
    
    • 1
    • 2
    • 3

    2.4 Node节点接口

    请求地址:

    GET http://rm-http-address:port/ws/v1/cluster/nodes
    
    • 1

    响应内容:

    {
      "nodes":
      {
        "node":
        [
          {
            "rack":"\/default-rack",
            "state":"RUNNING",
            "id":"host.domain.com:54158",
            "nodeHostName":"host.domain.com",
            "nodeHTTPAddress":"host.domain.com:8042",
            "lastHealthUpdate": 1476995346399,
            "version": "3.0.0-alpha2-SNAPSHOT",
            "healthReport":"",
            "numContainers":0,
            "usedMemoryMB":0,
            "availMemoryMB":8192,
            "usedVirtualCores":0,
            "availableVirtualCores":8,
            "resourceUtilization":
            {
              "nodePhysicalMemoryMB":1027,
              "nodeVirtualMemoryMB":1027,
              "nodeCPUUsage":0.016661113128066063,
              "aggregatedContainersPhysicalMemoryMB":0,
              "aggregatedContainersVirtualMemoryMB":0,
              "containersCPUUsage":0
            }
          },
          {
            "rack":"\/default-rack",
            "state":"RUNNING",
            "id":"host.domain.com:54158",
            "nodeHostName":"host.domain.com",
            "nodeHTTPAddress":"host.domain.com:8042",
            "lastHealthUpdate":1476995346399,
            "version":"3.0.0-alpha2-SNAPSHOT",
            "healthReport":"",
            "numContainers":0,
            "usedMemoryMB":0,
            "availMemoryMB":8192,
            "usedVirtualCores":0,
            "availableVirtualCores":8,
            "resourceUtilization":
            {
              "nodePhysicalMemoryMB":1027,
              "nodeVirtualMemoryMB":1027,
              "nodeCPUUsage":0.016661113128066063,
              "aggregatedContainersPhysicalMemoryMB":0,
              "aggregatedContainersVirtualMemoryMB":0,
              "containersCPUUsage":0
            }
          }
        ]
      }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56

    2.5 其它接口

    还有其它的接口就得自己根据实际项目情况去看了,本文不再赘述。

    03 文末

    本文主要整理了Yarn 相关的 REST API,并举出了一些例子,希望能帮助到大家,谢谢大家的阅读!

  • 相关阅读:
    Day05-Python组合数据类型
    【数据结构】堆的向上调整和向下调整以及相关方法
    【花雕动手做】有趣好玩的音乐可视化系列小项目(20)--首饰盒镜子灯
    [netcore] ASP.NET Core 中间件
    java培训技术-返回JSON
    Java Double equals()方法具有什么功能呢?
    电力电子转战数字IC20220725day56——寄存器模型
    CentOS7 二进制安装 zabbix_agent 5.0
    matplotlib绘制柱状图(普通、堆叠、左右分布)
    后代选择器(非常重要)
  • 原文地址:https://blog.csdn.net/qq_20042935/article/details/126649364