|
| 1 | +/** |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, software |
| 13 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | + * See the License for the specific language governing permissions and |
| 16 | + * limitations under the License. |
| 17 | + */ |
| 18 | + |
| 19 | +package org.apache.hadoop.yarn.server.resourcemanager.scheduler; |
| 20 | + |
| 21 | +import org.apache.hadoop.conf.Configuration; |
| 22 | +import org.apache.hadoop.metrics2.MetricsSystem; |
| 23 | +import org.apache.hadoop.metrics2.annotation.Metrics; |
| 24 | +import org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CSQueue; |
| 25 | + |
| 26 | +@Metrics(context = "yarn") |
| 27 | +public class PartitionQueueMetrics extends QueueMetrics { |
| 28 | + |
| 29 | + private String partition; |
| 30 | + |
| 31 | + protected PartitionQueueMetrics(MetricsSystem ms, String queueName, |
| 32 | + Queue parent, boolean enableUserMetrics, Configuration conf, |
| 33 | + String partition) { |
| 34 | + super(ms, queueName, parent, enableUserMetrics, conf); |
| 35 | + this.partition = partition; |
| 36 | + if (getParentQueue() != null) { |
| 37 | + String newQueueName = (getParentQueue() instanceof CSQueue) |
| 38 | + ? ((CSQueue) getParentQueue()).getQueuePath() |
| 39 | + : getParentQueue().getQueueName(); |
| 40 | + String parentMetricName = |
| 41 | + partition + METRIC_NAME_DELIMITER + newQueueName; |
| 42 | + setParent(getQueueMetrics().get(parentMetricName)); |
| 43 | + } |
| 44 | + } |
| 45 | + |
| 46 | + /** |
| 47 | + * Partition * Queue * User Metrics |
| 48 | + * |
| 49 | + * Computes Metrics at Partition (Node Label) * Queue * User Level. |
| 50 | + * |
| 51 | + * Sample JMX O/P Structure: |
| 52 | + * |
| 53 | + * PartitionQueueMetrics (labelX) |
| 54 | + * QueueMetrics (A) |
| 55 | + * usermetrics |
| 56 | + * QueueMetrics (A1) |
| 57 | + * usermetrics |
| 58 | + * QueueMetrics (A2) |
| 59 | + * usermetrics |
| 60 | + * QueueMetrics (B) |
| 61 | + * usermetrics |
| 62 | + * |
| 63 | + * @return QueueMetrics |
| 64 | + */ |
| 65 | + @Override |
| 66 | + public synchronized QueueMetrics getUserMetrics(String userName) { |
| 67 | + if (users == null) { |
| 68 | + return null; |
| 69 | + } |
| 70 | + |
| 71 | + String partitionJMXStr = |
| 72 | + (partition.equals(DEFAULT_PARTITION)) ? DEFAULT_PARTITION_JMX_STR |
| 73 | + : partition; |
| 74 | + |
| 75 | + QueueMetrics metrics = (PartitionQueueMetrics) users.get(userName); |
| 76 | + if (metrics == null) { |
| 77 | + metrics = new PartitionQueueMetrics(this.metricsSystem, this.queueName, |
| 78 | + null, false, this.conf, this.partition); |
| 79 | + users.put(userName, metrics); |
| 80 | + metricsSystem.register( |
| 81 | + pSourceName(partitionJMXStr).append(qSourceName(queueName)) |
| 82 | + .append(",user=").append(userName).toString(), |
| 83 | + "Metrics for user '" + userName + "' in queue '" + queueName + "'", |
| 84 | + ((PartitionQueueMetrics) metrics.tag(PARTITION_INFO, partitionJMXStr) |
| 85 | + .tag(QUEUE_INFO, queueName)).tag(USER_INFO, userName)); |
| 86 | + } |
| 87 | + return metrics; |
| 88 | + } |
| 89 | +} |
0 commit comments