martabal / qbittorrent-exporter

A fast and lightweight prometheus exporter for qBittorrent
MIT License
20 stars 1 forks source link

cannot unmarshal integers #77

Closed erdincsk closed 3 weeks ago

erdincsk commented 3 weeks ago

Hello,

I'm running qbittorrent-exporter on rpi with os as you can see the details below.

rpi@rpi:~/logs $ lsb_release -a No LSB modules are available. Distributor ID: Debian Description: Debian GNU/Linux 12 (bookworm) Release: 12 Codename: bookworm rpi@rpi:~/logs $ uname -a Linux rpi 6.6.51+rpt-rpi-2712 #1 SMP PREEMPT Debian 1:6.6.51-1+rpt2 (2024-10-01) aarch64 GNU/Linux

while running exporter I had integer errors such as

[2024-10-03 13:06:23] DEBUG json: cannot unmarshal number 171526531416 into Go struct field .server_state.dl_info_data of type int
[2024-10-03 13:06:23] ERROR Can not unmarshal JSON for maindata
[2024-10-03 13:06:08] DEBUG json: cannot unmarshal number 14989532172 into Go struct field .downloaded of type int
[2024-10-03 13:06:08] ERROR Can not unmarshal JSON for info

I think the reason was my torrents download size was too big for int type.

than I edited qbittorent.go files and changed those variables from int to int64,

Downloaded        int64     `json:"downloaded"`
DownloadedSession int64     `json:"downloaded_session"`
Size              int64    `json:"size"`
Uploaded          int64     `json:"uploaded"`
UploadedSession   int64     `json:"uploaded_session"`
AlltimeDl         int64 `json:"alltime_dl"`
AlltimeUl         int64 `json:"alltime_ul"`
DlInfoData        int64    `json:"dl_info_data"`
UpInfoData        int64    `json:"up_info_data"`

i also edited prometheus.go and changed the conversions for related variables.

        infoLabels := prometheus.Labels{
            "name":               torrent.Name,
            "category":           torrent.Category,
            "state":              torrent.State,
            "size":               strconv.FormatInt(torrent.Size, 10),
            "progress":           strconv.Itoa(int(torrent.Progress)),
            "seeders":            strconv.Itoa(torrent.NumSeeds),
            "leechers":           strconv.Itoa(torrent.NumLeechs),
            "dl_speed":           strconv.Itoa(torrent.Dlspeed),
            "up_speed":           strconv.Itoa(torrent.Upspeed),
            "amount_left":        strconv.FormatInt(torrent.AmountLeft, 10), // Dönüştürülen kısım
            "time_active":        strconv.Itoa(torrent.TimeActive),
            "eta":                strconv.Itoa(torrent.Eta),
            "uploaded":           strconv.FormatInt(torrent.Uploaded, 10), // Dönüştürülen kısım
            "uploaded_session":   strconv.FormatInt(torrent.UploadedSession, 10), // Dönüştürülen kısım
            "downloaded":         strconv.FormatInt(torrent.Downloaded, 10), // Dönüştürülen kısım
            "downloaded_session": strconv.FormatInt(torrent.DownloadedSession, 10), // Dönüştürülen kısım
            "max_ratio":          strconv.FormatFloat(torrent.MaxRatio, 'f', 3, 64),
            "ratio":              strconv.FormatFloat(torrent.Ratio, 'f', 3, 64),
            "tracker":            torrent.Tracker,
        }

after these changes and I could run exporter.

I'm not a professional developer so I could not create a pull request for you. I jus did all changes with the help of chatgpt :) ı just want to inform the issue. maybe you can make the necessary changes in source code. thanks.

martabal commented 3 weeks ago

Hey :wave:

Thanks for the report !