forked from cloudfoundry/guardian
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The two things that gather metrics (the debug server and the periodic Metron notifier) now take a map of metric keys to things that provide them. This is a prefactor before only enabling certain metrics when an image plugin is not configured. [#140552475] Signed-off-by: Craig Furman <[email protected]>
- Loading branch information
Showing
9 changed files
with
129 additions
and
452 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,77 +1,3 @@ | ||
package metrics | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"io/ioutil" | ||
"os/exec" | ||
"runtime" | ||
|
||
"code.cloudfoundry.org/lager" | ||
) | ||
|
||
//go:generate counterfeiter . Metrics | ||
|
||
type Metrics interface { | ||
NumCPU() int | ||
NumGoroutine() int | ||
LoopDevices() int | ||
BackingStores() int | ||
DepotDirs() int | ||
} | ||
|
||
type metrics struct { | ||
backingStoresPath string | ||
depotPath string | ||
logger lager.Logger | ||
} | ||
|
||
func NewMetrics(logger lager.Logger, backingStoresPath, depotPath string) Metrics { | ||
return &metrics{ | ||
backingStoresPath: backingStoresPath, | ||
depotPath: depotPath, | ||
logger: logger.Session("metrics"), | ||
} | ||
} | ||
|
||
func (m *metrics) NumCPU() int { | ||
return runtime.NumCPU() | ||
} | ||
|
||
func (m *metrics) NumGoroutine() int { | ||
return runtime.NumGoroutine() | ||
} | ||
|
||
func (m *metrics) LoopDevices() int { | ||
devices, err := exec.Command("losetup", "-a").CombinedOutput() | ||
if err != nil { | ||
m.logger.Error("cannot-get-loop-devices", fmt.Errorf("%s, out: %s", err, string(devices))) | ||
return -1 | ||
} | ||
return bytes.Count(devices, []byte("\n")) | ||
} | ||
|
||
func (m *metrics) BackingStores() int { | ||
if m.backingStoresPath == "" { | ||
// graph is disabled | ||
return -1 | ||
} | ||
|
||
entries, err := ioutil.ReadDir(m.backingStoresPath) | ||
if err != nil { | ||
m.logger.Error("cannot-get-backing-stores", err) | ||
return -1 | ||
} | ||
|
||
return len(entries) | ||
} | ||
|
||
func (m *metrics) DepotDirs() int { | ||
entries, err := ioutil.ReadDir(m.depotPath) | ||
if err != nil { | ||
m.logger.Error("cannot-get-depot-dirs", err) | ||
return -1 | ||
} | ||
|
||
return len(entries) | ||
} | ||
type Metrics map[string]func() int |
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,67 @@ | ||
package metrics | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"io/ioutil" | ||
"os/exec" | ||
"runtime" | ||
|
||
"code.cloudfoundry.org/lager" | ||
) | ||
|
||
type MetricsProvider struct { | ||
backingStoresPath string | ||
depotPath string | ||
logger lager.Logger | ||
} | ||
|
||
func NewMetricsProvider(logger lager.Logger, backingStoresPath, depotPath string) *MetricsProvider { | ||
return &MetricsProvider{ | ||
backingStoresPath: backingStoresPath, | ||
depotPath: depotPath, | ||
logger: logger.Session("metrics"), | ||
} | ||
} | ||
|
||
func (m *MetricsProvider) NumCPU() int { | ||
return runtime.NumCPU() | ||
} | ||
|
||
func (m *MetricsProvider) NumGoroutine() int { | ||
return runtime.NumGoroutine() | ||
} | ||
|
||
func (m *MetricsProvider) LoopDevices() int { | ||
devices, err := exec.Command("losetup", "-a").CombinedOutput() | ||
if err != nil { | ||
m.logger.Error("cannot-get-loop-devices", fmt.Errorf("%s, out: %s", err, string(devices))) | ||
return -1 | ||
} | ||
return bytes.Count(devices, []byte("\n")) | ||
} | ||
|
||
func (m *MetricsProvider) BackingStores() int { | ||
if m.backingStoresPath == "" { | ||
// graph is disabled | ||
return -1 | ||
} | ||
|
||
entries, err := ioutil.ReadDir(m.backingStoresPath) | ||
if err != nil { | ||
m.logger.Error("cannot-get-backing-stores", err) | ||
return -1 | ||
} | ||
|
||
return len(entries) | ||
} | ||
|
||
func (m *MetricsProvider) DepotDirs() int { | ||
entries, err := ioutil.ReadDir(m.depotPath) | ||
if err != nil { | ||
m.logger.Error("cannot-get-depot-dirs", err) | ||
return -1 | ||
} | ||
|
||
return len(entries) | ||
} |
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.