Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
apache-exporter
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
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
Show more breadcrumbs
ai3
thirdparty
apache-exporter
Commits
8e441933
Commit
8e441933
authored
8 years ago
by
Ruslan Islamgaliev
Browse files
Options
Downloads
Plain Diff
Merge branch 'ton31337-Fix/use_NewConstMetric'
parents
b8fb39e4
5b71e974
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
apache_exporter.go
+42
-47
42 additions, 47 deletions
apache_exporter.go
with
42 additions
and
47 deletions
apache_exporter.go
+
42
−
47
View file @
8e441933
...
...
@@ -30,11 +30,11 @@ type Exporter struct {
mutex
sync
.
Mutex
client
*
http
.
Client
up
prometheus
.
Gauge
up
*
prometheus
.
Desc
scrapeFailures
prometheus
.
Counter
accessesTotal
prometheus
.
Counter
kBytesTotal
prometheus
.
Counter
uptime
prometheus
.
Counter
accessesTotal
*
prometheus
.
Desc
kBytesTotal
*
prometheus
.
Desc
uptime
*
prometheus
.
Desc
workers
*
prometheus
.
GaugeVec
scoreboard
*
prometheus
.
GaugeVec
connections
*
prometheus
.
GaugeVec
...
...
@@ -43,31 +43,31 @@ type Exporter struct {
func
NewExporter
(
uri
string
)
*
Exporter
{
return
&
Exporter
{
URI
:
uri
,
up
:
prometheus
.
New
Gauge
(
prometheus
.
GaugeOpts
{
Namespace
:
namespace
,
Name
:
"up
"
,
Help
:
"Could the apache server be reached."
,
}
),
up
:
prometheus
.
New
Desc
(
prometheus
.
BuildFQName
(
namespace
,
""
,
"up"
)
,
"Could the apache server be reached
"
,
nil
,
nil
),
scrapeFailures
:
prometheus
.
NewCounter
(
prometheus
.
CounterOpts
{
Namespace
:
namespace
,
Name
:
"exporter_scrape_failures_total"
,
Help
:
"Number of errors while scraping apache."
,
}),
accessesTotal
:
prometheus
.
New
Counter
(
prometheus
.
CounterOpts
{
Namespace
:
namespace
,
Name
:
"
accesses
_total
"
,
Help
:
"Current total apache accesses"
,
}
),
kBytesTotal
:
prometheus
.
New
Counter
(
prometheus
.
CounterOpts
{
Namespace
:
namespace
,
Name
:
"sent_kilobytes_total
"
,
Help
:
"Current total kbytes sent"
,
}
),
uptime
:
prometheus
.
New
Counter
(
prometheus
.
CounterOpts
{
Namespace
:
namespace
,
Name
:
"
uptime
_
seconds
_total
"
,
Help
:
"Current uptime in seconds"
,
}
),
accessesTotal
:
prometheus
.
New
Desc
(
prometheus
.
BuildFQName
(
namespace
,
""
,
"accesses_total"
)
,
"Current total apache
accesses"
,
nil
,
nil
),
kBytesTotal
:
prometheus
.
New
Desc
(
prometheus
.
BuildFQName
(
namespace
,
""
,
"sent_kilobytes_total"
)
,
"Current total kbytes sent
"
,
nil
,
nil
),
uptime
:
prometheus
.
New
Desc
(
prometheus
.
BuildFQName
(
namespace
,
""
,
"uptime_seconds_total"
)
,
"Current
uptime
in
seconds"
,
nil
,
nil
),
workers
:
prometheus
.
NewGaugeVec
(
prometheus
.
GaugeOpts
{
Namespace
:
namespace
,
Name
:
"workers"
,
...
...
@@ -98,11 +98,11 @@ func NewExporter(uri string) *Exporter {
}
func
(
e
*
Exporter
)
Describe
(
ch
chan
<-
*
prometheus
.
Desc
)
{
e
.
up
.
Describe
(
ch
)
ch
<-
e
.
up
ch
<-
e
.
accessesTotal
ch
<-
e
.
kBytesTotal
ch
<-
e
.
uptime
e
.
scrapeFailures
.
Describe
(
ch
)
e
.
accessesTotal
.
Describe
(
ch
)
e
.
kBytesTotal
.
Describe
(
ch
)
e
.
uptime
.
Describe
(
ch
)
e
.
workers
.
Describe
(
ch
)
e
.
scoreboard
.
Describe
(
ch
)
e
.
connections
.
Describe
(
ch
)
...
...
@@ -158,12 +158,10 @@ func (e *Exporter) updateScoreboard(scoreboard string) {
func
(
e
*
Exporter
)
collect
(
ch
chan
<-
prometheus
.
Metric
)
error
{
resp
,
err
:=
e
.
client
.
Get
(
e
.
URI
)
if
err
!=
nil
{
e
.
up
.
Set
(
0
)
e
.
up
.
Collect
(
ch
)
ch
<-
prometheus
.
MustNewConstMetric
(
e
.
up
,
prometheus
.
GaugeValue
,
0
)
return
fmt
.
Errorf
(
"Error scraping apache: %v"
,
err
)
}
e
.
up
.
Set
(
1
)
e
.
up
.
Collect
(
ch
)
ch
<-
prometheus
.
MustNewConstMetric
(
e
.
up
,
prometheus
.
GaugeValue
,
1
)
data
,
err
:=
ioutil
.
ReadAll
(
resp
.
Body
)
resp
.
Body
.
Close
()
...
...
@@ -191,24 +189,21 @@ func (e *Exporter) collect(ch chan<- prometheus.Metric) error {
return
err
}
e
.
accessesTotal
.
Set
(
val
)
e
.
accessesTotal
.
Collect
(
ch
)
ch
<-
prometheus
.
MustNewConstMetric
(
e
.
accessesTotal
,
prometheus
.
CounterValue
,
val
)
case
key
==
"Total kBytes"
:
val
,
err
:=
strconv
.
ParseFloat
(
v
,
64
)
if
err
!=
nil
{
return
err
}
e
.
kBytesTotal
.
Set
(
val
)
e
.
kBytesTotal
.
Collect
(
ch
)
ch
<-
prometheus
.
MustNewConstMetric
(
e
.
kBytesTotal
,
prometheus
.
CounterValue
,
val
)
case
key
==
"Uptime"
:
val
,
err
:=
strconv
.
ParseFloat
(
v
,
64
)
if
err
!=
nil
{
return
err
}
e
.
uptime
.
Set
(
val
)
e
.
uptime
.
Collect
(
ch
)
ch
<-
prometheus
.
MustNewConstMetric
(
e
.
uptime
,
prometheus
.
CounterValue
,
val
)
case
key
==
"BusyWorkers"
:
val
,
err
:=
strconv
.
ParseFloat
(
v
,
64
)
if
err
!=
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