Skip to content

Commit

Permalink
Show metrics about installed apps and updates (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
xperimental authored Jan 21, 2021
1 parent 9a3107c commit 5d05bde
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
run.sh
nextcloud-exporter
nextcloud-exporter.yml
config.yml
dist/
16 changes: 16 additions & 0 deletions collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ var (
metricPrefix+"system_info",
"Contains meta information about Nextcloud as labels. Value is always 1.",
[]string{"version"}, nil)
appsInstalledDesc = prometheus.NewDesc(
metricPrefix+"apps_installed_total",
"Number of currently installed apps",
nil, nil)
appsUpdatesDesc = prometheus.NewDesc(
metricPrefix+"apps_updates_available_total",
"Number of apps that have available updates",
nil, nil)
usersDesc = prometheus.NewDesc(
metricPrefix+"users_total",
"Number of users of the instance.",
Expand Down Expand Up @@ -187,6 +195,14 @@ func collectSimpleMetrics(ch chan<- prometheus.Metric, status serverinfo.ServerI
desc *prometheus.Desc
value float64
}{
{
desc: appsInstalledDesc,
value: float64(status.Data.Nextcloud.System.Apps.Installed),
},
{
desc: appsUpdatesDesc,
value: float64(status.Data.Nextcloud.System.Apps.AvailableUpdates),
},
{
desc: usersDesc,
value: float64(status.Data.Nextcloud.Storage.Users),
Expand Down
10 changes: 9 additions & 1 deletion serverinfo/serverinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ type System struct {
FilelockingEnabled bool `xml:"filelocking.enabled"`
Debug bool `xml:"debug"`
FreeSpace int64 `xml:"freespace"`
// <cpuload>
Apps Apps `xml:"apps"`
}

const boolYes = "yes"
Expand All @@ -63,6 +63,7 @@ func (s *System) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
FilelockingEnabled string `xml:"filelocking.enabled"`
Debug string `xml:"debug"`
FreeSpace int64 `xml:"freespace"`
Apps Apps `xml:"apps"`
}
if err := d.DecodeElement(&raw, &start); err != nil {
return err
Expand All @@ -77,9 +78,16 @@ func (s *System) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
s.FilelockingEnabled = raw.FilelockingEnabled == boolYes
s.Debug = raw.Debug == boolYes
s.FreeSpace = raw.FreeSpace
s.Apps = raw.Apps
return nil
}

// Apps contains information about installed apps and updates.
type Apps struct {
Installed uint `xml:"num_installed"`
AvailableUpdates uint `xml:"num_updates_available"`
}

// Storage contains information about the nextcloud storage system.
type Storage struct {
Users uint `xml:"num_users"`
Expand Down

0 comments on commit 5d05bde

Please sign in to comment.