This repository has been archived by the owner on Feb 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 773
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: yeya24 <yb532204897@gmail.com>
- Loading branch information
Showing
11 changed files
with
258 additions
and
33 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,114 @@ | ||
# Monitor Dragonfly with Prometheus | ||
|
||
Currently metrics become an important part of observability. As for monitoring Dragonfly, we recommend you to use Prometheus. | ||
|
||
In Dragonfly project, there are two long-running process: supernode and dfdaemon. Both of these two components expose its metrics via `/metrics` endpoint, so Prometheus can get metrics from these two components. We will also support dfget metrics in the future. As for current metrics, you can check out this docs. | ||
|
||
## How to set up Prometheus | ||
|
||
### Setup Dragonfly Environment | ||
|
||
First, please ensure you know how to setup Dragonfly environment. If you don't, you can check out this [quick_start](https://github.com/dragonflyoss/Dragonfly/blob/master/docs/quick_start/README.md) docs first. Besides, building from source code is ok. | ||
|
||
``` bash | ||
make build | ||
# start supernode and dfdaemon | ||
bin/linux_amd64/supernode --advertise-ip 127.0.0.1 | ||
bin/linux_amd64/dfdaemon | ||
``` | ||
|
||
When supernode and dfdaemon is running normally, you can check metrics through command line. | ||
|
||
check dfdaemon metrics: | ||
|
||
``` bash | ||
➜ ~ curl localhost:65001/metrics | ||
# HELP go_gc_duration_seconds A summary of the GC invocation durations. | ||
# TYPE go_gc_duration_seconds summary | ||
go_gc_duration_seconds{quantile="0"} 0 | ||
go_gc_duration_seconds{quantile="0.25"} 0 | ||
go_gc_duration_seconds{quantile="0.5"} 0 | ||
go_gc_duration_seconds{quantile="0.75"} 0 | ||
go_gc_duration_seconds{quantile="1"} 0 | ||
go_gc_duration_seconds_sum 0 | ||
go_gc_duration_seconds_count 0 | ||
# HELP go_goroutines Number of goroutines that currently exist. | ||
# TYPE go_goroutines gauge | ||
go_goroutines 10 | ||
``` | ||
|
||
check supernode metrics: | ||
|
||
``` bash | ||
➜ ~ curl localhost:8002/metrics | ||
# HELP go_gc_duration_seconds A summary of the GC invocation durations. | ||
# TYPE go_gc_duration_seconds summary | ||
go_gc_duration_seconds{quantile="0"} 2.2854e-05 | ||
go_gc_duration_seconds{quantile="0.25"} 0.000150952 | ||
go_gc_duration_seconds{quantile="0.5"} 0.000155267 | ||
go_gc_duration_seconds{quantile="0.75"} 0.000171251 | ||
go_gc_duration_seconds{quantile="1"} 0.00018524 | ||
go_gc_duration_seconds_sum 0.000685564 | ||
go_gc_duration_seconds_count 5 | ||
# HELP go_goroutines Number of goroutines that currently exist. | ||
# TYPE go_goroutines gauge | ||
go_goroutines 8 | ||
``` | ||
|
||
If you can get the results above, it means your Dragonfly components work well. Next, we will start to setup Prometheus. | ||
|
||
### Download Prometheus | ||
|
||
[Download the release of Prometheus](https://prometheus.io/download/) for your platform, then extract and run it. Here we take Linux version as an example: | ||
|
||
``` bash | ||
wget https://github.com/prometheus/prometheus/releases/download/v2.11.1/prometheus-2.11.1.linux-amd64.tar.gz | ||
tar -xvf prometheus-2.11.1.linux-amd64.tar.gz | ||
cd prometheus-2.11.1.linux-amd64 | ||
``` | ||
|
||
Before starting using Prometheus, we should configure Prometheus first. | ||
|
||
### Configure Prometheus | ||
|
||
Here we provide a minimal-configuration below for monitoring Dragonfly. As for more detailed configuration, you can check [Prometheus Configuration](https://prometheus.io/docs/prometheus/latest/configuration/configuration/) for help. | ||
|
||
``` | ||
global: | ||
scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute. | ||
alerting: | ||
alertmanagers: | ||
- static_configs: | ||
- targets: | ||
# - alertmanager:9093 | ||
rule_files: | ||
# - "first_rules.yml" | ||
# - "second_rules.yml" | ||
scrape_configs: | ||
- job_name: 'dragonfly' | ||
static_configs: | ||
- targets: ['localhost:8002', 'localhost:65001'] | ||
``` | ||
|
||
If you are not familiar with Prometheus, you can modify `prometheus.yml` to this configuration above. Here we don't use any alert rules and alertmanager, so these parts is unset. After modifying this file, you can validate it via `promtool`. | ||
|
||
``` bash | ||
./promtool check config prometheus.yml | ||
Checking prometheus.yml | ||
SUCCESS: 0 rule files found | ||
``` | ||
|
||
Finally you can start Prometheus in the same directory. If Prometheus works well, you can open your browser with localhost:9090 and see Prometheus web ui. | ||
|
||
``` bash | ||
./prometheus | ||
``` | ||
|
||
### Get Dragonfly Metrics Using Prometheus | ||
|
||
In Prometheus web ui, you can search Dragonfly metrics below. If you want to learn more about Prometheus query language, please check [promql](https://prometheus.io/docs/prometheus/latest/querying/basics/) for help. | ||
|
||
![dragonfly_metrics.png](../images/dragonfly_metrics.png) |
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
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,72 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/dragonflyoss/Dragonfly/test/command" | ||
"github.com/dragonflyoss/Dragonfly/test/request" | ||
|
||
"github.com/go-check/check" | ||
) | ||
|
||
// APIMetricsSuite is the test suite for Prometheus metrics. | ||
type APIMetricsSuite struct { | ||
starter *command.Starter | ||
} | ||
|
||
func init() { | ||
check.Suite(&APIMetricsSuite{}) | ||
} | ||
|
||
// SetUpSuite does common setup in the beginning of each test. | ||
func (s *APIMetricsSuite) SetUpSuite(c *check.C) { | ||
s.starter = command.NewStarter("SupernodeMetricsTestSuite") | ||
if _, err := s.starter.Supernode(0); err != nil { | ||
panic(fmt.Sprintf("start supernode failed:%v", err)) | ||
} | ||
} | ||
|
||
func (s *APIMetricsSuite) TearDownSuite(c *check.C) { | ||
s.starter.Clean() | ||
} | ||
|
||
// TestMetrics tests /metrics API. | ||
func (s *APIMetricsSuite) TestMetrics(c *check.C) { | ||
resp, err := request.Get("/metrics") | ||
c.Assert(err, check.IsNil) | ||
defer resp.Body.Close() | ||
|
||
CheckRespStatus(c, resp, 200) | ||
} | ||
|
||
// TestMetricsRequestTotal tests http-related metrics. | ||
func (s *APIMetricsSuite) TestHttpMetrics(c *check.C) { | ||
requestCounter := `dragonfly_supernode_http_requests_total{code="%d",handler="%s",method="%s"}` | ||
responseSizeSum := `dragonfly_supernode_http_response_size_bytes_sum{code="%d",handler="%s",method="%s"}` | ||
responseSizeCount := `dragonfly_supernode_http_response_size_bytes_count{code="%d",handler="%s",method="%s"}` | ||
requestSizeCount := `dragonfly_supernode_http_request_size_bytes_count{code="%d",handler="%s",method="%s"}` | ||
|
||
resp, err := request.Get("/_ping") | ||
c.Assert(err, check.IsNil) | ||
CheckRespStatus(c, resp, 200) | ||
|
||
// Get httpRequest counter value equals 1. | ||
pingTimes, found := GetMetricValue(c, fmt.Sprintf(requestCounter, 200, "/_ping", "get")) | ||
c.Assert(found, check.Equals, true) | ||
c.Assert(pingTimes, check.Equals, float64(1)) | ||
|
||
// Get httpResponse size sum value equals 2. | ||
responseBytes, found := GetMetricValue(c, fmt.Sprintf(responseSizeSum, 200, "/_ping", "get")) | ||
c.Assert(found, check.Equals, true) | ||
c.Assert(responseBytes, check.Equals, float64(2)) | ||
|
||
// Get httpResponse size count value equals 1. | ||
responseCount, found := GetMetricValue(c, fmt.Sprintf(responseSizeCount, 200, "/_ping", "get")) | ||
c.Assert(found, check.Equals, true) | ||
c.Assert(responseCount, check.Equals, float64(1)) | ||
|
||
// Get httpRequest size count value equals 1. | ||
requestCount, found := GetMetricValue(c, fmt.Sprintf(requestSizeCount, 200, "/_ping", "get")) | ||
c.Assert(found, check.Equals, true) | ||
c.Assert(requestCount, check.Equals, float64(1)) | ||
} |
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.