1   /*
2    * Copyright 2017 LINE Corporation
3    *
4    * LINE Corporation licenses this file to you under the Apache License,
5    * version 2.0 (the "License"); you may not use this file except in compliance
6    * with the License. You may obtain a copy of the License at:
7    *
8    *   https://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, WITHOUT
12   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13   * License for the specific language governing permissions and limitations
14   * under the License.
15   */
16  package com.linecorp.centraldogma.server;
17  
18  import java.io.IOException;
19  
20  import com.fasterxml.jackson.core.JsonGenerator;
21  import com.fasterxml.jackson.databind.SerializerProvider;
22  import com.fasterxml.jackson.databind.ser.std.StdSerializer;
23  import com.github.benmanes.caffeine.cache.stats.CacheStats;
24  
25  final class CacheStatsSerializer extends StdSerializer<CacheStats> {
26  
27      private static final long serialVersionUID = 4356076669993625289L;
28  
29      CacheStatsSerializer() {
30          super(CacheStats.class);
31      }
32  
33      @Override
34      public void serialize(CacheStats value, JsonGenerator gen, SerializerProvider provider) throws IOException {
35          gen.writeStartObject();
36          gen.writeNumberField("requestCount", value.requestCount());
37          gen.writeNumberField("hitCount", value.hitCount());
38          gen.writeNumberField("hitRate", value.hitRate());
39          gen.writeNumberField("missCount", value.missCount());
40          gen.writeNumberField("missRate", value.missRate());
41          gen.writeNumberField("loadCount", value.loadCount());
42          gen.writeNumberField("loadSuccessCount", value.loadSuccessCount());
43          gen.writeNumberField("loadFailureCount", value.loadFailureCount());
44          gen.writeNumberField("loadFailureRate", value.loadFailureRate());
45          gen.writeNumberField("totalLoadTime", value.totalLoadTime());
46          gen.writeNumberField("averageLoadPenalty", value.averageLoadPenalty());
47          gen.writeNumberField("evictionCount", value.evictionCount());
48          gen.writeNumberField("evictionWeight", value.evictionWeight());
49          gen.writeEndObject();
50      }
51  }