-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
metrics: collect the metrics of nydusd events
Collect the metrics of nydus daemon events, including INIT, RUNNING and DIED. Signed-off-by: Bin Tang <tangbin.bin@bytedance.com>
- Loading branch information
Showing
18 changed files
with
219 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* Copyright (c) 2022. Nydus Developers. All rights reserved. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package collector | ||
|
||
import "github.com/containerd/nydus-snapshotter/pkg/daemon/types" | ||
|
||
type Collector interface { | ||
Collect() | ||
} | ||
|
||
func CollectDaemonEvent(daemonID string, event string) error { | ||
GlobalDaemonEventCollector.Collect(daemonID, event) | ||
return nil | ||
} | ||
|
||
func CollectFsMetrics(m *types.FsMetrics, imageRef string) error { | ||
GlobalFsMetricsCollector.Collect(m, imageRef) | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* Copyright (c) 2022. Nydus Developers. All rights reserved. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package collector | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/containerd/nydus-snapshotter/pkg/metrics/data" | ||
) | ||
|
||
type DaemonEventCollector struct{} | ||
|
||
var GlobalDaemonEventCollector *DaemonEventCollector | ||
|
||
func init() { | ||
GlobalDaemonEventCollector = &DaemonEventCollector{} | ||
} | ||
|
||
func (d *DaemonEventCollector) Collect(daemonID string, event string) { | ||
data.NydusdEvent.WithLabelValues(daemonID, time.Now().Format("2006-01-02 15:04:05.000"), event).Inc() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright (c) 2022. Nydus Developers. All rights reserved. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package collector | ||
|
||
import ( | ||
"github.com/containerd/nydus-snapshotter/pkg/daemon/types" | ||
"github.com/containerd/nydus-snapshotter/pkg/metrics/data" | ||
"github.com/pkg/errors" | ||
) | ||
|
||
type FsMetricsCollector struct{} | ||
|
||
var GlobalFsMetricsCollector *FsMetricsCollector | ||
|
||
func init() { | ||
GlobalFsMetricsCollector = &FsMetricsCollector{} | ||
} | ||
|
||
func (f *FsMetricsCollector) Collect(m *types.FsMetrics, imageRef string) error { | ||
data.ReadCount.WithLabelValues(imageRef).Set(float64(m.DataRead)) | ||
data.OpenFdCount.WithLabelValues(imageRef).Set(float64(m.NrOpens)) | ||
data.OpenFdMaxCount.WithLabelValues(imageRef).Set(float64(m.NrMaxOpens)) | ||
data.LastFopTimestamp.WithLabelValues(imageRef).Set(float64(m.LastFopTp)) | ||
|
||
for _, h := range data.MetricHists { | ||
o, err := h.ToConstHistogram(m, imageRef) | ||
if err != nil { | ||
return errors.Wrapf(err, "failed to new const histogram for %s", h.Desc.String()) | ||
} | ||
h.Save(o) | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* Copyright (c) 2022. Nydus Developers. All rights reserved. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package data | ||
|
||
import "github.com/prometheus/client_golang/prometheus" | ||
|
||
var ( | ||
daemonIDLabel = "daemon_id" | ||
timeLabel = "time" | ||
eventLabel = "event" | ||
) | ||
|
||
var ( | ||
NydusdEvent = prometheus.NewCounterVec( | ||
prometheus.CounterOpts{ | ||
Name: "nydusd_lifetime_events", | ||
Help: "The lifetime events of nydus daemon.", | ||
}, | ||
[]string{daemonIDLabel, timeLabel, eventLabel}, | ||
) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* | ||
* Copyright (c) 2022. Nydus Developers. All rights reserved. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package exporter | ||
|
||
type Exporter interface { | ||
Export() | ||
} | ||
|
||
func FileExport() error { | ||
return GlobalFileExporter.Export() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.