Skip to content
This repository has been archived by the owner on Feb 27, 2023. It is now read-only.

Commit

Permalink
add some supernode metrics
Browse files Browse the repository at this point in the history
Signed-off-by: yeya24 <[email protected]>
  • Loading branch information
yeya24 committed Aug 14, 2019
1 parent 13322ca commit 3dc9888
Show file tree
Hide file tree
Showing 22 changed files with 425 additions and 100 deletions.
4 changes: 2 additions & 2 deletions dfdaemon/constant/constant.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ const (
)

const (
// Namespace is the prefix of the metrics' name of dragonfly
// Namespace is the prefix of the metricsutils' name of dragonfly
Namespace = "dragonfly"
// Subsystem represents metrics for dfdaemon
// Subsystem represents metricsutils for dfdaemon
Subsystem = "dfdaemon"
)
2 changes: 1 addition & 1 deletion dfdaemon/handler/root_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ func New() *http.ServeMux {
s.HandleFunc("/args", getArgs)
s.HandleFunc("/env", getEnv)
s.HandleFunc("/debug/version", version.Handler)
s.HandleFunc("/metrics", promhttp.Handler().ServeHTTP)
s.HandleFunc("/metricsutils", promhttp.Handler().ServeHTTP)
return s
}
7 changes: 7 additions & 0 deletions docs/user_guide/metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ This doc contains all the metrics that Dragonfly components currently support. N
- dragonfly_supernode_http_request_duration_seconds{code, handler, method} - http request latency in seconds
- dragonfly_supernode_http_request_size_bytes{code, handler, method} - http request size in bytes
- dragonfly_supernode_http_response_size_bytes{code, handler, method} - http response size in bytes
- dragonfly_supernode_peers{hostname} - dragonfly peers
- dragonfly_supernode_tasks{taskid, cdnstatus} - dragonfly tasks
- dragonfly_supernode_dfgettasks{taskid, callsystem} - dragonfly dfget tasks
- dragonfly_supernode_daemon_dfgettasks{taskid, callsystem} - dragonfly current dfget tasks, which are called from dfdaemon
- dragonfly_supernode_schedule_duration_milliseconds{taskid} - duration for task scheduling in milliseconds
- dragonfly_supernode_trigger_cdn_total{} - total times of triggering cdn.
- dragonfly_supernode_trigger_cdn_failed_total{} - total failed times of triggering cdn.

## Dfdaemon

Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ require (
github.com/stretchr/testify v1.2.2
github.com/valyala/fasthttp v1.3.0
github.com/willf/bitset v0.0.0-20190228212526-18bd95f470f9
golang.org/x/net v0.0.0-20190620200207-3b0461eec859 // indirect
gopkg.in/gcfg.v1 v1.2.3
gopkg.in/mgo.v2 v2.0.0-20160818020120-3f83fa500528 // indirect
gopkg.in/warnings.v0 v0.1.2
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73r
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190522155817-f3200d17e092 h1:4QSRKanuywn15aTZvI/mIDEgPQpswuFndXpOj3rKEco=
golang.org/x/net v0.0.0-20190522155817-f3200d17e092/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859 h1:R/3boaszxrf1GEUWTVDzSKVwLmSJpwZ1yqXm8j0v2QI=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package util
package metricsutils

import (
"github.com/prometheus/client_golang/prometheus"
Expand All @@ -26,6 +26,7 @@ const (
)

// NewCounter will auto-register a Counter metric to prometheus default registry and return it.
// TODO(yeya24): Stop using default registry, add registry as a parameter instead.
func NewCounter(subsystem, name, help string, labels []string) *prometheus.CounterVec {
return promauto.NewCounterVec(
prometheus.CounterOpts{
Expand Down
5 changes: 5 additions & 0 deletions pkg/timeutils/time_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,8 @@ import (
func GetCurrentTimeMillis() int64 {
return time.Now().UnixNano() / time.Millisecond.Nanoseconds()
}

// GetCurrentTimeMillisFloat returns the time in millis for now in float64 format.
func GetCurrentTimeMillisFloat() float64 {
return float64(time.Now().UnixNano()) / float64(time.Millisecond.Nanoseconds())
}
4 changes: 2 additions & 2 deletions supernode/config/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ const (
)

const (
// SubsystemSupernode represents metrics from supernode
// SubsystemSupernode represents metricsutils from supernode
SubsystemSupernode = "supernode"
// SubsystemDfget represents metrics from dfget
// SubsystemDfget represents metricsutils from dfget
SubsystemDfget = "dfget"
)
33 changes: 32 additions & 1 deletion supernode/daemon/mgr/dfgettask/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ package dfgettask
import (
"context"
"fmt"
"github.com/dragonflyoss/Dragonfly/pkg/metricsutils"
"github.com/dragonflyoss/Dragonfly/supernode/config"

"github.com/dragonflyoss/Dragonfly/apis/types"
"github.com/dragonflyoss/Dragonfly/pkg/errortypes"
Expand All @@ -28,21 +30,39 @@ import (
dutil "github.com/dragonflyoss/Dragonfly/supernode/daemon/util"

"github.com/pkg/errors"
"github.com/prometheus/client_golang/prometheus"
)

var _ mgr.DfgetTaskMgr = &Manager{}

type metrics struct {
dfgetTasks *prometheus.GaugeVec
dfgetTasksDaemon *prometheus.GaugeVec
}

func newMetrics() *metrics {
return &metrics{
dfgetTasks: metricsutils.NewGauge(config.SubsystemSupernode, "dfgettasks",
"The number of dfget tasks", []string{"taskid", "callsystem"}),

dfgetTasksDaemon: metricsutils.NewGauge(config.SubsystemSupernode, "daemon_dfgettasks",
"The number of dfget tasks from dfdaemon", []string{"taskid", "callsystem"}),
}
}

// Manager is an implementation of the interface of DfgetTaskMgr.
type Manager struct {
dfgetTaskStore *dutil.Store
ptoc *syncmap.SyncMap
metrics *metrics
}

// NewManager returns a new Manager.
func NewManager() (*Manager, error) {
return &Manager{
dfgetTaskStore: dutil.NewStore(),
ptoc: syncmap.NewSyncMap(),
metrics: newMetrics(),
}, nil
}

Expand Down Expand Up @@ -73,6 +93,13 @@ func (dtm *Manager) Add(ctx context.Context, dfgetTask *types.DfGetTask) error {

dtm.ptoc.Add(generatePeerKey(dfgetTask.PeerID, dfgetTask.TaskID), dfgetTask.CID)
dtm.dfgetTaskStore.Put(key, dfgetTask)

if dfgetTask.Dfdaemon {
dtm.metrics.dfgetTasksDaemon.WithLabelValues(dfgetTask.TaskID, dfgetTask.CallSystem).Inc()
} else {
dtm.metrics.dfgetTasks.WithLabelValues(dfgetTask.TaskID, dfgetTask.CallSystem).Inc()
}

return nil
}

Expand Down Expand Up @@ -103,7 +130,11 @@ func (dtm *Manager) Delete(ctx context.Context, clientID, taskID string) error {
return err
}
dtm.ptoc.Delete(generatePeerKey(dfgetTask.PeerID, dfgetTask.TaskID))

if dfgetTask.Dfdaemon {
dtm.metrics.dfgetTasksDaemon.WithLabelValues(dfgetTask.TaskID, dfgetTask.CallSystem).Dec()
} else {
dtm.metrics.dfgetTasks.WithLabelValues(dfgetTask.TaskID, dfgetTask.CallSystem).Dec()
}
return dtm.dfgetTaskStore.Delete(key)
}

Expand Down
Loading

0 comments on commit 3dc9888

Please sign in to comment.