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
04e57ed1
Commit
04e57ed1
authored
2 years ago
by
Riccardo Sellari
Browse files
Options
Downloads
Patches
Plain Diff
not finding any usefull regex for now
parent
8d7f2630
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
cofnigurationFile.txt
+26
-0
26 additions, 0 deletions
cofnigurationFile.txt
memcached2Influx.py
+57
-0
57 additions, 0 deletions
memcached2Influx.py
with
83 additions
and
0 deletions
cofnigurationFile.txt
0 → 100644
+
26
−
0
View file @
04e57ed1
{
"dataset":[
{
"name":"e_current", ← name of the variable (in influxdb will appear as measurement)
"type":"double", ← type of the data (valid are: int32|int64|double|float|bool|string|json)
"description":"readout electron current", ← an optional description
"offset":24, ← offset into a binary key
"len":8, ← data size
"factor":0, ← an optional factor that multiply the data
"lbe":true, ← endianess true: little endian, false: bigendian
"rate":1, ← >0 rate fetch-pushrate (in Hz)
"keybind":"DCTEL002_DYN" ← source memcached key
},
{
"name":"dafne_state",
"type":"json", ← (the data is a utf-8 string, the type of data is implicit once imported in JSON)
"description":"Dafne state",
"offset":0, ← optional in case of json (if not is the offset inside the string)
"variables":["jsonkey1","jsonkey2"], ← optional field that specifies the keys in the json to be pushed (if not specified, all keys must be pushed
"len":256, ← maximum data length
"keybind":"DAFNESTATE_JDAT"
}]
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
memcached2Influx.py
0 → 100644
+
57
−
0
View file @
04e57ed1
import
argparse
from
influxdb
import
InfluxDBClient
import
sys
from
pymemcache.client
import
base
import
os
import
re
def
findTheKey
(
path
,
clientMemcached
):
with
open
(
path
,
'
r
'
)
as
configFile
:
data
=
{}
pattern
=
r
'
\"(.+)\":(.+),
'
for
line
in
configFile
:
match
=
re
.
search
(
pattern
,
line
)
if
(
match
):
match
=
re
.
search
(
pattern
,
line
)
data
[
match
.
group
(
1
)]
=
match
.
group
(
2
)
print
(
data
)
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
"
-u
"
,
"
--username
"
,
required
=
False
,
default
=
""
,
help
=
"
the username needed to log in the db
"
)
parser
.
add_argument
(
"
-p
"
,
"
--password
"
,
required
=
False
,
default
=
""
,
help
=
"
the password needed to log in the db
"
)
parser
.
add_argument
(
"
-s
"
,
"
--server
"
,
required
=
False
,
default
=
""
,
help
=
"
the ip address of the server
"
)
parser
.
add_argument
(
"
-d
"
,
"
--database
"
,
required
=
False
,
default
=
""
,
help
=
"
the name of the database you want to log in
"
)
parser
.
add_argument
(
"
-f
"
,
"
--file
"
,
default
=
"
.
"
,
help
=
"
the configuration file path
"
)
parser
.
add_argument
(
"
-po
"
,
"
--port
"
,
help
=
"
the port associated with the server address
"
)
args
=
parser
.
parse_args
()
#log in the influx DB
#python memcached2Influx.py -s vldantemon003.lnf.infn.it -po 8086 -f '/home/riccardo/Random bs go/Test/cofnigurationFile.txt'
#dcsMemDb
try
:
clientInflux
=
InfluxDBClient
(
host
=
args
.
server
,
port
=
args
.
port
,
username
=
args
.
username
,
password
=
args
.
password
)
print
(
"
succesfully logged in
"
)
except
:
sys
.
exit
(
"
Error: Invalid parameters, please try again
"
)
#log in the memcached DB
#memcached_server = "192.168.198.20"
#mc_port = 11211
try
:
clientMemcached
=
base
.
Client
(
(
"
192.168.198.20
"
,
11211
)
,
connect_timeout
=
20.0
)
except
:
sys
.
exit
(
'
Cannot reach the memcached server, try again later
'
)
#try:
# if os.path.isfile(args.file):
key
=
findTheKey
(
args
.
file
,
clientMemcached
)
#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