Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
exchain
nebula
Commits
cc2c0b4e
Commit
cc2c0b4e
authored
Mar 15, 2023
by
Sebastian Stammler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
op-service/metrics: Add Event and EventVec metrics
Reusable event metrics modules.
parent
4751b03c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
58 additions
and
0 deletions
+58
-0
event.go
op-service/metrics/event.go
+58
-0
No files found.
op-service/metrics/event.go
0 → 100644
View file @
cc2c0b4e
package
metrics
import
(
"fmt"
"github.com/prometheus/client_golang/prometheus"
)
type
Event
struct
{
Total
prometheus
.
Counter
LastTime
prometheus
.
Gauge
}
func
(
e
*
Event
)
Record
()
{
e
.
Total
.
Inc
()
e
.
LastTime
.
SetToCurrentTime
()
}
func
NewEvent
(
factory
Factory
,
ns
string
,
name
string
,
displayName
string
)
Event
{
return
Event
{
Total
:
factory
.
NewCounter
(
prometheus
.
CounterOpts
{
Namespace
:
ns
,
Name
:
fmt
.
Sprintf
(
"%s_total"
,
name
),
Help
:
fmt
.
Sprintf
(
"Count of %s events"
,
displayName
),
}),
LastTime
:
factory
.
NewGauge
(
prometheus
.
GaugeOpts
{
Namespace
:
ns
,
Name
:
fmt
.
Sprintf
(
"last_%s_unix"
,
name
),
Help
:
fmt
.
Sprintf
(
"Timestamp of last %s event"
,
displayName
),
}),
}
}
type
EventVec
struct
{
Total
prometheus
.
CounterVec
LastTime
prometheus
.
GaugeVec
}
func
(
e
*
EventVec
)
Record
(
lvs
...
string
)
{
e
.
Total
.
WithLabelValues
(
lvs
...
)
.
Inc
()
e
.
LastTime
.
WithLabelValues
(
lvs
...
)
.
SetToCurrentTime
()
}
func
NewEventVec
(
factory
Factory
,
ns
string
,
name
string
,
displayName
string
,
labelNames
[]
string
)
EventVec
{
return
EventVec
{
Total
:
*
factory
.
NewCounterVec
(
prometheus
.
CounterOpts
{
Namespace
:
ns
,
Name
:
fmt
.
Sprintf
(
"%s_total"
,
name
),
Help
:
fmt
.
Sprintf
(
"Count of %s events"
,
displayName
),
},
labelNames
),
LastTime
:
*
factory
.
NewGaugeVec
(
prometheus
.
GaugeOpts
{
Namespace
:
ns
,
Name
:
fmt
.
Sprintf
(
"last_%s_unix"
,
name
),
Help
:
fmt
.
Sprintf
(
"Timestamp of last %s event"
,
displayName
),
},
labelNames
),
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment