View Javadoc
1   /*
2    * Copyright 2021 TiKV Project Authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   *
16   */
17  
18  package org.tikv.service.failsafe;
19  
20  public class HealthCounts {
21    private final long totalCount;
22    private final long errorCount;
23    private final int errorPercentage;
24  
25    HealthCounts(long total, long error) {
26      this.totalCount = total;
27      this.errorCount = error;
28      if (totalCount > 0) {
29        this.errorPercentage = (int) ((double) errorCount / totalCount * 100);
30      } else {
31        this.errorPercentage = 0;
32      }
33    }
34  
35    public long getTotalRequests() {
36      return totalCount;
37    }
38  
39    public long getErrorCount() {
40      return errorCount;
41    }
42  
43    public int getErrorPercentage() {
44      return errorPercentage;
45    }
46  
47    @Override
48    public String toString() {
49      return "HealthCounts{"
50          + "totalCount="
51          + totalCount
52          + ", errorCount="
53          + errorCount
54          + ", errorPercentage="
55          + errorPercentage
56          + '}';
57    }
58  }