Skip to content

Commit

Permalink
Merge pull request #13 from f100024/feature/add-last-connection-times…
Browse files Browse the repository at this point in the history
…tamp

Minor fixes;
  • Loading branch information
f100024 authored Jun 2, 2021
2 parents 6106b56 + d173a3c commit 039a3ba
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
13 changes: 6 additions & 7 deletions collector/rest_stats_device.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,17 +162,16 @@ func (c *StatsDeviceResponse) Collect(ch chan<- prometheus.Metric) {
)
thetime, err := time.Parse(time.RFC3339, deviceDataAssertion["lastSeen"].(string))
if err != nil {
_ = level.Warn(*c.logger).Log(
"msg", "failed to parse timestamp",
"err", err,
)
return
_ = level.Warn(*c.logger).Log(
"msg", "failed to parse timestamp",
"err", err,
)
return
}
epoch := float64(thetime.Unix())
ch <- prometheus.MustNewConstMetric(
c.numericalMetrics["last_connection_timestamp"].Desc,
c.numericalMetrics["last_connection_timestamp"].Type,
c.numericalMetrics["last_connection_timestamp"].Value(epoch),
c.numericalMetrics["last_connection_timestamp"].Value(float64(thetime.Unix())),
deviceID,
)
}
Expand Down
6 changes: 3 additions & 3 deletions collector/rest_stats_device_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ func TestNewStatsDeviceReport(t *testing.T) {
syncthing_rest_stats_device_last_connection_duration{deviceID="AAAAAAA-AAAAAAA-AAAAAAA-AAAAAAA-AAAAAAA-AAAAAAA-AAAAAAA-CCCCCCC"} 0
# HELP syncthing_rest_stats_device_last_connection_timestamp Timestamp since last connection with remote device expressed in Unix epoch
# TYPE syncthing_rest_stats_device_last_connection_timestamp gauge
syncthing_rest_stats_device_last_connection_timestamp{deviceID="AAAAAAA-AAAAAAA-AAAAAAA-AAAAAAA-AAAAAAA-AAAAAAA-AAAAAAA-AAAAAAA"} 3407040050
syncthing_rest_stats_device_last_connection_timestamp{deviceID="AAAAAAA-AAAAAAA-AAAAAAA-AAAAAAA-AAAAAAA-AAAAAAA-AAAAAAA-BBBBBBB"} 3385540225
syncthing_rest_stats_device_last_connection_timestamp{deviceID="AAAAAAA-AAAAAAA-AAAAAAA-AAAAAAA-AAAAAAA-AAAAAAA-AAAAAAA-CCCCCCC"} 473385600
syncthing_rest_stats_device_last_connection_timestamp{deviceID="AAAAAAA-AAAAAAA-AAAAAAA-AAAAAAA-AAAAAAA-AAAAAAA-AAAAAAA-AAAAAAA"} 3.40704005e+09
syncthing_rest_stats_device_last_connection_timestamp{deviceID="AAAAAAA-AAAAAAA-AAAAAAA-AAAAAAA-AAAAAAA-AAAAAAA-AAAAAAA-BBBBBBB"} 3.385540225e+09
syncthing_rest_stats_device_last_connection_timestamp{deviceID="AAAAAAA-AAAAAAA-AAAAAAA-AAAAAAA-AAAAAAA-AAAAAAA-AAAAAAA-CCCCCCC"} 4.733856e+08
# HELP syncthing_rest_stats_device_total_scrapes Current total Syncthings scrapes.
# TYPE syncthing_rest_stats_device_total_scrapes counter
syncthing_rest_stats_device_total_scrapes 1
Expand Down

0 comments on commit 039a3ba

Please sign in to comment.