forked from open-telemetry/opentelemetry-collector-contrib
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[receiver/haproxyreceiver] add HAProxy receiver (open-telemetry#16842)
* [receiver/haproxyreceiver] add HAProxy receiver * don't expose CreateDefaultConfig * code review * remove component from configschema requirements * undo unintented rename * fix file uri * tidy * Update receiver/haproxyreceiver/README.md Co-authored-by: Evan Bradley <[email protected]> Co-authored-by: Evan Bradley <[email protected]>
- Loading branch information
1 parent
d303152
commit 2b56579
Showing
23 changed files
with
1,596 additions
and
0 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,16 @@ | ||
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' | ||
change_type: new_component | ||
|
||
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) | ||
component: haproxyreceiver | ||
|
||
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). | ||
note: A receiver scraping metrics from the HAProxy stats command. | ||
|
||
# One or more tracking issues related to the change | ||
issues: [16829] | ||
|
||
# (Optional) One or more lines of additional information to render under the primary note. | ||
# These lines will be padded with 2 spaces and then inserted directly into the document. | ||
# Use pipe (|) for multiline entries. | ||
subtext: |
Validating CODEOWNERS rules …
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
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 @@ | ||
include ../../Makefile.Common |
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,55 @@ | ||
# HAProxy Receiver | ||
|
||
| Status | | | ||
| ------------------------ |---------------| | ||
| Stability | [development] | | ||
| Supported pipeline types | metrics | | ||
| Distributions | [contrib] | | ||
|
||
The HAProxy receiver generates metrics by polling periodically the HAProxy process through a dedicated socket or HTTP URL. | ||
|
||
Supported pipeline types: metrics | ||
|
||
## Getting Started | ||
|
||
## Configuration | ||
|
||
### endpoint (required) | ||
Path to the endpoint exposed by HAProxy for communications. It can be a local file socket or a HTTP URL. | ||
|
||
### Collection interval settings (optional) | ||
The scraping collection interval can be configured. | ||
|
||
Default: 1 minute | ||
|
||
### Example configuration | ||
|
||
```yaml | ||
haproxy: | ||
endpoint: file:https:///var/run/haproxy.ipc | ||
collection_interval: 1m | ||
metrics: | ||
|
||
``` | ||
|
||
## Enabling metrics. | ||
|
||
See [documentation.md](./documentation.md). | ||
|
||
You can enable or disable selective metrics. | ||
|
||
Example: | ||
|
||
```yaml | ||
receivers: | ||
haproxy: | ||
endpoint: http:https://127.0.0.1:8080/stats | ||
metrics: | ||
haproxy.connection_rate: | ||
enabled: false | ||
haproxy.requests: | ||
enabled: true | ||
``` | ||
|
||
[development]: https://github.com/open-telemetry/opentelemetry-collector#development | ||
|
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,39 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// | ||
// 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 haproxyreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/haproxyreceiver" | ||
|
||
import ( | ||
"errors" | ||
|
||
"go.opentelemetry.io/collector/config" | ||
"go.opentelemetry.io/collector/config/confighttp" | ||
"go.opentelemetry.io/collector/receiver/scraperhelper" | ||
|
||
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/haproxyreceiver/internal/metadata" | ||
) | ||
|
||
type Config struct { | ||
config.ReceiverSettings `mapstructure:",squash"` | ||
confighttp.HTTPClientSettings `mapstructure:",squash"` | ||
scraperhelper.ScraperControllerSettings `mapstructure:",squash"` | ||
MetricsSettings metadata.MetricsSettings `mapstructure:"metrics"` | ||
} | ||
|
||
func (c Config) Validate() error { | ||
if c.HTTPClientSettings.Endpoint == "" { | ||
return errors.New("'endpoint' cannot be empty") | ||
} | ||
return nil | ||
} |
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,18 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// | ||
// 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. | ||
|
||
//go:generate mdatagen metadata.yaml | ||
|
||
// Package haproxyreceiver implements a receiver collecting metrics from HAProxy. | ||
package haproxyreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/haproxyreceiver" |
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,59 @@ | ||
[comment]: <> (Code generated by mdatagen. DO NOT EDIT.) | ||
|
||
# haproxyreceiver | ||
|
||
## Default Metrics | ||
|
||
The following metrics are emitted by default. Each of them can be disabled by applying the following configuration: | ||
|
||
```yaml | ||
metrics: | ||
<metric_name>: | ||
enabled: false | ||
``` | ||
|
||
### haproxy.connection_rate | ||
|
||
Number of connections over the last elapsed second (frontend). Corresponds to HAProxy's `conn_rate` metric. | ||
|
||
| Unit | Metric Type | Value Type | | ||
| ---- | ----------- | ---------- | | ||
| {connections} | Gauge | Int | | ||
|
||
### haproxy.idle_percent | ||
|
||
Ratio of system polling time versus total time. Corresponds to HAProxy's `I`dle_pct` metric. | ||
|
||
| Unit | Metric Type | Value Type | | ||
| ---- | ----------- | ---------- | | ||
| {percent} | Gauge | Double | | ||
|
||
### haproxy.requests | ||
|
||
Total number of requests on this worker process since started. Corresponds to HAProxy's `CumReq` metric. | ||
|
||
| Unit | Metric Type | Value Type | Aggregation Temporality | Monotonic | | ||
| ---- | ----------- | ---------- | ----------------------- | --------- | | ||
| {requests} | Sum | Int | Cumulative | true | | ||
|
||
### haproxy.sessions.count | ||
|
||
Current sessions. Corresponds to HAProxy's `scur` metric. | ||
|
||
| Unit | Metric Type | Value Type | | ||
| ---- | ----------- | ---------- | | ||
| {sessions} | Gauge | Int | | ||
|
||
## Resource Attributes | ||
|
||
| Name | Description | Values | | ||
| ---- | ----------- | ------ | | ||
| haproxy.addr | address:port or "unix". IPv6 has brackets around the address. | Any Str | | ||
| haproxy.algo | load balancing algorithm | Any Str | | ||
| haproxy.iid | unique proxy id | Any Str | | ||
| haproxy.pid | process id (0 for first instance, 1 for second, ...) | Any Str | | ||
| haproxy.proxy_name | Proxy name | Any Str | | ||
| haproxy.service_name | Service name (FRONTEND for frontend, BACKEND for backend, any name for server/listener) | Any Str | | ||
| haproxy.sid | server id (unique inside a proxy) | Any Str | | ||
| haproxy.type | (0=frontend, 1=backend, 2=server, 3=socket/listener) | Any Str | | ||
| haproxy.url | The path to the HAProxy socket or HTTP URL. | Any Str | |
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,79 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// | ||
// 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 haproxyreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/haproxyreceiver" | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
"go.opentelemetry.io/collector/component" | ||
"go.opentelemetry.io/collector/config" | ||
"go.opentelemetry.io/collector/consumer" | ||
"go.opentelemetry.io/collector/receiver" | ||
"go.opentelemetry.io/collector/receiver/scraperhelper" | ||
|
||
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/haproxyreceiver/internal/metadata" | ||
) | ||
|
||
const ( | ||
typeStr = "haproxy" | ||
stability = component.StabilityLevelDevelopment | ||
) | ||
|
||
// NewFactory creates a new HAProxy receiver factory. | ||
func NewFactory() receiver.Factory { | ||
return receiver.NewFactory( | ||
typeStr, | ||
newDefaultConfig, | ||
receiver.WithMetrics(newReceiver, stability)) | ||
} | ||
|
||
func newDefaultConfig() component.Config { | ||
return &Config{ | ||
ReceiverSettings: config.NewReceiverSettings(component.NewID(typeStr)), | ||
ScraperControllerSettings: scraperhelper.ScraperControllerSettings{ | ||
ReceiverSettings: config.NewReceiverSettings(component.NewID(typeStr)), | ||
CollectionInterval: 1 * time.Minute, | ||
}, | ||
MetricsSettings: metadata.DefaultMetricsSettings(), | ||
} | ||
} | ||
|
||
func newReceiver( | ||
_ context.Context, | ||
settings receiver.CreateSettings, | ||
cfg component.Config, | ||
consumer consumer.Metrics, | ||
) (receiver.Metrics, error) { | ||
haProxyCfg := cfg.(*Config) | ||
metricsBuilder := metadata.NewMetricsBuilder(haProxyCfg.MetricsSettings, settings) | ||
|
||
mp, err := newScraper(settings.ID, metricsBuilder, haProxyCfg, settings.TelemetrySettings.Logger) | ||
if err != nil { | ||
return nil, err | ||
} | ||
s, err := scraperhelper.NewScraper(settings.ID.Name(), mp.Scrape) | ||
if err != nil { | ||
return nil, err | ||
} | ||
opt := scraperhelper.AddScraper(s) | ||
|
||
return scraperhelper.NewScraperControllerReceiver( | ||
&haProxyCfg.ScraperControllerSettings, | ||
settings, | ||
consumer, | ||
opt, | ||
) | ||
} |
Oops, something went wrong.