Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
telegraf-nftables
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Due to inactivity, this project is scheduled to be deleted on 2035-04-24.
Why is this scheduled?
Show more breadcrumbs
vqgroup
telegraf-nftables
Commits
1c73caba
Commit
1c73caba
authored
7 years ago
by
Bob Shannon
Committed by
Daniel Nelson
7 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Add SSL/TLS support to nginx input plugin (#2883)
parent
84dbf8bb
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
CHANGELOG.md
+1
-0
1 addition, 0 deletions
CHANGELOG.md
plugins/inputs/nginx/README.md
+10
-0
10 additions, 0 deletions
plugins/inputs/nginx/README.md
plugins/inputs/nginx/nginx.go
+54
-9
54 additions, 9 deletions
plugins/inputs/nginx/nginx.go
with
65 additions
and
9 deletions
CHANGELOG.md
+
1
−
0
View file @
1c73caba
...
@@ -6,6 +6,7 @@
...
@@ -6,6 +6,7 @@
-
[
#2773
](
https://github.com/influxdata/telegraf/pull/2773
)
: Add support for self-signed certs to InfluxDB input plugin
-
[
#2773
](
https://github.com/influxdata/telegraf/pull/2773
)
: Add support for self-signed certs to InfluxDB input plugin
-
[
#2581
](
https://github.com/influxdata/telegraf/pull/2581
)
: Add Docker container environment variables as tags. Only whitelisted
-
[
#2581
](
https://github.com/influxdata/telegraf/pull/2581
)
: Add Docker container environment variables as tags. Only whitelisted
-
[
#2817
](
https://github.com/influxdata/telegraf/pull/2817
)
: Added timeout option to IPMI sensor plugin
-
[
#2817
](
https://github.com/influxdata/telegraf/pull/2817
)
: Added timeout option to IPMI sensor plugin
-
[
#2883
](
https://github.com/influxdata/telegraf/pull/2883
)
: Add support for an optional SSL/TLS configuration to nginx input plugin
-
[
#2882
](
https://github.com/influxdata/telegraf/pull/2882
)
: Add timezone support for logparser timestamps.
-
[
#2882
](
https://github.com/influxdata/telegraf/pull/2882
)
: Add timezone support for logparser timestamps.
-
[
#2814
](
https://github.com/influxdata/telegraf/pull/2814
)
: Add result_type field for http_response input.
-
[
#2814
](
https://github.com/influxdata/telegraf/pull/2814
)
: Add result_type field for http_response input.
...
...
This diff is collapsed.
Click to expand it.
plugins/inputs/nginx/README.md
+
10
−
0
View file @
1c73caba
...
@@ -7,6 +7,16 @@
...
@@ -7,6 +7,16 @@
[[inputs.nginx]]
[[inputs.nginx]]
## An array of Nginx stub_status URI to gather stats.
## An array of Nginx stub_status URI to gather stats.
urls = ["http://localhost/server_status"]
urls = ["http://localhost/server_status"]
## Optional SSL Config
# ssl_ca = "/etc/telegraf/ca.pem"
# ssl_cert = "/etc/telegraf/cert.pem"
# ssl_key = "/etc/telegraf/key.pem"
## Use SSL but skip chain & host verification
# insecure_skip_verify = false
## HTTP response timeout (default: 5s)
response_timeout = "5s"
```
```
### Measurements & Fields:
### Measurements & Fields:
...
...
This diff is collapsed.
Click to expand it.
plugins/inputs/nginx/nginx.go
+
54
−
9
View file @
1c73caba
...
@@ -12,16 +12,39 @@ import (
...
@@ -12,16 +12,39 @@ import (
"time"
"time"
"github.com/influxdata/telegraf"
"github.com/influxdata/telegraf"
"github.com/influxdata/telegraf/internal"
"github.com/influxdata/telegraf/plugins/inputs"
"github.com/influxdata/telegraf/plugins/inputs"
)
)
type
Nginx
struct
{
type
Nginx
struct
{
// List of status URLs
Urls
[]
string
Urls
[]
string
// Path to CA file
SSLCA
string
`toml:"ssl_ca"`
// Path to client cert file
SSLCert
string
`toml:"ssl_cert"`
// Path to cert key file
SSLKey
string
`toml:"ssl_key"`
// Use SSL but skip chain & host verification
InsecureSkipVerify
bool
// HTTP client
client
*
http
.
Client
// Response timeout
ResponseTimeout
internal
.
Duration
}
}
var
sampleConfig
=
`
var
sampleConfig
=
`
## An array of Nginx stub_status URI to gather stats.
# An array of Nginx stub_status URI to gather stats.
urls = ["http://localhost/status"]
urls = ["http://localhost/server_status"]
# TLS/SSL configuration
ssl_ca = "/etc/telegraf/ca.pem"
ssl_cert = "/etc/telegraf/cert.cer"
ssl_key = "/etc/telegraf/key.key"
insecure_skip_verify = false
# HTTP response timeout (default: 5s)
response_timeout = "5s"
`
`
func
(
n
*
Nginx
)
SampleConfig
()
string
{
func
(
n
*
Nginx
)
SampleConfig
()
string
{
...
@@ -35,6 +58,16 @@ func (n *Nginx) Description() string {
...
@@ -35,6 +58,16 @@ func (n *Nginx) Description() string {
func
(
n
*
Nginx
)
Gather
(
acc
telegraf
.
Accumulator
)
error
{
func
(
n
*
Nginx
)
Gather
(
acc
telegraf
.
Accumulator
)
error
{
var
wg
sync
.
WaitGroup
var
wg
sync
.
WaitGroup
// Create an HTTP client that is re-used for each
// collection interval
if
n
.
client
==
nil
{
client
,
err
:=
n
.
createHttpClient
()
if
err
!=
nil
{
return
err
}
n
.
client
=
client
}
for
_
,
u
:=
range
n
.
Urls
{
for
_
,
u
:=
range
n
.
Urls
{
addr
,
err
:=
url
.
Parse
(
u
)
addr
,
err
:=
url
.
Parse
(
u
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -52,17 +85,29 @@ func (n *Nginx) Gather(acc telegraf.Accumulator) error {
...
@@ -52,17 +85,29 @@ func (n *Nginx) Gather(acc telegraf.Accumulator) error {
return
nil
return
nil
}
}
var
tr
=
&
http
.
Transport
{
func
(
n
*
Nginx
)
createHttpClient
()
(
*
http
.
Client
,
error
)
{
ResponseHeaderTimeout
:
time
.
Duration
(
3
*
time
.
Second
),
tlsCfg
,
err
:=
internal
.
GetTLSConfig
(
}
n
.
SSLCert
,
n
.
SSLKey
,
n
.
SSLCA
,
n
.
InsecureSkipVerify
)
if
err
!=
nil
{
return
nil
,
err
}
if
n
.
ResponseTimeout
.
Duration
<
time
.
Second
{
n
.
ResponseTimeout
.
Duration
=
time
.
Second
*
5
}
client
:=
&
http
.
Client
{
Transport
:
&
http
.
Transport
{
TLSClientConfig
:
tlsCfg
,
},
Timeout
:
n
.
ResponseTimeout
.
Duration
,
}
var
client
=
&
http
.
Client
{
return
client
,
nil
Transport
:
tr
,
Timeout
:
time
.
Duration
(
4
*
time
.
Second
),
}
}
func
(
n
*
Nginx
)
gatherUrl
(
addr
*
url
.
URL
,
acc
telegraf
.
Accumulator
)
error
{
func
(
n
*
Nginx
)
gatherUrl
(
addr
*
url
.
URL
,
acc
telegraf
.
Accumulator
)
error
{
resp
,
err
:=
client
.
Get
(
addr
.
String
())
resp
,
err
:=
n
.
client
.
Get
(
addr
.
String
())
if
err
!=
nil
{
if
err
!=
nil
{
return
fmt
.
Errorf
(
"error making HTTP request to %s: %s"
,
addr
.
String
(),
err
)
return
fmt
.
Errorf
(
"error making HTTP request to %s: %s"
,
addr
.
String
(),
err
)
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment