diff --git a/src/fr/devinsy/statoolinfos/metrics/http/HttpAccessLog.java b/src/fr/devinsy/statoolinfos/metrics/http/HttpAccessLog.java index 1784ea5..ab3ee16 100644 --- a/src/fr/devinsy/statoolinfos/metrics/http/HttpAccessLog.java +++ b/src/fr/devinsy/statoolinfos/metrics/http/HttpAccessLog.java @@ -82,6 +82,36 @@ public class HttpAccessLog return this.ip; } + /** + * Gets the method. + * + * @return the method + */ + public HttpMethod getMethod() + { + HttpMethod result; + + if (this.request == null) + { + result = HttpMethod.UNKNOWN; + } + else + { + int space = this.request.indexOf(' '); + if (space == -1) + { + result = HttpMethod.UNKNOWN; + } + else + { + result = HttpMethod.of(this.request.substring(0, space)); + } + } + + // + return result; + } + public String getReferer() { return this.referer; diff --git a/src/fr/devinsy/statoolinfos/metrics/http/HttpAccessLogAnalyzer.java b/src/fr/devinsy/statoolinfos/metrics/http/HttpAccessLogAnalyzer.java index 9beeef5..164ffb6 100644 --- a/src/fr/devinsy/statoolinfos/metrics/http/HttpAccessLogAnalyzer.java +++ b/src/fr/devinsy/statoolinfos/metrics/http/HttpAccessLogAnalyzer.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2021 Christian Pierre MOMON + * Copyright (C) 2020-2022 Christian Pierre MOMON * * This file is part of StatoolInfos, simple service statistics tool. * @@ -344,6 +344,10 @@ public class HttpAccessLogAnalyzer } } + // metrics.http.methods.XXXX + String method = log.getMethod().toString(); + this.counters.inc("metrics.http.methods." + method, year, yearMonth, yearWeek, date); + // metrics.http.status.XXXX String status = String.valueOf(log.getStatus().getCode()); this.counters.inc("metrics.http.status." + status, year, yearMonth, yearWeek, date); diff --git a/src/fr/devinsy/statoolinfos/metrics/http/HttpMethod.java b/src/fr/devinsy/statoolinfos/metrics/http/HttpMethod.java new file mode 100644 index 0000000..f43b40a --- /dev/null +++ b/src/fr/devinsy/statoolinfos/metrics/http/HttpMethod.java @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2022 Christian Pierre MOMON + * + * This file is part of StatoolInfos, simple service statistics tool. + * + * StatoolInfos is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * StatoolInfos is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with StatoolInfos. If not, see . + */ +package fr.devinsy.statoolinfos.metrics.http; + +/** + * The Class HttpMethod. + */ +public enum HttpMethod +{ + GET, + HEAD, + POST, + OPTIONS, + CONNECT, + TRACE, + PUT, + PATCH, + DELETE, + UNKNOWN; + + /** + * Parses the. + * + * @param value + * the value + * @return the http method + */ + public static HttpMethod of(final String value) + { + HttpMethod result; + + if (value == null) + { + result = null; + } + else + { + try + { + result = valueOf(value); + } + catch (IllegalArgumentException exception) + { + result = UNKNOWN; + } + } + + // + return result; + } +} \ No newline at end of file