Added Nextcloud Monitoring

This commit is contained in:
Philippe-Adrien Nousse 2018-07-31 13:24:20 +02:00
parent 95e6d9a705
commit d3af949035
4 changed files with 99 additions and 5 deletions

16
monitoring.go Normal file
View File

@ -0,0 +1,16 @@
package gonextcloud
import (
"github.com/partitio/gonextcloud/types"
"net/http"
)
func (c *Client) Monitoring() (*types.Monitoring, error) {
res, err := c.baseRequest(routes.monitor, "", "", nil, http.MethodGet)
if err != nil {
return nil, err
}
var m types.MonitoringResponse
res.JSON(&m)
return &m.Ocs.Data, nil
}

View File

@ -8,16 +8,18 @@ type Routes struct {
users *url.URL
groups *url.URL
apps *url.URL
monitor *url.URL
}
const badRequest = 998
var (
apiPath = &url.URL{Path: "/ocs/v1.php/cloud"}
apiPath = &url.URL{Path: "/ocs/v1.php"}
routes = Routes{
capabilities: &url.URL{Path: apiPath.Path + "/capabilities"},
users: &url.URL{Path: apiPath.Path + "/users"},
groups: &url.URL{Path: apiPath.Path + "/groups"},
apps: &url.URL{Path: apiPath.Path + "/apps"},
capabilities: &url.URL{Path: apiPath.Path + "/cloud/capabilities"},
users: &url.URL{Path: apiPath.Path + "/cloud/users"},
groups: &url.URL{Path: apiPath.Path + "/cloud/groups"},
apps: &url.URL{Path: apiPath.Path + "/cloud/apps"},
monitor: &url.URL{Path: apiPath.Path + "/apps/serverinfo/api/v1/info"},
}
)

65
types/monitoring.go Normal file
View File

@ -0,0 +1,65 @@
package types
type System struct {
Version string `json:"version"`
Theme string `json:"theme"`
EnableAvatars string `json:"enable_avatars"`
EnablePreviews string `json:"enable_previews"`
MemcacheLocal string `json:"memcache.local"`
MemcacheDistributed string `json:"memcache.distributed"`
FilelockingEnabled string `json:"filelocking.enabled"`
MemcacheLocking string `json:"memcache.locking"`
Debug string `json:"debug"`
Freespace int64 `json:"freespace"`
Cpuload []float32 `json:"cpuload"`
MemTotal int `json:"mem_total"`
MemFree int `json:"mem_free"`
SwapTotal int `json:"swap_total"`
SwapFree int `json:"swap_free"`
}
type Monitoring struct {
Nextcloud struct {
System System `json:"system"`
Storage Storage `json:"storage"`
Shares struct {
NumShares int `json:"num_shares"`
NumSharesUser int `json:"num_shares_user"`
NumSharesGroups int `json:"num_shares_groups"`
NumSharesLink int `json:"num_shares_link"`
NumSharesLinkNoPassword int `json:"num_shares_link_no_password"`
NumFedSharesSent int `json:"num_fed_shares_sent"`
NumFedSharesReceived int `json:"num_fed_shares_received"`
} `json:"shares"`
} `json:"nextcloud"`
Server struct {
Webserver string `json:"webserver"`
Php struct {
Version string `json:"version"`
MemoryLimit int `json:"memory_limit"`
MaxExecutionTime int `json:"max_execution_time"`
UploadMaxFilesize int `json:"upload_max_filesize"`
} `json:"php"`
Database struct {
Type string `json:"type"`
Version string `json:"version"`
Size int `json:"size"`
} `json:"database"`
} `json:"server"`
ActiveUsers ActiveUsers `json:"activeUsers"`
}
type ActiveUsers struct {
Last5Minutes int `json:"last5minutes"`
Last1Hour int `json:"last1hour"`
Last24Hours int `json:"last24hours"`
}
type Storage struct {
NumUsers int `json:"num_users"`
NumFiles int `json:"num_files"`
NumStorages int `json:"num_storages"`
NumStoragesLocal int `json:"num_storages_local"`
NumStoragesHome int `json:"num_storages_home"`
NumStoragesOther int `json:"num_storages_other"`
}

View File

@ -87,3 +87,14 @@ type CapabilitiesResponse struct {
} `json:"data"`
} `json:"ocs"`
}
type MonitoringResponse struct {
Ocs struct {
Meta struct {
Status string `json:"status"`
Statuscode int `json:"statuscode"`
Message string `json:"message"`
} `json:"meta"`
Data Monitoring `json:"data"`
} `json:"ocs"`
}