-
Notifications
You must be signed in to change notification settings - Fork 305
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add a prometheus /metrics endpoint. (#517)
* chore: Update jicoco. * feat: Port some metrics to prometheus. * chore: Bump jetty. * feat: Add a /metrics endpoint for prometheus. * feat: Port most stats to metrics.
- Loading branch information
Showing
5 changed files
with
237 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
src/main/java/org/jitsi/jigasi/metrics/JigasiMetricsContainer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Jigasi, the JItsi GAteway to SIP. | ||
* | ||
* Copyright @ 2024 - present 8x8, Inc | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.jitsi.jigasi.metrics; | ||
|
||
import io.prometheus.client.*; | ||
import org.jitsi.metrics.*; | ||
|
||
public class JigasiMetricsContainer extends MetricsContainer | ||
{ | ||
public final static JigasiMetricsContainer INSTANCE = new JigasiMetricsContainer(); | ||
|
||
private JigasiMetricsContainer() | ||
{ | ||
super(CollectorRegistry.defaultRegistry, "jitsi_jigasi"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Copyright @ 2024 - present, 8x8 Inc | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.jitsi.jigasi.rest; | ||
|
||
import io.prometheus.client.exporter.common.*; | ||
import jakarta.servlet.*; | ||
import jakarta.servlet.http.*; | ||
import org.eclipse.jetty.server.*; | ||
import org.eclipse.jetty.server.handler.*; | ||
import org.jitsi.jigasi.metrics.*; | ||
import org.jitsi.jigasi.stats.*; | ||
|
||
import java.io.*; | ||
|
||
public class MetricsHandler extends AbstractHandler | ||
{ | ||
@Override | ||
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) | ||
throws IOException, ServletException | ||
{ | ||
if ("/metrics".equals(target)) | ||
{ | ||
String accept = request.getHeader("Accept"); | ||
|
||
Statistics.updateMetrics(); | ||
|
||
String responseBody; | ||
if (accept != null && accept.startsWith("application/openmetrics-text")) | ||
{ | ||
responseBody = JigasiMetricsContainer.INSTANCE.getPrometheusMetrics( | ||
TextFormat.CONTENT_TYPE_OPENMETRICS_100); | ||
response.setContentType(TextFormat.CONTENT_TYPE_OPENMETRICS_100); | ||
} | ||
else if (accept != null && accept.startsWith("text/plain")) | ||
{ | ||
responseBody = JigasiMetricsContainer.INSTANCE.getPrometheusMetrics(TextFormat.CONTENT_TYPE_004); | ||
response.setContentType(TextFormat.CONTENT_TYPE_004); | ||
} | ||
else | ||
{ | ||
responseBody = JigasiMetricsContainer.INSTANCE.getJsonString(); | ||
response.setContentType(RESTUtil.JSON_CONTENT_TYPE_WITH_CHARSET); | ||
} | ||
|
||
Writer writer = response.getWriter(); | ||
writer.write(responseBody); | ||
response.setStatus(200); | ||
} | ||
} | ||
} |
Oops, something went wrong.