|
13 | 13 | func (sme *smbMetricsExporter) register() error {
|
14 | 14 | cols := []prometheus.Collector{
|
15 | 15 | sme.newSMBVersionsCollector(),
|
| 16 | + sme.newSMBActivityCollector(), |
16 | 17 | sme.newSMBSharesCollector(),
|
17 |
| - sme.newSMBLocksCollector(), |
18 | 18 | }
|
19 | 19 | for _, c := range cols {
|
20 | 20 | if err := sme.reg.Register(c); err != nil {
|
@@ -79,72 +79,88 @@ func (sme *smbMetricsExporter) newSMBVersionsCollector() prometheus.Collector {
|
79 | 79 | return col
|
80 | 80 | }
|
81 | 81 |
|
82 |
| -type smbSharesCollector struct { |
| 82 | +type smbActivityCollector struct { |
83 | 83 | smbCollector
|
84 | 84 | }
|
85 | 85 |
|
86 |
| -func (col *smbSharesCollector) Collect(ch chan<- prometheus.Metric) { |
87 |
| - total := 0 |
| 86 | +func (col *smbActivityCollector) Collect(ch chan<- prometheus.Metric) { |
| 87 | + totalSessions := 0 |
| 88 | + totalTreeCons := 0 |
| 89 | + totalConnectedUsers := 0 |
| 90 | + totalLockedFiles := 0 |
88 | 91 | smbInfo, err := NewUpdatedSMBInfo()
|
89 |
| - if err != nil { |
90 |
| - ch <- prometheus.MustNewConstMetric(col.dsc[1], |
91 |
| - prometheus.GaugeValue, float64(total)) |
92 |
| - return |
93 |
| - } |
94 |
| - serviceByMachine := smbInfo.MapServiceToMachines() |
95 |
| - for serviceID, machineToCount := range serviceByMachine { |
96 |
| - for machineID, count := range machineToCount { |
97 |
| - ch <- prometheus.MustNewConstMetric(col.dsc[0], |
98 |
| - prometheus.GaugeValue, |
99 |
| - float64(count), |
100 |
| - serviceID, |
101 |
| - machineID) |
102 |
| - total += count |
103 |
| - } |
| 92 | + if err == nil { |
| 93 | + totalSessions = smbInfo.TotalSessions() |
| 94 | + totalTreeCons = smbInfo.TotalTreeCons() |
| 95 | + totalConnectedUsers = smbInfo.TotalConnectedUsers() |
| 96 | + totalLockedFiles = smbInfo.TotalLockedFiles() |
104 | 97 | }
|
| 98 | + ch <- prometheus.MustNewConstMetric(col.dsc[0], |
| 99 | + prometheus.GaugeValue, float64(totalSessions)) |
| 100 | + |
105 | 101 | ch <- prometheus.MustNewConstMetric(col.dsc[1],
|
106 |
| - prometheus.GaugeValue, float64(total)) |
| 102 | + prometheus.GaugeValue, float64(totalTreeCons)) |
| 103 | + |
| 104 | + ch <- prometheus.MustNewConstMetric(col.dsc[2], |
| 105 | + prometheus.GaugeValue, float64(totalConnectedUsers)) |
| 106 | + |
| 107 | + ch <- prometheus.MustNewConstMetric(col.dsc[3], |
| 108 | + prometheus.GaugeValue, float64(totalLockedFiles)) |
107 | 109 | }
|
108 | 110 |
|
109 |
| -func (sme *smbMetricsExporter) newSMBSharesCollector() prometheus.Collector { |
110 |
| - col := &smbSharesCollector{} |
| 111 | +func (sme *smbMetricsExporter) newSMBActivityCollector() prometheus.Collector { |
| 112 | + col := &smbActivityCollector{} |
111 | 113 | col.sme = sme
|
112 | 114 | col.dsc = []*prometheus.Desc{
|
113 | 115 | prometheus.NewDesc(
|
114 |
| - collectorName("shares", "machine"), |
115 |
| - "Number of currently active shares by host-machine ip", |
116 |
| - []string{"service", "machine"}, nil), |
| 116 | + collectorName("sessions", "total"), |
| 117 | + "Number of currently active SMB sessions", |
| 118 | + []string{}, nil), |
| 119 | + |
| 120 | + prometheus.NewDesc( |
| 121 | + collectorName("tcon", "total"), |
| 122 | + "Number of currently active SMB tree-connections", |
| 123 | + []string{}, nil), |
117 | 124 |
|
118 | 125 | prometheus.NewDesc(
|
119 |
| - collectorName("shares", "total"), |
120 |
| - "Total number of currently active shares", |
| 126 | + collectorName("users", "total"), |
| 127 | + "Number of currently active SMB users", |
| 128 | + []string{}, nil), |
| 129 | + |
| 130 | + prometheus.NewDesc( |
| 131 | + collectorName("locks", "total"), |
| 132 | + "Number of currently active file-locks", |
121 | 133 | []string{}, nil),
|
122 | 134 | }
|
123 | 135 | return col
|
124 | 136 | }
|
125 | 137 |
|
126 |
| -type smbLocksCollector struct { |
| 138 | +type smbSharesCollector struct { |
127 | 139 | smbCollector
|
128 | 140 | }
|
129 | 141 |
|
130 |
| -func (col *smbLocksCollector) Collect(ch chan<- prometheus.Metric) { |
131 |
| - value := 0 |
132 |
| - smbInfo, err := NewUpdatedSMBInfo() |
133 |
| - if err == nil { |
134 |
| - value = smbInfo.TotalLockedFiles() |
| 142 | +func (col *smbSharesCollector) Collect(ch chan<- prometheus.Metric) { |
| 143 | + smbInfo, _ := NewUpdatedSMBInfo() |
| 144 | + serviceByMachine := smbInfo.MapServiceToMachines() |
| 145 | + for serviceID, machineToCount := range serviceByMachine { |
| 146 | + for machineID, count := range machineToCount { |
| 147 | + ch <- prometheus.MustNewConstMetric(col.dsc[0], |
| 148 | + prometheus.GaugeValue, |
| 149 | + float64(count), |
| 150 | + serviceID, |
| 151 | + machineID) |
| 152 | + } |
135 | 153 | }
|
136 |
| - ch <- prometheus.MustNewConstMetric(col.dsc[0], |
137 |
| - prometheus.GaugeValue, float64(value)) |
138 | 154 | }
|
139 | 155 |
|
140 |
| -func (sme *smbMetricsExporter) newSMBLocksCollector() prometheus.Collector { |
141 |
| - col := &smbLocksCollector{} |
| 156 | +func (sme *smbMetricsExporter) newSMBSharesCollector() prometheus.Collector { |
| 157 | + col := &smbSharesCollector{} |
142 | 158 | col.sme = sme
|
143 | 159 | col.dsc = []*prometheus.Desc{
|
144 | 160 | prometheus.NewDesc(
|
145 |
| - collectorName("locks", "total"), |
146 |
| - "Total number of active locks", |
147 |
| - []string{}, nil), |
| 161 | + collectorName("shares", "machine"), |
| 162 | + "Number of currently active shares by host-machine ip", |
| 163 | + []string{"service", "machine"}, nil), |
148 | 164 | }
|
149 | 165 | return col
|
150 | 166 | }
|
|
0 commit comments