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
8bccbdaf
Commit
8bccbdaf
authored
Dec 21, 2016
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(live): minor progress on stream manager
parent
b7827962
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
101 additions
and
0 deletions
+101
-0
pkg/api/live/stream_manager.go
+74
-0
pkg/models/streams.go
+27
-0
No files found.
pkg/api/live/stream_manager.go
0 → 100644
View file @
8bccbdaf
package
live
import
(
"sync"
"github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/log"
m
"github.com/grafana/grafana/pkg/models"
)
type
StreamManagerImpl
struct
{
log
log
.
Logger
streams
map
[
string
]
*
Stream
streamRWMutex
*
sync
.
RWMutex
}
func
NewStreamManager
()
m
.
StreamManager
{
return
&
StreamManagerImpl
{
log
:
log
.
New
(
"live.stream.manager"
),
streams
:
make
(
map
[
string
]
*
Stream
),
streamRWMutex
:
&
sync
.
RWMutex
{},
}
}
func
(
s
*
StreamManagerImpl
)
GetStreamList
()
m
.
StreamList
{
list
:=
make
(
m
.
StreamList
,
0
)
for
_
,
stream
:=
range
s
.
streams
{
list
=
append
(
list
,
&
m
.
StreamInfo
{
Name
:
stream
.
name
,
})
}
return
list
}
func
(
s
*
StreamManagerImpl
)
Push
(
packet
*
m
.
StreamPacket
)
{
stream
,
exist
:=
s
.
streams
[
packet
.
Stream
]
if
!
exist
{
s
.
log
.
Info
(
"Creating metric stream"
,
"name"
,
packet
.
Stream
)
stream
=
NewStream
(
packet
.
Stream
)
s
.
streams
[
stream
.
name
]
=
stream
}
stream
.
Push
(
packet
)
}
type
Stream
struct
{
subscribers
[]
*
connection
name
string
}
func
NewStream
(
name
string
)
*
Stream
{
return
&
Stream
{
subscribers
:
make
([]
*
connection
,
0
),
name
:
name
,
}
}
func
(
s
*
Stream
)
Push
(
packet
*
m
.
StreamPacket
)
{
messageBytes
,
_
:=
simplejson
.
NewFromAny
(
packet
)
.
Encode
()
for
_
,
sub
:=
range
s
.
subscribers
{
// check if channel is open
// if _, ok := h.connections[sub]; !ok {
// delete(s.subscribers, sub)
// continue
// }
sub
.
send
<-
messageBytes
}
}
pkg/models/streams.go
0 → 100644
View file @
8bccbdaf
package
models
import
"gopkg.in/guregu/null.v3"
type
TimePoint
[
2
]
null
.
Float
type
TimeSeriesPoints
[]
TimePoint
type
StreamPacket
struct
{
Stream
string
`json:"stream"`
Series
[]
StreamSeries
`json:"series"`
}
type
StreamSeries
struct
{
Name
string
`json:"name"`
Points
TimeSeriesPoints
`json:"points"`
}
type
StreamInfo
struct
{
Name
string
}
type
StreamList
[]
*
StreamInfo
type
StreamManager
interface
{
GetStreamList
()
StreamList
Push
(
data
*
StreamPacket
)
}
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