001/**
002 * Copyright (c) 2015-2022, Michael Yang 杨福海 (fuhai999@gmail.com).
003 * <p>
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 * <p>
008 * http://www.apache.org/licenses/LICENSE-2.0
009 * <p>
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package io.jboot.support.metric.request;
017
018import java.util.HashMap;
019import java.util.Map;
020
021
022public class JbootRequestMetricHandler extends AbstractInstrumentedFilter {
023
024    private static final String NAME_PREFIX = "responseCodes.";
025    private static final int OK = 200;
026    private static final int CREATED = 201;
027    private static final int NO_CONTENT = 204;
028    private static final int BAD_REQUEST = 400;
029    private static final int NOT_FOUND = 404;
030    private static final int SERVER_ERROR = 500;
031
032    /**
033     * Creates a new instance of the request filter.
034     */
035    public JbootRequestMetricHandler() {
036        super(createMeterNamesByStatusCode(), NAME_PREFIX + "other");
037    }
038
039    private static Map<Integer, String> createMeterNamesByStatusCode() {
040        final Map<Integer, String> meterNamesByStatusCode = new HashMap<>(6);
041        meterNamesByStatusCode.put(OK, NAME_PREFIX + "ok");
042        meterNamesByStatusCode.put(CREATED, NAME_PREFIX + "created");
043        meterNamesByStatusCode.put(NO_CONTENT, NAME_PREFIX + "noContent");
044        meterNamesByStatusCode.put(BAD_REQUEST, NAME_PREFIX + "badRequest");
045        meterNamesByStatusCode.put(NOT_FOUND, NAME_PREFIX + "notFound");
046        meterNamesByStatusCode.put(SERVER_ERROR, NAME_PREFIX + "serverError");
047        return meterNamesByStatusCode;
048    }
049}