after testing i removed the unnecessary sub-collector

Signed-off-by: Andrey Burtasov <BurtasovAA@GSP-I.RU>
This commit is contained in:
Andrey Burtasov 2023-11-28 09:11:59 +03:00
parent 61ec692534
commit f62077014f
1 changed files with 5 additions and 29 deletions

View File

@ -45,7 +45,6 @@ type collector struct {
// All available collector functions // All available collector functions
var smbAllCollectorNames = []string{ var smbAllCollectorNames = []string{
"ServerShares", "ServerShares",
"ServerSessions",
} }
func New(logger log.Logger, config *Config) types.Collector { func New(logger log.Logger, config *Config) types.Collector {
@ -86,7 +85,6 @@ func (c *collector) SetLogger(logger log.Logger) {
func (c *collector) GetPerfCounter() ([]string, error) { func (c *collector) GetPerfCounter() ([]string, error) {
return []string{ return []string{
"SMB Server Sessions",
"SMB Server Shares", "SMB Server Shares",
}, nil }, nil
} }
@ -103,13 +101,12 @@ func (c *collector) Build() error {
} }
c.CurrentOpenFileCount = desc("server_shares_current_open_file_count", "Current total count open files on the SMB Server") c.CurrentOpenFileCount = desc("server_shares_current_open_file_count", "Current total count open files on the SMB Server")
c.TreeConnectCount = desc("server_session_tree_connect_count", "Tree connect count to SMB Server") c.TreeConnectCount = desc("server_shares_tree_connect_count", "Tree connect count to SMB Server")
c.enabledCollectors = make([]string, 0, len(smbAllCollectorNames)) c.enabledCollectors = make([]string, 0, len(smbAllCollectorNames))
collectorDesc := map[string]string{ collectorDesc := map[string]string{
"ServerShares": "SMB Server Shares", "ServerShares": "SMB Server Shares",
"ServerSessions": "SMB Server Sessions",
} }
if *c.smbListAllCollectors { if *c.smbListAllCollectors {
@ -140,8 +137,7 @@ func (c *collector) Build() error {
// Collect collects smb metrics and sends them to prometheus // Collect collects smb metrics and sends them to prometheus
func (c *collector) Collect(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error { func (c *collector) Collect(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
collectorFuncs := map[string]func(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error{ collectorFuncs := map[string]func(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error{
"ServerShares": c.collectServerShares, "ServerShares": c.collectServerShares,
"ServerSessions": c.collectServerSessions,
} }
for _, collectorName := range c.enabledCollectors { for _, collectorName := range c.enabledCollectors {
@ -158,6 +154,7 @@ type perflibServerShares struct {
Name string Name string
CurrentOpenFileCount float64 `perflib:"Current Open File Count"` CurrentOpenFileCount float64 `perflib:"Current Open File Count"`
TreeConnectCount float64 `perflib:"Tree Connect Count"`
} }
func (c *collector) collectServerShares(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error { func (c *collector) collectServerShares(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
@ -177,33 +174,12 @@ func (c *collector) collectServerShares(ctx *types.ScrapeContext, ch chan<- prom
instance.CurrentOpenFileCount, instance.CurrentOpenFileCount,
) )
}
return nil
}
// Perflib: SMB Server Sessions
type perflibServerSession struct {
Name string
TreeConnectCount float64 `perflib:"Tree Connect Count"`
}
func (c *collector) collectServerSessions(ctx *types.ScrapeContext, ch chan<- prometheus.Metric) error {
var data []perflibServerSession
if err := perflib.UnmarshalObject(ctx.PerfObjects["SMB Server Sessions"], &data, c.logger); err != nil {
return err
}
for _, instance := range data {
labelName := c.toLabelName(instance.Name)
if !strings.HasSuffix(labelName, "_total") {
continue
}
ch <- prometheus.MustNewConstMetric( ch <- prometheus.MustNewConstMetric(
c.TreeConnectCount, c.TreeConnectCount,
prometheus.CounterValue, prometheus.CounterValue,
instance.TreeConnectCount, instance.TreeConnectCount,
) )
} }
return nil return nil
} }