Skip to content

Commit

Permalink
Fix SessionStats' current & cumulative stats
Browse files Browse the repository at this point in the history
  • Loading branch information
metalmatze committed Dec 18, 2016
1 parent 72e8b2b commit a7dc5e6
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 26 deletions.
22 changes: 15 additions & 7 deletions cmd/transmission-exporter/session_stats_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,6 @@ func (sc *SessionStatsCollector) Collect(ch chan<- prometheus.Metric) {
log.Printf("failed to get session stats: %v", err)
}

dur := time.Duration(stats.CurrentStats.SecondsActive) * time.Second
timestamp := time.Now().Add(-1 * dur).Unix()

ch <- prometheus.MustNewConstMetric(
sc.DownloadSpeed,
prometheus.GaugeValue,
Expand Down Expand Up @@ -143,24 +140,35 @@ func (sc *SessionStatsCollector) Collect(ch chan<- prometheus.Metric) {

types := []string{"current", "cumulative"}
for _, t := range types {
var stateStats transmission.SessionStateStats
if t == types[0] {
stateStats = stats.CurrentStats
} else {
stateStats = stats.CumulativeStats
}

ch <- prometheus.MustNewConstMetric(
sc.Downloaded,
prometheus.GaugeValue,
float64(stats.CurrentStats.DownloadedBytes),
float64(stateStats.DownloadedBytes),
t,
)
ch <- prometheus.MustNewConstMetric(
sc.Uploaded,
prometheus.GaugeValue,
float64(stats.CurrentStats.UploadedBytes),
float64(stateStats.UploadedBytes),
t,
)
ch <- prometheus.MustNewConstMetric(
sc.FilesAdded,
prometheus.GaugeValue,
float64(stats.CurrentStats.FilesAdded),
float64(stateStats.FilesAdded),
t,
)

dur := time.Duration(stateStats.SecondsActive) * time.Second
timestamp := time.Now().Add(-1 * dur).Unix()

ch <- prometheus.MustNewConstMetric(
sc.ActiveTime,
prometheus.GaugeValue,
Expand All @@ -170,7 +178,7 @@ func (sc *SessionStatsCollector) Collect(ch chan<- prometheus.Metric) {
ch <- prometheus.MustNewConstMetric(
sc.SessionCount,
prometheus.GaugeValue,
float64(stats.CurrentStats.SessionCount),
float64(stateStats.SessionCount),
t,
)
}
Expand Down
34 changes: 15 additions & 19 deletions session_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,20 @@ type (

// SessionStats contains information about the current & cumulative session
SessionStats struct {
DownloadSpeed int `json:"downloadSpeed"`
UploadSpeed int `json:"uploadSpeed"`
ActiveTorrentCount int `json:"activeTorrentCount"`
PausedTorrentCount int `json:"pausedTorrentCount"`
TorrentCount int `json:"torrentCount"`
CumulativeStats struct {
DownloadedBytes int `json:"downloadedBytes"`
UploadedBytes int `json:"uploadedBytes"`
FilesAdded int `json:"filesAdded"`
SecondsActive int `json:"secondsActive"`
SessionCount int `json:"sessionCount"`
} `json:"cumulative-stats"`
CurrentStats struct {
DownloadedBytes int `json:"downloadedBytes"`
UploadedBytes int `json:"uploadedBytes"`
FilesAdded int `json:"filesAdded"`
SecondsActive int `json:"secondsActive"`
SessionCount int `json:"sessionCount"`
} `json:"current-stats"`
DownloadSpeed int `json:"downloadSpeed"`
UploadSpeed int `json:"uploadSpeed"`
ActiveTorrentCount int `json:"activeTorrentCount"`
PausedTorrentCount int `json:"pausedTorrentCount"`
TorrentCount int `json:"torrentCount"`
CumulativeStats SessionStateStats `json:"cumulative-stats"`
CurrentStats SessionStateStats `json:"current-stats"`
}
// SessionStateStats contains current or cumulative session stats
SessionStateStats struct {
DownloadedBytes int `json:"downloadedBytes"`
UploadedBytes int `json:"uploadedBytes"`
FilesAdded int `json:"filesAdded"`
SecondsActive int `json:"secondsActive"`
SessionCount int `json:"sessionCount"`
}
)

0 comments on commit a7dc5e6

Please sign in to comment.