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
6efe91ea
Commit
6efe91ea
authored
8 years ago
by
Cameron Sparr
Browse files
Options
Downloads
Patches
Plain Diff
prometheus_client, implement Collector interface
closes #1334
parent
5f0a63f5
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
CHANGELOG.md
+1
-0
1 addition, 0 deletions
CHANGELOG.md
plugins/outputs/prometheus_client/prometheus_client.go
+37
-33
37 additions, 33 deletions
plugins/outputs/prometheus_client/prometheus_client.go
with
38 additions
and
33 deletions
CHANGELOG.md
+
1
−
0
View file @
6efe91ea
...
...
@@ -44,6 +44,7 @@ should now look like:
-
[
#1378
](
https://github.com/influxdata/telegraf/issues/1378
)
: Trim BOM from config file for Windows support.
-
[
#1339
](
https://github.com/influxdata/telegraf/issues/1339
)
: Prometheus client output panic on service reload.
-
[
#1461
](
https://github.com/influxdata/telegraf/pull/1461
)
: Prometheus parser, protobuf format header fix.
-
[
#1334
](
https://github.com/influxdata/telegraf/issues/1334
)
: Prometheus output, metric refresh and caching fixes.
## v1.0 beta 2 [2016-06-21]
...
...
This diff is collapsed.
Click to expand it.
plugins/outputs/prometheus_client/prometheus_client.go
+
37
−
33
View file @
6efe91ea
...
...
@@ -6,6 +6,7 @@ import (
"net/http"
"regexp"
"strings"
"sync"
"github.com/influxdata/telegraf"
"github.com/influxdata/telegraf/plugins/outputs"
...
...
@@ -26,6 +27,10 @@ var (
type
PrometheusClient
struct
{
Listen
string
metrics
map
[
string
]
prometheus
.
Metric
sync
.
Mutex
}
var
sampleConfig
=
`
...
...
@@ -34,6 +39,7 @@ var sampleConfig = `
`
func
(
p
*
PrometheusClient
)
Start
()
error
{
prometheus
.
MustRegister
(
p
)
defer
func
()
{
if
r
:=
recover
();
r
!=
nil
{
// recovering from panic here because there is no way to stop a
...
...
@@ -78,7 +84,27 @@ func (p *PrometheusClient) Description() string {
return
"Configuration for the Prometheus client to spawn"
}
// Implements prometheus.Collector
func
(
p
*
PrometheusClient
)
Describe
(
ch
chan
<-
*
prometheus
.
Desc
)
{
prometheus
.
NewGauge
(
prometheus
.
GaugeOpts
{
Name
:
"Dummy"
,
Help
:
"Dummy"
})
.
Describe
(
ch
)
}
// Implements prometheus.Collector
func
(
p
*
PrometheusClient
)
Collect
(
ch
chan
<-
prometheus
.
Metric
)
{
p
.
Lock
()
defer
p
.
Unlock
()
for
_
,
m
:=
range
p
.
metrics
{
ch
<-
m
}
}
func
(
p
*
PrometheusClient
)
Write
(
metrics
[]
telegraf
.
Metric
)
error
{
p
.
Lock
()
defer
p
.
Unlock
()
p
.
metrics
=
make
(
map
[
string
]
prometheus
.
Metric
)
if
len
(
metrics
)
==
0
{
return
nil
}
...
...
@@ -124,45 +150,23 @@ func (p *PrometheusClient) Write(metrics []telegraf.Metric) error {
continue
}
mVec
:=
prometheus
.
NewUntypedVec
(
prometheus
.
UntypedOpts
{
Name
:
mname
,
Help
:
"Telegraf collected metric"
,
},
labels
,
)
collector
,
err
:=
prometheus
.
RegisterOrGet
(
mVec
)
if
err
!=
nil
{
log
.
Printf
(
"prometheus_client: Metric failed to register with prometheus, %s"
,
err
)
continue
}
mVec
,
ok
:=
collector
.
(
*
prometheus
.
UntypedVec
)
if
!
ok
{
continue
}
desc
:=
prometheus
.
NewDesc
(
mname
,
"Telegraf collected metric"
,
nil
,
l
)
var
metric
prometheus
.
Metric
var
err
error
switch
val
:=
val
.
(
type
)
{
case
int64
:
m
,
err
:=
mVec
.
GetMetricWith
(
l
)
if
err
!=
nil
{
log
.
Printf
(
"ERROR Getting metric in Prometheus output, "
+
"key: %s, labels: %v,
\n
err: %s
\n
"
,
mname
,
l
,
err
.
Error
())
continue
}
m
.
Set
(
float64
(
val
))
metric
,
err
=
prometheus
.
NewConstMetric
(
desc
,
prometheus
.
UntypedValue
,
float64
(
val
))
case
float64
:
m
,
err
:=
mVec
.
GetMetricWith
(
l
)
if
err
!=
nil
{
log
.
Printf
(
"ERROR Getting metric in Prometheus output, "
+
"key: %s, labels: %v,
\n
err: %s
\n
"
,
mname
,
l
,
err
.
Error
())
continue
}
m
.
Set
(
val
)
metric
,
err
=
prometheus
.
NewConstMetric
(
desc
,
prometheus
.
UntypedValue
,
val
)
default
:
continue
}
if
err
!=
nil
{
log
.
Printf
(
"ERROR creating prometheus metric, "
+
"key: %s, labels: %v,
\n
err: %s
\n
"
,
mname
,
l
,
err
.
Error
())
}
p
.
metrics
[
desc
.
String
()]
=
metric
}
}
return
nil
...
...
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