Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
U
uniset2
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
UniSet project repositories
uniset2
Commits
f90f053d
Commit
f90f053d
authored
Oct 26, 2016
by
Pavel Vainerman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(netdata plugin): initial commit
parent
0d5a2ef6
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
216 additions
and
0 deletions
+216
-0
test.xml
conf/test.xml
+21
-0
uniset.chart.py
python/netdata-plugin/uniset.chart.py
+192
-0
uniset.conf
python/netdata-plugin/uniset.conf
+3
-0
No files found.
conf/test.xml
View file @
f90f053d
...
@@ -298,6 +298,11 @@
...
@@ -298,6 +298,11 @@
<item
id=
"2055"
mbtcp=
"3"
mbaddr=
"2"
mbreg=
"263"
iotype=
"AI"
name=
"AIMBADD2"
textname=
"Тестовый регистр для проверки чтения по второму устройству"
/>
<item
id=
"2055"
mbtcp=
"3"
mbaddr=
"2"
mbreg=
"263"
iotype=
"AI"
name=
"AIMBADD2"
textname=
"Тестовый регистр для проверки чтения по второму устройству"
/>
<!-- test netdata -->
<item
id=
"200"
iotype=
"DI"
name=
"UNET_DATA1_S"
textname=
"UNET: data1"
ndata=
"unet"
/>
<item
id=
"201"
iotype=
"DI"
name=
"UNET_DATA2_S"
textname=
"UNET: data2"
ndata=
"unet"
/>
<item
id=
"202"
iotype=
"DI"
name=
"UNET_DATA3_S"
textname=
"UNET: data3"
ndata=
"unet"
/>
<!-- MBTCP PERF TEST -->
<!-- MBTCP PERF TEST -->
<item
id=
"10001"
mbperf=
"1"
iotype=
"AI"
mbaddr=
"0x01"
mbfunc=
"0x03"
mbreg=
"3"
mbtype=
"rtu"
name=
"Sensor10001_S"
textname=
"test sensor 10001"
/>
<item
id=
"10001"
mbperf=
"1"
iotype=
"AI"
mbaddr=
"0x01"
mbfunc=
"0x03"
mbreg=
"3"
mbtype=
"rtu"
name=
"Sensor10001_S"
textname=
"test sensor 10001"
/>
<item
id=
"10002"
mbperf=
"1"
iotype=
"AI"
mbaddr=
"0x01"
mbfunc=
"0x03"
mbreg=
"5"
mbtype=
"rtu"
name=
"Sensor10002_S"
textname=
"test sensor 10002"
/>
<item
id=
"10002"
mbperf=
"1"
iotype=
"AI"
mbaddr=
"0x01"
mbfunc=
"0x03"
mbreg=
"5"
mbtype=
"rtu"
name=
"Sensor10002_S"
textname=
"test sensor 10002"
/>
...
@@ -5644,4 +5649,20 @@
...
@@ -5644,4 +5649,20 @@
<point
x=
"1000"
y=
"600"
/>
<point
x=
"1000"
y=
"600"
/>
</diagram>
</diagram>
</Calibrations>
</Calibrations>
<netdata>
<!-- https://github.com/firehol/netdata/wiki/External-Plugins -->
<!-- CHART type.id name title units [family [context [charttype [priority [update_every]]]]] -->
<chart
id=
'unet'
name=
'NAME'
title=
"unet"
units=
'count'
family=
'UNET'
context=
''
charttype=
'stacked'
priority=
''
update_every=
''
>
<!-- Чтобы иметь возможность выводить на одном чарте, разные группы можно указывать много 'line' -->
<!-- Параметры берутся из <sensors> в виду netdata_xxx (необязательные помечены []
В качестве id - берётся name.
В качестве name - берётся name, если не указан netdata_name=''
-->
<!-- DIMENSION id [name [algorithm [multiplier [divisor [hidden]]]]] -->
<lines
filter_field=
'ndata'
filter_value=
'unet'
/>
</chart>
</netdata>
</UNISETPLC>
</UNISETPLC>
python/netdata-plugin/uniset.chart.py
0 → 100755
View file @
f90f053d
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Description: uniset netdata python.d module
# Author: Pavel Vainerman (pv)
import
os
import
sys
sys
.
path
.
append
(
"./python_modules"
)
import
random
import
uniset2
from
uniset2
import
UniXML
from
base
import
SimpleService
NAME
=
os
.
path
.
basename
(
__file__
)
.
replace
(
".chart.py"
,
""
)
# default module values
update_every
=
5
priority
=
90000
retries
=
60
class
Service
(
SimpleService
):
sensors
=
[]
def
__init__
(
self
,
configuration
=
None
,
name
=
None
):
super
(
self
.
__class__
,
self
)
.
__init__
(
configuration
=
configuration
,
name
=
name
)
# if 'confile' not in self.configuration:
# self.error("uniset plugin: Unknown confile..")
# raise RuntimeError
self
.
info
(
"uniset plugin: read from /home/pv/Projects.com/uniset-2.0/conf/test.xml"
)
self
.
create_charts
(
"/home/pv/Projects.com/uniset-2.0/conf/test.xml"
)
# class Service():
#
# sensors = []
#
# def error(self,txt):
# print txt
#
# def __init__(self, configuration=None, name=None):
# self.create_charts("./test.xml")
def
find_section
(
self
,
xml
,
secname
):
node
=
xml
.
findNode
(
xml
.
getDoc
(),
secname
)[
0
]
if
node
==
None
:
self
.
error
(
"uniset plugin: not found
%
s section"
%
secname
)
raise
RuntimeError
return
node
.
children
def
create_charts
(
self
,
confile
):
try
:
xml
=
UniXML
(
confile
)
snode
=
self
.
find_section
(
xml
,
"sensors"
)
cnode
=
self
.
find_section
(
xml
,
"netdata"
)
myCharts
=
{}
myOrder
=
[]
node
=
xml
.
firstNode
(
cnode
)
while
node
!=
None
:
# CHART type.id name title units [family [context [charttype [priority [update_every]]]]]
id
=
node
.
prop
(
'id'
)
if
id
==
''
or
id
==
None
:
self
.
error
(
"uniset plugin: IGNORE CHART.. Unknown id=''."
)
node
=
xml
.
nextNode
(
node
)
continue
chart
=
{}
options
=
[]
#options.append(node.prop('id'))
options
.
append
(
None
)
options
.
append
(
node
.
prop
(
'name'
))
options
.
append
(
node
.
prop
(
'units'
))
options
.
append
(
node
.
prop
(
'title'
))
options
.
append
(
node
.
prop
(
'family'
))
# options.append(node.prop('context'))
options
.
append
(
self
.
get_param
(
node
,
'charttype'
,
'area'
))
# options.append(node.prop('priority'))
# options.append(node.prop('update_every'))
chart
[
'options'
]
=
options
chart
[
'lines'
]
=
[]
self
.
build_lines
(
chart
,
node
,
xml
,
snode
)
if
len
(
chart
[
'lines'
])
>
0
:
myOrder
.
append
(
id
)
myCharts
[
id
]
=
chart
node
=
xml
.
nextNode
(
node
)
self
.
definitions
=
myCharts
self
.
order
=
myOrder
except
uniset2
.
UniXMLException
,
e
:
self
.
error
(
"uniset plugin: FAILED load xmlfile=
%
s err='
%
s'"
%
(
confile
,
e
.
getError
()))
raise
RuntimeError
def
build_lines
(
self
,
chart
,
lnode
,
xml
,
snode
):
node
=
xml
.
firstNode
(
lnode
.
children
)
while
node
!=
None
:
ff
=
node
.
prop
(
'filter_field'
)
fv
=
node
.
prop
(
'filter_value'
)
if
ff
==
''
or
ff
==
None
:
self
.
error
(
"uniset plugin: Unknown filter_fileld for chart id='
%
s'"
%
node
.
parent
.
prop
(
'id'
))
raise
RuntimeError
self
.
read_sensors
(
snode
,
ff
,
fv
,
xml
,
chart
)
node
=
xml
.
nextNode
(
node
)
def
read_sensors
(
self
,
snode
,
ff
,
fv
,
xml
,
chart
):
node
=
xml
.
firstNode
(
snode
)
while
node
!=
None
:
if
self
.
check_filter
(
node
,
ff
,
fv
)
==
False
:
node
=
xml
.
nextNode
(
node
)
continue
# DIMENSION id[name[algorithm[multiplier[divisor[hidden]]]]]
# Параметры берутся из <sensors> по полям netdata_xxx (необязательные помечены []
# В качестве id - берётся name.
# В качестве name - берётся name, если не указан netdata_name=''
params
=
[]
id
=
self
.
get_param
(
node
,
'netdata_id'
,
node
.
prop
(
'name'
))
if
id
==
''
or
id
==
None
:
self
.
error
(
"uniset plugin: Unknown 'id' for sensor
%
s"
%
node
.
prop
(
'name'
))
raise
RuntimeError
params
.
append
(
id
)
params
.
append
(
self
.
get_param
(
node
,
'netdata_name'
,
node
.
prop
(
'name'
)))
params
.
append
(
self
.
get_param
(
node
,
'netdata_alg'
,
'absolute'
))
# params.append(self.get_param(node, 'netdata_multiplier', None))
# params.append(self.get_param(node, 'netdata_divisor', None))
# params.append(self.get_param(node, 'netdata_hidden', None))
self
.
sensors
.
append
([
id
,
node
.
prop
(
'id'
)])
chart
[
'lines'
]
.
append
(
params
)
node
=
xml
.
nextNode
(
node
)
def
get_param
(
self
,
node
,
name
,
defval
):
val
=
node
.
prop
(
name
)
if
val
!=
None
and
len
(
val
)
>
0
:
return
val
return
defval
def
check_filter
(
self
,
node
,
ff
,
fv
):
if
ff
==
None
:
return
False
if
ff
==
''
:
return
True
;
if
fv
==
''
and
node
.
prop
(
ff
)
==
''
:
return
False
if
fv
!=
''
and
node
.
prop
(
ff
)
!=
fv
:
return
False
return
True
def
_get_data
(
self
):
data
=
{}
for
netid
,
id
in
self
.
sensors
:
data
[
netid
]
=
random
.
randint
(
0
,
100
)
if
len
(
data
)
==
0
:
return
None
return
data
# if __name__ == "__main__":
#
# serv = Service(None,"test")
\ No newline at end of file
python/netdata-plugin/uniset.conf
0 → 100644
View file @
f90f053d
update_every
=
5
confile
: /
home
/
pv
/
Projects
.
com
/
uniset
-
2
.
0
/
conf
/
test
.
xml
\ No newline at end of file
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