@@ -48,7 +48,7 @@ func New() *Chrony {
4848 Protocol : chronyDefaultProtocol ,
4949 Address : chronyDefaultCmdAddr ,
5050 SentryConfig : sentry.ClientOptions {},
51- Timeout : 1000 ,
51+ Timeout : 500 ,
5252 },
5353 charts : & charts ,
5454 latestSource : net .IPv4zero ,
@@ -80,7 +80,7 @@ func (c *Chrony) Init() bool {
8080 }
8181
8282 c .conn = conn
83- return true
83+ return c . ApplyChronyVersion () == nil
8484}
8585
8686// Check makes check
@@ -105,42 +105,25 @@ func (c *Chrony) Charts() *Charts {
105105func (c * Chrony ) Collect () map [string ]int64 {
106106 // collect all we need and sent Exception to sentry
107107 res := map [string ]int64 {"running" : 0 }
108+ var err error
108109
109- if ! c .Running () {
110- return res
111- }
112- res ["running" ] = 1
113-
114- tra := c .collectTracking ()
115- for k , v := range tra {
116- res [k ] = v
110+ err = c .collectTracking (res )
111+ if err != nil {
112+ c .Errorf ("fetch tracking status failed: %s" , err )
117113 }
118114
119- act : = c .collectActivity ()
120- for k , v := range act {
121- res [ k ] = v
115+ err = c .collectActivity (res )
116+ if err != nil {
117+ c . Errorf ( "fetch activity status failed: %s" , err )
122118 }
123119
124120 return res
125121}
126122
127- func (c * Chrony ) Running () bool {
128- err := c .SubmitEmptyRequest ()
129- if err != nil {
130- c .Errorf ("contract chrony failed with err: %s" , err )
131- return false
132- }
133- return true
134- }
135-
136- func (c * Chrony ) collectTracking () (res map [string ]int64 ) {
137- res = make (map [string ]int64 )
123+ func (c * Chrony ) collectTracking (res map [string ]int64 ) error {
138124 tracking , err := c .FetchTracking ()
139125 if err != nil {
140- c .Errorf ("fetch tracking status failed: %s" , err )
141126 sentry .CaptureException ((FetchingChronyError )(err .Error ()))
142- res ["running" ] = 0
143- return
144127 }
145128 c .Debugf (tracking .String ())
146129
@@ -154,8 +137,9 @@ func (c *Chrony) collectTracking() (res map[string]int64) {
154137 res ["last_offset" ] = (int64 )(tracking .LastOffset .Int64 ())
155138 res ["rms_offset" ] = (int64 )(tracking .RmsOffset .Int64 ())
156139 res ["update_interval" ] = (int64 )(tracking .LastUpdateInterval .Int64 ())
157- res ["current_correction" ] = (int64 )(tracking .LastUpdateInterval .Int64 ())
140+ res ["current_correction" ] = (int64 )(tracking .CurrentCorrection .Int64 ())
158141 res ["ref_timestamp" ] = tracking .RefTime .Time ().Unix ()
142+ res ["residual_frequency" ] = (int64 )(tracking .ResidFreqPpm .Int64 ())
159143
160144 sourceIp := tracking .Ip .Ip ()
161145
@@ -206,18 +190,14 @@ func (c *Chrony) collectTracking() (res map[string]int64) {
206190 sentry .CaptureException ((OutOfSyncForTooLong )(rt ))
207191 }
208192
209- return
193+ return nil
210194}
211195
212- func (c * Chrony ) collectActivity () (res map [string ]int64 ) {
213- res = make (map [string ]int64 )
196+ func (c * Chrony ) collectActivity (res map [string ]int64 ) error {
214197 activity , err := c .FetchActivity ()
215198 if err != nil {
216- c .Errorf ("fetch activity status failed: %s" , err )
217199 sentry .CaptureException ((FetchingChronyError )(err .Error ()))
218- return
219200 }
220- c .Debug (activity .String ())
221201
222202 res ["online_sources" ] = int64 (activity .Online )
223203 res ["offline_sources" ] = int64 (activity .Offline )
@@ -229,5 +209,5 @@ func (c *Chrony) collectActivity() (res map[string]int64) {
229209 c .Debugf ("sending sentry error for NoSourceOnlineError: %g" , activity .Online )
230210 sentry .CaptureException ((NoSourceOnlineError )(activity .Online ))
231211 }
232- return res
212+ return nil
233213}
0 commit comments