Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
memcached2influx
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
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
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
Show more breadcrumbs
lnf-da-control
memcached2influx
Commits
577891f8
Commit
577891f8
authored
2 years ago
by
Riccardo Sellari
Browse files
Options
Downloads
Patches
Plain Diff
clean but not funtioning
parent
f45374fe
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
memcached2Influx.py
+32
-34
32 additions, 34 deletions
memcached2Influx.py
with
32 additions
and
34 deletions
memcached2Influx.py
+
32
−
34
View file @
577891f8
...
...
@@ -5,42 +5,38 @@ import sys
from
pymemcache.client
import
base
import
os
import
re
import
json
#dafneStat
def
findTheKey
(
path
,
clientMemcached
):
with
open
(
path
,
'
r
'
)
as
configFile
:
data
=
{}
pattern
=
r
'
^
"
(.+)
"
:(.+,(( ←)|[^a-zA-Z ]))
'
for
line
in
configFile
:
def
jsonPost2Influx
(
fileData
,
clientMemcached
,
clientInflux
):
fileData
[
'
memcached
'
]
=
json
.
load
(
clientMemcached
.
get
(
fileData
[
'
keybind
'
]))
payload
=
[]
payload
.
append
({
"
measurement
"
:
"
dafneStat
"
,
"
tags
"
:
{
"
key
"
:
fileData
[
"
keybind
"
]
},
"
fields
"
:
{
"
data
"
:
json
.
dumps
(
fileData
[
"
memcached
"
])
}
})
def
findTheKey
(
configFile
,
path
):
data
=
{}
pattern
=
r
'
^
"
(.+)
"
:(.+,(( ←)|[^a-zA-Z ]))
'
for
line
in
configFile
:
match
=
re
.
search
(
pattern
,
line
)
if
(
match
):
match
=
re
.
search
(
pattern
,
line
)
parameter
=
re
.
sub
(
r
'
,|
"
|( ←)
'
,
""
,
match
.
group
(
2
))
data
[
match
.
group
(
1
)]
=
parameter
if
(
line
.
find
(
'
keybind
'
)
!=
-
1
):
line
=
re
.
sub
(
r
'
,|( ←)
'
,
""
,
line
)
pattern
=
r
'"
(.+)
"
:
"
(.+)
"'
match
=
re
.
search
(
pattern
,
line
)
if
(
match
):
match
=
re
.
search
(
pattern
,
line
)
parameter
=
re
.
sub
(
r
'
,|
"
|( ←)
'
,
""
,
match
.
group
(
2
))
data
[
match
.
group
(
1
)]
=
parameter
if
(
line
.
find
(
'
keybind
'
)
!=
-
1
):
line
=
re
.
sub
(
r
'
,|( ←)
'
,
""
,
line
)
pattern
=
r
'"
(.+)
"
:
"
(.+)
"'
match
=
re
.
search
(
pattern
,
line
)
data
[
match
.
group
(
1
)]
=
match
.
group
(
2
)
data
[
'
memcached
'
]
=
clientMemcached
.
get
(
data
[
'
keybind
'
])
if
(
data
[
'
type
'
]
==
'
json
'
):
data4influx
=
[{
"
measurements
"
:
"
memcachedData
"
,
"
timestamp
"
:
datetime
.
now
(),
"
tags
"
:
{
"
type
"
:
data
[
"
type
"
]
},
"
fields
"
:{
data
[
"
keybind
"
]
:
data
[
'
memcached
'
]
}
}
]
print
(
data4influx
)
print
(
'
\n
'
)
clientInflux
.
write_points
(
data4influx
)
data
.
clear
else
:
pass
data
[
match
.
group
(
1
)]
=
match
.
group
(
2
)
return
data
...
...
@@ -74,6 +70,8 @@ except:
#try:
# if os.path.isfile(args.file):
key
=
findTheKey
(
args
.
file
,
clientMemcached
)
with
open
(
args
.
file
,
'
r
'
)
as
configFile
:
fileData
=
findTheKey
(
configFile
,
clientMemcached
)
jsonPost2Influx
(
fileData
,
clientMemcached
,
clientInflux
)
#except FileNotFoundError as e:
# sys.exit("Error: " + args.iptable + " is not valid or does not point to a DBFile.")
\ No newline at end of file
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