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
2cff988b
Commit
2cff988b
authored
Aug 22, 2013
by
spenceralger
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #400 from spenceralger/master
Creates zero-filled data for the histogram.
parents
3b9bc6bc
69ab6bbd
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
139 additions
and
44 deletions
+139
-44
js/services.js
+0
-2
panels/histogram/module.js
+139
-42
No files found.
js/services.js
View file @
2cff988b
...
...
@@ -868,5 +868,4 @@ angular.module('kibana.services', [])
return
false
;
});
};
});
\ No newline at end of file
panels/histogram/module.js
View file @
2cff988b
...
...
@@ -34,7 +34,7 @@
'use strict'
;
angular
.
module
(
'kibana.histogram'
,
[])
.
controller
(
'histogram'
,
function
(
$scope
,
querySrv
,
dashboard
,
filterSrv
)
{
.
controller
(
'histogram'
,
function
(
$scope
,
querySrv
,
dashboard
,
filterSrv
,
timeSeries
)
{
$scope
.
panelMeta
=
{
editorTabs
:
[
...
...
@@ -85,7 +85,39 @@ angular.module('kibana.histogram', [])
};
$scope
.
get_data
=
function
(
segment
,
query_id
)
{
/**
* The time range effecting the panel
* @return {[type]} [description]
*/
$scope
.
get_time_range
=
function
()
{
var
range
=
$scope
.
range
=
filterSrv
.
timeRange
(
'min'
);
return
range
;
}
$scope
.
get_interval
=
function
()
{
var
interval
=
$scope
.
panel
.
interval
,
range
;
if
(
$scope
.
panel
.
auto_int
)
{
range
=
$scope
.
get_time_range
()
if
(
range
)
{
interval
=
kbn
.
secondsToHms
(
kbn
.
calculate_interval
(
range
.
from
,
range
.
to
,
$scope
.
panel
.
resolution
,
0
)
/
1000
);
}
}
$scope
.
panel
.
interval
=
interval
||
'10m'
;
return
$scope
.
panel
.
interval
}
/**
* Fetch the data for a chunk of a queries results. Multiple segments occur when several indicies
* need to be consulted (like timestamped logstash indicies)
* @param number segment The segment count, (0 based)
* @param number query_id The id of the query, generated on the first run and passed back when
* this call is made recursively for more segments
*/
$scope
.
get_data
=
function
(
segment
,
query_id
)
{
if
(
_
.
isUndefined
(
segment
))
{
segment
=
0
}
delete
$scope
.
panel
.
error
;
// Make sure we have everything for the request to complete
...
...
@@ -94,7 +126,8 @@ angular.module('kibana.histogram', [])
}
var
_range
=
$scope
.
range
=
filterSrv
.
timeRange
(
'min'
);
var
_range
=
$scope
.
get_time_range
()
var
_interval
=
$scope
.
get_interval
(
_range
);
if
(
$scope
.
panel
.
auto_int
)
{
$scope
.
panel
.
interval
=
kbn
.
secondsToHms
(
...
...
@@ -102,8 +135,7 @@ angular.module('kibana.histogram', [])
}
$scope
.
panelMeta
.
loading
=
true
;
var
_segment
=
_
.
isUndefined
(
segment
)
?
0
:
segment
;
var
request
=
$scope
.
ejs
.
Request
().
indices
(
dashboard
.
indices
[
_segment
]);
var
request
=
$scope
.
ejs
.
Request
().
indices
(
dashboard
.
indices
[
segment
]);
$scope
.
panel
.
queries
.
ids
=
querySrv
.
idsByMode
(
$scope
.
panel
.
queries
);
// Build the query
...
...
@@ -124,7 +156,7 @@ angular.module('kibana.histogram', [])
}
facet
=
facet
.
keyField
(
$scope
.
panel
.
time_field
).
valueField
(
$scope
.
panel
.
value_field
);
}
facet
=
facet
.
interval
(
$scope
.
panel
.
interval
).
facetFilter
(
$scope
.
ejs
.
QueryFilter
(
query
));
facet
=
facet
.
interval
(
_
interval
).
facetFilter
(
$scope
.
ejs
.
QueryFilter
(
query
));
request
=
request
.
facet
(
facet
).
size
(
0
);
});
...
...
@@ -137,7 +169,7 @@ angular.module('kibana.histogram', [])
// Populate scope when we have results
results
.
then
(
function
(
results
)
{
$scope
.
panelMeta
.
loading
=
false
;
if
(
_
segment
===
0
)
{
if
(
segment
===
0
)
{
$scope
.
hits
=
0
;
$scope
.
data
=
[];
query_id
=
$scope
.
query_id
=
new
Date
().
getTime
();
...
...
@@ -153,49 +185,42 @@ angular.module('kibana.histogram', [])
var
facetIds
=
_
.
map
(
_
.
keys
(
results
.
facets
),
function
(
k
){
return
parseInt
(
k
,
10
);});
// Make sure we're still on the same query/queries
if
(
$scope
.
query_id
===
query_id
&&
_
.
intersection
(
facetIds
,
$scope
.
panel
.
queries
.
ids
).
length
===
$scope
.
panel
.
queries
.
ids
.
length
)
{
if
(
$scope
.
query_id
===
query_id
&&
_
.
difference
(
facetIds
,
$scope
.
panel
.
queries
.
ids
).
length
===
0
)
{
var
i
=
0
;
var
data
,
hits
;
var
i
=
0
,
time_series
,
hits
;
_
.
each
(
$scope
.
panel
.
queries
.
ids
,
function
(
id
)
{
var
v
=
results
.
facets
[
id
];
// Null values at each end of the time range ensure we see entire range
if
(
_
.
isUndefined
(
$scope
.
data
[
i
])
||
_segment
===
0
)
{
data
=
[];
if
(
filterSrv
.
idsByType
(
'time'
).
length
>
0
)
{
data
=
[[
_range
.
from
.
getTime
(),
null
],[
_range
.
to
.
getTime
(),
null
]];
//data = [];
}
var
query_results
=
results
.
facets
[
id
];
// we need to initialize the data variable on the first run,
// and when we are working on the first segment of the data.
if
(
_
.
isUndefined
(
$scope
.
data
[
i
])
||
segment
===
0
)
{
time_series
=
new
timeSeries
.
ZeroFilled
(
_interval
,
// range may be false
_range
&&
_range
.
from
,
_range
&&
_range
.
to
);
hits
=
0
;
}
else
{
data
=
$scope
.
data
[
i
].
data
;
time_series
=
$scope
.
data
[
i
].
time_series
;
hits
=
$scope
.
data
[
i
].
hits
;
}
// Assemble segments
var
segment_data
=
[];
_
.
each
(
v
.
entries
,
function
(
v
,
k
)
{
segment_data
.
push
([
v
.
time
,
v
[
$scope
.
panel
.
mode
]]);
hits
+=
v
.
count
;
// The series level hits counter
$scope
.
hits
+=
v
.
count
;
// Entire dataset level hits counter
// push each entry into the time series, while incrementing counters
_
.
each
(
query_results
.
entries
,
function
(
entry
)
{
time_series
.
addValue
(
entry
.
time
,
entry
[
$scope
.
panel
.
mode
]);
hits
+=
entry
.
count
;
// The series level hits counter
$scope
.
hits
+=
entry
.
count
;
// Entire dataset level hits counter
});
data
.
splice
.
apply
(
data
,[
1
,
0
].
concat
(
segment_data
));
// Join histogram data
// Create the flot series object
var
series
=
{
data
:
{
$scope
.
data
[
i
]
=
{
time_series
:
time_series
,
info
:
querySrv
.
list
[
id
],
data
:
data
,
data
:
time_series
.
getFlotPairs
()
,
hits
:
hits
},
};
$scope
.
data
[
i
]
=
series
.
data
;
i
++
;
});
...
...
@@ -203,10 +228,9 @@ angular.module('kibana.histogram', [])
$scope
.
$emit
(
'render'
);
// If we still have segments left, get them
if
(
_
segment
<
dashboard
.
indices
.
length
-
1
)
{
$scope
.
get_data
(
_
segment
+
1
,
query_id
);
if
(
segment
<
dashboard
.
indices
.
length
-
1
)
{
$scope
.
get_data
(
segment
+
1
,
query_id
);
}
}
});
};
...
...
@@ -372,8 +396,9 @@ angular.module('kibana.histogram', [])
function
tt
(
x
,
y
,
contents
)
{
// If the tool tip already exists, don't recreate it, just update it
var
tooltip
=
$
(
'#pie-tooltip'
).
length
?
$
(
'#pie-tooltip'
)
:
$
(
'<div id="pie-tooltip"></div>'
);
var
tooltip
=
$
(
'#pie-tooltip'
).
length
?
$
(
'#pie-tooltip'
)
:
$
(
'<div id="pie-tooltip"></div>'
);
tooltip
.
html
(
contents
).
css
({
position
:
'absolute'
,
...
...
@@ -411,4 +436,75 @@ angular.module('kibana.histogram', [])
});
}
};
})
.
service
(
'timeSeries'
,
function
()
{
/**
* Certain graphs require 0 entries to be specified for them to render
* properly (like the line graph). So with this we will caluclate all of
* the expected time measurements, and fill the missing ones in with 0
* @param date start The start time for the result set
* @param date end The end time for the result set
* @param integer interval The length between measurements, in es interval
* notation (1m, 30s, 1h, 15d)
*/
var
undef
;
function
base10Int
(
val
)
{
return
parseInt
(
val
,
10
);
}
this
.
ZeroFilled
=
function
(
interval
,
start
,
end
)
{
// the expected differenece between readings.
this
.
interval_ms
=
base10Int
(
kbn
.
interval_to_seconds
(
interval
))
*
1000
;
// will keep all values here, keyed by their time
this
.
_data
=
{};
if
(
start
)
{
this
.
addValue
(
start
,
null
);
}
if
(
end
)
{
this
.
addValue
(
end
,
null
);
}
}
/**
* Add a row
* @param int time The time for the value, in
* @param any value The value at this time
*/
this
.
ZeroFilled
.
prototype
.
addValue
=
function
(
time
,
value
)
{
if
(
time
instanceof
Date
)
{
time
=
Math
.
floor
(
time
.
getTime
()
/
1000
)
*
1000
;
}
else
{
time
=
base10Int
(
time
);
}
if
(
!
isNaN
(
time
))
{
this
.
_data
[
time
]
=
(
value
===
undef
?
0
:
value
);
}
};
/**
* return the rows in the format:
* [ [time, value], [time, value], ... ]
* @return array
*/
this
.
ZeroFilled
.
prototype
.
getFlotPairs
=
function
()
{
// var startTime = performance.now();
var
times
=
_
.
map
(
_
.
keys
(
this
.
_data
),
base10Int
).
sort
()
,
result
=
[]
,
i
,
next
,
expected_next
;
for
(
i
=
0
;
i
<
times
.
length
;
i
++
)
{
result
.
push
([
times
[
i
],
this
.
_data
[
times
[
i
]]
]);
next
=
times
[
i
+
1
];
expected_next
=
times
[
i
]
+
this
.
interval_ms
;
for
(;
times
.
length
>
i
&&
next
>
expected_next
;
expected_next
+=
this
.
interval_ms
)
{
/**
* since we don't know how the server will round subsequent segments
* we have to recheck for blanks each time.
*/
// this._data[expected_next] = 0;
result
.
push
([
expected_next
,
0
]);
}
}
// console.log(Math.round((performance.now() - startTime)*100)/100, 'ms to get', result.length, 'pairs');
return
result
;
};
});
\ 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