Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
rsyslog-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
rsyslog-exporter
Commits
041a30c6
Commit
041a30c6
authored
3 years ago
by
Filippo Giunchedi
Browse files
Options
Downloads
Patches
Plain Diff
Add omfwd support
parent
d721280f
No related branches found
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
exporter.go
+9
-0
9 additions, 0 deletions
exporter.go
forward.go
+35
-0
35 additions, 0 deletions
forward.go
forward_test.go
+52
-0
52 additions, 0 deletions
forward_test.go
utils.go
+2
-0
2 additions, 0 deletions
utils.go
with
98 additions
and
0 deletions
exporter.go
+
9
−
0
View file @
041a30c6
...
@@ -22,6 +22,7 @@ const (
...
@@ -22,6 +22,7 @@ const (
rsyslogDynStat
rsyslogDynStat
rsyslogDynafileCache
rsyslogDynafileCache
rsyslogInputIMDUP
rsyslogInputIMDUP
rsyslogForward
)
)
type
rsyslogExporter
struct
{
type
rsyslogExporter
struct
{
...
@@ -112,6 +113,14 @@ func (re *rsyslogExporter) handleStatLine(rawbuf []byte) error {
...
@@ -112,6 +113,14 @@ func (re *rsyslogExporter) handleStatLine(rawbuf []byte) error {
for
_
,
p
:=
range
d
.
toPoints
()
{
for
_
,
p
:=
range
d
.
toPoints
()
{
re
.
set
(
p
)
re
.
set
(
p
)
}
}
case
rsyslogForward
:
f
,
err
:=
newForwardFromJSON
(
buf
)
if
err
!=
nil
{
return
err
}
for
_
,
p
:=
range
f
.
toPoints
()
{
re
.
set
(
p
)
}
default
:
default
:
return
fmt
.
Errorf
(
"unknown pstat type: %v"
,
pstatType
)
return
fmt
.
Errorf
(
"unknown pstat type: %v"
,
pstatType
)
...
...
This diff is collapsed.
Click to expand it.
forward.go
0 → 100644
+
35
−
0
View file @
041a30c6
package
main
import
(
"encoding/json"
"fmt"
)
type
forward
struct
{
Name
string
`json:"name"`
BytesSent
int64
`json:"bytes.sent"`
}
func
newForwardFromJSON
(
b
[]
byte
)
(
*
forward
,
error
)
{
var
pstat
forward
err
:=
json
.
Unmarshal
(
b
,
&
pstat
)
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"failed to decode forward stat `%v`: %v"
,
string
(
b
),
err
)
}
return
&
pstat
,
nil
}
func
(
f
*
forward
)
toPoints
()
[]
*
point
{
points
:=
make
([]
*
point
,
1
)
points
[
0
]
=
&
point
{
Name
:
"forward_bytes_total"
,
Type
:
counter
,
Value
:
f
.
BytesSent
,
Description
:
"bytes forwarded to destination"
,
LabelName
:
"destination"
,
LabelValue
:
f
.
Name
,
}
return
points
}
This diff is collapsed.
Click to expand it.
forward_test.go
0 → 100644
+
52
−
0
View file @
041a30c6
package
main
import
"testing"
var
(
forwardLog
=
[]
byte
(
`{ "name": "TCP-FQDN-6514", "origin": "omfwd", "bytes.sent": 666 }`
)
)
func
TestNewForwardFromJSON
(
t
*
testing
.
T
)
{
logType
:=
getStatType
(
forwardLog
)
if
logType
!=
rsyslogForward
{
t
.
Errorf
(
"detected pstat type should be %d but is %d"
,
rsyslogForward
,
logType
)
}
pstat
,
err
:=
newForwardFromJSON
([]
byte
(
forwardLog
))
if
err
!=
nil
{
t
.
Fatalf
(
"expected parsing action not to fail, got: %v"
,
err
)
}
if
want
,
got
:=
"TCP-FQDN-6514"
,
pstat
.
Name
;
want
!=
got
{
t
.
Errorf
(
"wanted '%s', got '%s'"
,
want
,
got
)
}
if
want
,
got
:=
int64
(
666
),
pstat
.
BytesSent
;
want
!=
got
{
t
.
Errorf
(
"wanted '%d', got '%d'"
,
want
,
got
)
}
}
func
TestForwardToPoints
(
t
*
testing
.
T
)
{
pstat
,
err
:=
newForwardFromJSON
([]
byte
(
forwardLog
))
if
err
!=
nil
{
t
.
Fatalf
(
"expected parsing action not to fail, got: %v"
,
err
)
}
points
:=
pstat
.
toPoints
()
point
:=
points
[
0
]
if
want
,
got
:=
"forward_bytes_total"
,
point
.
Name
;
want
!=
got
{
t
.
Errorf
(
"wanted '%s', got '%s'"
,
want
,
got
)
}
if
want
,
got
:=
int64
(
666
),
point
.
Value
;
want
!=
got
{
t
.
Errorf
(
"wanted '%d', got '%d'"
,
want
,
got
)
}
if
want
,
got
:=
counter
,
point
.
Type
;
want
!=
got
{
t
.
Errorf
(
"wanted '%d', got '%d'"
,
want
,
got
)
}
if
want
,
got
:=
"TCP-FQDN-6514"
,
point
.
LabelValue
;
want
!=
got
{
t
.
Errorf
(
"wanted '%s', got '%s'"
,
want
,
got
)
}
}
This diff is collapsed.
Click to expand it.
utils.go
+
2
−
0
View file @
041a30c6
...
@@ -18,6 +18,8 @@ func getStatType(buf []byte) rsyslogType {
...
@@ -18,6 +18,8 @@ func getStatType(buf []byte) rsyslogType {
return
rsyslogDynStat
return
rsyslogDynStat
}
else
if
strings
.
Contains
(
line
,
"dynafile cache"
)
{
}
else
if
strings
.
Contains
(
line
,
"dynafile cache"
)
{
return
rsyslogDynafileCache
return
rsyslogDynafileCache
}
else
if
strings
.
Contains
(
line
,
"omfwd"
)
{
return
rsyslogForward
}
}
return
rsyslogUnknown
return
rsyslogUnknown
}
}
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