-
Notifications
You must be signed in to change notification settings - Fork 492
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[feat] add prometheus support for proxy & httpserver. (#877)
* [feat] add prometheus support for proxy & httpserver. * fix pr comments. * sorted imports * fix deadlock * change lock from pointer to vale * add default buckets for histogram metrics
- Loading branch information
Showing
14 changed files
with
565 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# Prometheus | ||
|
||
- [Prometheus](#prometheus) | ||
- [Exporter URI](#exporter-uri) | ||
- [Metrics](#metrics) | ||
- [Objects](#objects) | ||
- [HTTPServer](#httpserver) | ||
- [Filters](#filters) | ||
- [Proxy](#proxy) | ||
- [Create Metrics for Extended Objects and Filters](#create-metrics-for-extended-objects-and-filters) | ||
|
||
Easegress has a builtin Prometheus exporter. | ||
|
||
## Exporter URI | ||
|
||
``` | ||
Get /apis/v2/metrics | ||
``` | ||
|
||
## Metrics | ||
|
||
### Objects | ||
|
||
#### HTTPServer | ||
|
||
| Metric | Type | Description | Labels | | ||
|---------------------------------|-----------|--------------------------------------------------------------|-------------------------------------------------------------------------| | ||
| httpserver_health | gauge | show the status for the http server: 1 for ready, 0 for down | clusterName, clusterRole, instanceName, name, kind | | ||
| httpserver_total_requests | counter | the total count of http requests | clusterName, clusterRole, instanceName, name, kind, routerKind, backend | | ||
| httpserver_total_responses | counter | the total count of http resposnes | clusterName, clusterRole, instanceName, name, kind, routerKind, backend | | ||
| httpserver_total_error_requests | counter | the total count of http error requests | clusterName, clusterRole, instanceName, name, kind, routerKind, backend | | ||
| httpserver_requests_duration | histogram | request processing duration histogram | clusterName, clusterRole, instanceName, name, kind, routerKind, backend | | ||
| httpserver_requests_size_bytes | histogram | a histogram of the total size of the request. Includes body | clusterName, clusterRole, instanceName, name, kind, routerKind, backend | | ||
| httpserver_responses_size_bytes | histogram | a histogram of the total size of the returned responses body | clusterName, clusterRole, instanceName, name, kind, routerKind, backend | | ||
|
||
### Filters | ||
|
||
#### Proxy | ||
|
||
| Metric | Type | Description | Labels | | ||
|-------------------------------|-----------|-----------------------------------------------|-------------------------------------------------------------------------------------| | ||
| proxy_total_connections | counter | the total count of proxy connections | clusterName, clusterRole, instanceName, name, kind, loadBalancePolicy, filterPolicy | | ||
| proxy_total_error_connections | counter | the total count of proxy error connections | clusterName, clusterRole, instanceName, name, kind, loadBalancePolicy, filterPolicy | | ||
| proxy_request_body_size | histogram | a histogram of the total size of the request | clusterName, clusterRole, instanceName, name, kind, loadBalancePolicy, filterPolicy | | ||
| proxy_response_body_size | histogram | a histogram of the total size of the response | clusterName, clusterRole, instanceName, name, kind, loadBalancePolicy, filterPolicy | | ||
|
||
## Create Metrics for Extended Objects and Filters | ||
|
||
We provide several helper functions to help you create Prometheus metrics | ||
when develop your own Objects and Filters. | ||
|
||
* `prometheushelper.NewCounter` | ||
* `prometheushelper.NewGauge` | ||
* `prometheushelper.NewHistogram` | ||
* `prometheushelper.NewSummary` | ||
|
||
These metrics will be registered to `DefaultRegisterer` automatically. | ||
|
||
Besides, you can use native Prometheus SDK to create metrics and register them | ||
by yourself. |
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
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,37 @@ | ||
/* | ||
* Copyright (c) 2017, MegaEase | ||
* All rights reserved. | ||
* | ||
* 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:https://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 api | ||
|
||
import ( | ||
"github.com/prometheus/client_golang/prometheus/promhttp" | ||
) | ||
|
||
const ( | ||
// PrometheusMetricsPrefix is the prefix of Prometheus metrics exporter | ||
PrometheusMetricsPrefix = "/metrics" | ||
) | ||
|
||
func (s *Server) prometheusMetricsAPIEntries() []*Entry { | ||
return []*Entry{ | ||
{ | ||
Path: PrometheusMetricsPrefix, | ||
Method: "GET", | ||
Handler: promhttp.Handler().ServeHTTP, | ||
}, | ||
} | ||
} |
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
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
Oops, something went wrong.