Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
c9260d7e
Commit
c9260d7e
authored
Dec 25, 2013
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bugfixes and improvements to graphite target editor
parent
7cbd88f3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
122 additions
and
80 deletions
+122
-80
src/app/controllers/graphiteTarget.js
+25
-34
src/app/services/graphite/functions.js
+0
-46
src/app/services/graphite/graphiteFuncs.js
+97
-0
No files found.
src/app/controllers/graphiteTarget.js
View file @
c9260d7e
...
@@ -2,10 +2,10 @@ define([
...
@@ -2,10 +2,10 @@ define([
'angular'
,
'angular'
,
'underscore'
,
'underscore'
,
'config'
,
'config'
,
'../services/graphite/
function
s'
,
'../services/graphite/
graphiteFunc
s'
,
'../services/graphite/parser'
'../services/graphite/parser'
],
],
function
(
angular
,
_
,
config
,
graphiteFunc
tion
s
,
Parser
)
{
function
(
angular
,
_
,
config
,
graphiteFuncs
,
Parser
)
{
'use strict'
;
'use strict'
;
var
module
=
angular
.
module
(
'kibana.controllers'
);
var
module
=
angular
.
module
(
'kibana.controllers'
);
...
@@ -13,9 +13,8 @@ function (angular, _, config, graphiteFunctions, Parser) {
...
@@ -13,9 +13,8 @@ function (angular, _, config, graphiteFunctions, Parser) {
module
.
controller
(
'GraphiteTargetCtrl'
,
function
(
$scope
,
$http
)
{
module
.
controller
(
'GraphiteTargetCtrl'
,
function
(
$scope
,
$http
)
{
$scope
.
init
=
function
()
{
$scope
.
init
=
function
()
{
$scope
.
funcDefs
=
graphiteFunc
tions
;
$scope
.
funcDefs
=
graphiteFunc
s
.
getDefList
()
;
parseTarget
();
parseTarget
();
console
.
log
(
'init:'
);
};
};
function
parseTarget
()
{
function
parseTarget
()
{
...
@@ -34,7 +33,15 @@ function (angular, _, config, graphiteFunctions, Parser) {
...
@@ -34,7 +33,15 @@ function (angular, _, config, graphiteFunctions, Parser) {
return
;
return
;
}
}
try
{
parseTargeRecursive
(
astNode
);
parseTargeRecursive
(
astNode
);
}
catch
(
err
)
{
console
.
log
(
'error parsing target:'
,
err
.
message
);
$scope
.
parserError
=
err
.
message
;
$scope
.
showTextEditor
=
true
;
}
checkOtherSegments
(
$scope
.
segments
.
length
);
checkOtherSegments
(
$scope
.
segments
.
length
);
}
}
...
@@ -43,24 +50,26 @@ function (angular, _, config, graphiteFunctions, Parser) {
...
@@ -43,24 +50,26 @@ function (angular, _, config, graphiteFunctions, Parser) {
return
null
;
return
null
;
}
}
if
(
astNode
.
type
===
'function'
)
{
switch
(
astNode
.
type
)
{
var
innerFunc
=
{};
case
'function'
:
innerFunc
.
def
=
_
.
findWhere
(
$scope
.
funcDefs
,
{
name
:
astNode
.
name
});
var
innerFunc
=
graphiteFuncs
.
createFuncInstance
(
astNode
.
name
);
innerFunc
.
params
=
innerFunc
.
def
.
defaultParams
.
slice
(
0
);
_
.
each
(
astNode
.
params
,
function
(
param
,
index
)
{
_
.
each
(
astNode
.
params
,
function
(
param
,
index
)
{
parseTargeRecursive
(
param
,
innerFunc
,
index
);
parseTargeRecursive
(
param
,
innerFunc
,
index
);
});
});
innerFunc
.
text
=
getFuncText
(
innerFunc
.
def
,
innerFunc
.
params
);
innerFunc
.
updateText
(
);
$scope
.
functions
.
push
(
innerFunc
);
$scope
.
functions
.
push
(
innerFunc
);
}
break
;
if
(
astNode
.
type
===
'number'
||
astNode
.
type
===
'string'
)
{
case
'string'
:
func
.
params
[
index
-
1
]
=
astNode
.
value
;
case
'number'
:
if
((
index
-
1
)
>=
func
.
def
.
params
.
length
)
{
throw
{
message
:
'invalid number of parameters to method '
+
func
.
def
.
name
};
}
}
func
.
params
[
index
-
1
]
=
astNode
.
value
;
if
(
astNode
.
type
===
'metric'
)
{
break
;
case
'metric'
:
$scope
.
segments
=
_
.
map
(
astNode
.
segments
,
function
(
segment
)
{
$scope
.
segments
=
_
.
map
(
astNode
.
segments
,
function
(
segment
)
{
return
{
return
{
val
:
segment
.
value
,
val
:
segment
.
value
,
...
@@ -114,20 +123,6 @@ function (angular, _, config, graphiteFunctions, Parser) {
...
@@ -114,20 +123,6 @@ function (angular, _, config, graphiteFunctions, Parser) {
});
});
}
}
function
getFuncText
(
funcDef
,
params
)
{
if
(
params
.
length
===
0
)
{
return
funcDef
.
name
+
'()'
;
}
var
text
=
funcDef
.
name
+
'('
;
_
.
each
(
funcDef
.
params
,
function
(
param
,
index
)
{
text
+=
params
[
index
]
+
', '
;
});
text
=
text
.
substring
(
0
,
text
.
length
-
2
);
text
+=
')'
;
return
text
;
}
function
wrapFunction
(
target
,
func
)
{
function
wrapFunction
(
target
,
func
)
{
var
targetWrapped
=
func
.
def
.
name
+
'('
+
target
;
var
targetWrapped
=
func
.
def
.
name
+
'('
+
target
;
_
.
each
(
func
.
params
,
function
(
param
)
{
_
.
each
(
func
.
params
,
function
(
param
)
{
...
@@ -200,16 +195,12 @@ function (angular, _, config, graphiteFunctions, Parser) {
...
@@ -200,16 +195,12 @@ function (angular, _, config, graphiteFunctions, Parser) {
};
};
$scope
.
functionParamsChanged
=
function
(
func
)
{
$scope
.
functionParamsChanged
=
function
(
func
)
{
func
.
text
=
getFuncText
(
func
.
def
,
func
.
params
);
func
.
updateText
(
);
$scope
.
targetChanged
();
$scope
.
targetChanged
();
};
};
$scope
.
addFunction
=
function
(
funcDef
)
{
$scope
.
addFunction
=
function
(
funcDef
)
{
$scope
.
functions
.
push
({
$scope
.
functions
.
push
(
graphiteFuncs
.
createFuncInstance
(
funcDef
));
def
:
funcDef
,
params
:
funcDef
.
defaultParams
.
slice
(
0
),
text
:
getFuncText
(
funcDef
,
funcDef
.
defaultParams
)
});
$scope
.
targetChanged
();
$scope
.
targetChanged
();
};
};
...
...
src/app/services/graphite/functions.js
deleted
100644 → 0
View file @
7cbd88f3
define
([
],
function
()
{
'use strict'
;
return
[
{
name
:
"scaleToSeconds"
,
params
:
[
{
name
:
"seconds"
,
type
:
"int"
}
],
defaultParams
:
[
1
]
},
{
name
:
"sumSeries"
,
params
:
[],
defaultParams
:
[]
},
{
name
:
"groupByNode"
,
params
:
[
{
name
:
"node"
,
type
:
"node"
,
},
{
name
:
"function"
,
type
:
"function"
,
}
],
defaultParams
:
[
3
,
"sum"
]
},
{
name
:
"alias"
,
params
:
[
{
name
:
"alias"
,
type
:
'string'
}
],
defaultParams
:
[
'alias'
]
},
{
name
:
'aliasByNode'
,
params
:
[
{
name
:
"node"
,
type
:
"node"
,
}
],
defaultParams
:
[
3
]
}
];
});
\ No newline at end of file
src/app/services/graphite/graphiteFuncs.js
0 → 100644
View file @
c9260d7e
define
([
'underscore'
],
function
(
_
)
{
'use strict'
;
var
funcDefList
=
[];
var
index
=
[];
function
addFuncDef
(
funcDef
)
{
funcDefList
.
push
(
funcDef
);
index
[
funcDef
.
name
]
=
funcDef
;
index
[
funcDef
.
shortName
||
funcDef
.
name
]
=
funcDef
;
}
addFuncDef
({
name
:
'scaleToSeconds'
,
params
:
[
{
name
:
'seconds'
,
type
:
'int'
}
],
defaultParams
:
[
1
],
});
addFuncDef
({
name
:
"alias"
,
params
:
[
{
name
:
"alias"
,
type
:
'string'
}
],
defaultParams
:
[
'alias'
]
});
addFuncDef
({
name
:
'sumSeries'
,
shortName
:
'sum'
,
params
:
[],
defaultParams
:
[]
});
addFuncDef
({
name
:
"groupByNode"
,
params
:
[
{
name
:
"node"
,
type
:
"node"
,
},
{
name
:
"function"
,
type
:
"function"
,
}
],
defaultParams
:
[
3
,
"sum"
]
});
addFuncDef
({
name
:
'aliasByNode'
,
params
:
[
{
name
:
"node"
,
type
:
"node"
,
}
],
defaultParams
:
[
3
]
});
function
FuncInstance
(
funcDef
)
{
this
.
def
=
funcDef
;
this
.
params
=
funcDef
.
defaultParams
.
slice
(
0
);
this
.
updateText
();
}
FuncInstance
.
prototype
.
updateText
=
function
()
{
if
(
this
.
params
.
length
===
0
)
{
this
.
text
=
this
.
def
.
name
+
'()'
;
return
;
}
var
text
=
this
.
def
.
name
+
'('
;
_
.
each
(
this
.
def
.
params
,
function
(
param
,
index
)
{
text
+=
this
.
params
[
index
]
+
', '
;
},
this
);
text
=
text
.
substring
(
0
,
text
.
length
-
2
);
text
+=
')'
;
this
.
text
=
text
;
};
return
{
createFuncInstance
:
function
(
name
)
{
if
(
_
.
isString
(
name
))
{
var
funcDef
=
index
[
name
];
if
(
!
funcDef
)
{
throw
{
message
:
'Method not found '
+
name
};
}
name
=
funcDef
;
}
return
new
FuncInstance
(
name
);
},
getDefList
:
function
()
{
return
funcDefList
.
slice
(
0
);
}
};
});
\ 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