mirror of
				https://github.com/karl0ss/homepage.git
				synced 2025-10-30 22:13:59 +00:00 
			
		
		
		
	Enhancement: support for glances v4 (#3196)
This commit is contained in:
		
							parent
							
								
									4fe4ae9622
								
							
						
					
					
						commit
						def9b27006
					
				| @ -12,6 +12,7 @@ The Glances widget allows you to monitor the resources (CPU, memory, storage, te | |||||||
|     url: http://host.or.ip:port |     url: http://host.or.ip:port | ||||||
|     username: user # optional if auth enabled in Glances |     username: user # optional if auth enabled in Glances | ||||||
|     password: pass # optional if auth enabled in Glances |     password: pass # optional if auth enabled in Glances | ||||||
|  |     version: 4 # required only if running glances v4 or higher, defaults to 3 | ||||||
|     cpu: true # optional, enabled by default, disable by setting to false |     cpu: true # optional, enabled by default, disable by setting to false | ||||||
|     mem: true # optional, enabled by default, disable by setting to false |     mem: true # optional, enabled by default, disable by setting to false | ||||||
|     cputemp: true # disabled by default |     cputemp: true # disabled by default | ||||||
|  | |||||||
| @ -17,6 +17,7 @@ widget: | |||||||
|   url: http://glances.host.or.ip:port |   url: http://glances.host.or.ip:port | ||||||
|   username: user # optional if auth enabled in Glances |   username: user # optional if auth enabled in Glances | ||||||
|   password: pass # optional if auth enabled in Glances |   password: pass # optional if auth enabled in Glances | ||||||
|  |   version: 4 # required only if running glances v4 or higher, defaults to 3 | ||||||
|   metric: cpu |   metric: cpu | ||||||
|   diskUnits: bytes # optional, bytes (default) or bbytes. Only applies to disk |   diskUnits: bytes # optional, bytes (default) or bbytes. Only applies to disk | ||||||
|   refreshInterval: 5000 # optional - in milliseconds, defaults to 1000 or more, depending on the metric |   refreshInterval: 5000 # optional - in milliseconds, defaults to 1000 or more, depending on the metric | ||||||
|  | |||||||
| @ -13,7 +13,7 @@ async function retrieveFromGlancesAPI(privateWidgetOptions, endpoint) { | |||||||
|     throw new Error(errorMessage); |     throw new Error(errorMessage); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   const apiUrl = `${url}/api/3/${endpoint}`; |   const apiUrl = `${url}/api/${privateWidgetOptions.version}/${endpoint}`; | ||||||
|   const headers = { |   const headers = { | ||||||
|     "Accept-Encoding": "application/json", |     "Accept-Encoding": "application/json", | ||||||
|   }; |   }; | ||||||
| @ -42,9 +42,10 @@ async function retrieveFromGlancesAPI(privateWidgetOptions, endpoint) { | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export default async function handler(req, res) { | export default async function handler(req, res) { | ||||||
|   const { index, cputemp: includeCpuTemp, uptime: includeUptime, disk: includeDisks } = req.query; |   const { index, cputemp: includeCpuTemp, uptime: includeUptime, disk: includeDisks, version } = req.query; | ||||||
| 
 | 
 | ||||||
|   const privateWidgetOptions = await getPrivateWidgetOptions("glances", index); |   const privateWidgetOptions = await getPrivateWidgetOptions("glances", index); | ||||||
|  |   privateWidgetOptions.version = version ?? 3; | ||||||
| 
 | 
 | ||||||
|   try { |   try { | ||||||
|     const cpuData = await retrieveFromGlancesAPI(privateWidgetOptions, "cpu"); |     const cpuData = await retrieveFromGlancesAPI(privateWidgetOptions, "cpu"); | ||||||
|  | |||||||
| @ -394,6 +394,7 @@ export function cleanServiceGroups(groups) { | |||||||
|           enableNowPlaying, |           enableNowPlaying, | ||||||
| 
 | 
 | ||||||
|           // glances
 |           // glances
 | ||||||
|  |           version, | ||||||
|           chart, |           chart, | ||||||
|           metric, |           metric, | ||||||
|           pointsLimit, |           pointsLimit, | ||||||
| @ -528,6 +529,7 @@ export function cleanServiceGroups(groups) { | |||||||
|           if (snapshotPath) cleanedService.widget.snapshotPath = snapshotPath; |           if (snapshotPath) cleanedService.widget.snapshotPath = snapshotPath; | ||||||
|         } |         } | ||||||
|         if (type === "glances") { |         if (type === "glances") { | ||||||
|  |           if (version) cleanedService.widget.version = version; | ||||||
|           if (metric) cleanedService.widget.metric = metric; |           if (metric) cleanedService.widget.metric = metric; | ||||||
|           if (chart !== undefined) { |           if (chart !== undefined) { | ||||||
|             cleanedService.widget.chart = chart; |             cleanedService.widget.chart = chart; | ||||||
|  | |||||||
| @ -16,15 +16,16 @@ const defaultInterval = 1000; | |||||||
| export default function Component({ service }) { | export default function Component({ service }) { | ||||||
|   const { t } = useTranslation(); |   const { t } = useTranslation(); | ||||||
|   const { widget } = service; |   const { widget } = service; | ||||||
|   const { chart, refreshInterval = defaultInterval, pointsLimit = defaultPointsLimit } = widget; |   const { chart, refreshInterval = defaultInterval, pointsLimit = defaultPointsLimit, version = 3 } = widget; | ||||||
| 
 | 
 | ||||||
|   const [dataPoints, setDataPoints] = useState(new Array(pointsLimit).fill({ value: 0 }, 0, pointsLimit)); |   const [dataPoints, setDataPoints] = useState(new Array(pointsLimit).fill({ value: 0 }, 0, pointsLimit)); | ||||||
| 
 | 
 | ||||||
|   const { data, error } = useWidgetAPI(service.widget, "cpu", { |   const { data, error } = useWidgetAPI(service.widget, "cpu", { | ||||||
|     refreshInterval: Math.max(defaultInterval, refreshInterval), |     refreshInterval: Math.max(defaultInterval, refreshInterval), | ||||||
|  |     version, | ||||||
|   }); |   }); | ||||||
| 
 | 
 | ||||||
|   const { data: quicklookData, error: quicklookError } = useWidgetAPI(service.widget, "quicklook"); |   const { data: quicklookData, error: quicklookError } = useWidgetAPI(service.widget, "quicklook", { version }); | ||||||
| 
 | 
 | ||||||
|   useEffect(() => { |   useEffect(() => { | ||||||
|     if (data) { |     if (data) { | ||||||
|  | |||||||
| @ -16,7 +16,7 @@ const defaultInterval = 1000; | |||||||
| export default function Component({ service }) { | export default function Component({ service }) { | ||||||
|   const { t } = useTranslation(); |   const { t } = useTranslation(); | ||||||
|   const { widget } = service; |   const { widget } = service; | ||||||
|   const { chart, refreshInterval = defaultInterval, pointsLimit = defaultPointsLimit } = widget; |   const { chart, refreshInterval = defaultInterval, pointsLimit = defaultPointsLimit, version = 3 } = widget; | ||||||
|   const [, diskName] = widget.metric.split(":"); |   const [, diskName] = widget.metric.split(":"); | ||||||
| 
 | 
 | ||||||
|   const [dataPoints, setDataPoints] = useState( |   const [dataPoints, setDataPoints] = useState( | ||||||
| @ -26,6 +26,7 @@ export default function Component({ service }) { | |||||||
| 
 | 
 | ||||||
|   const { data, error } = useWidgetAPI(service.widget, "diskio", { |   const { data, error } = useWidgetAPI(service.widget, "diskio", { | ||||||
|     refreshInterval: Math.max(defaultInterval, refreshInterval), |     refreshInterval: Math.max(defaultInterval, refreshInterval), | ||||||
|  |     version, | ||||||
|   }); |   }); | ||||||
| 
 | 
 | ||||||
|   const calculateRates = (d) => |   const calculateRates = (d) => | ||||||
|  | |||||||
| @ -11,12 +11,13 @@ const defaultInterval = 1000; | |||||||
| export default function Component({ service }) { | export default function Component({ service }) { | ||||||
|   const { t } = useTranslation(); |   const { t } = useTranslation(); | ||||||
|   const { widget } = service; |   const { widget } = service; | ||||||
|   const { chart, refreshInterval = defaultInterval } = widget; |   const { chart, refreshInterval = defaultInterval, version = 3 } = widget; | ||||||
|   const [, fsName] = widget.metric.split("fs:"); |   const [, fsName] = widget.metric.split("fs:"); | ||||||
|   const diskUnits = widget.diskUnits === "bbytes" ? "common.bbytes" : "common.bytes"; |   const diskUnits = widget.diskUnits === "bbytes" ? "common.bbytes" : "common.bytes"; | ||||||
| 
 | 
 | ||||||
|   const { data, error } = useWidgetAPI(widget, "fs", { |   const { data, error } = useWidgetAPI(widget, "fs", { | ||||||
|     refreshInterval: Math.max(defaultInterval, refreshInterval), |     refreshInterval: Math.max(defaultInterval, refreshInterval), | ||||||
|  |     version, | ||||||
|   }); |   }); | ||||||
| 
 | 
 | ||||||
|   if (error) { |   if (error) { | ||||||
|  | |||||||
| @ -16,13 +16,14 @@ const defaultInterval = 1000; | |||||||
| export default function Component({ service }) { | export default function Component({ service }) { | ||||||
|   const { t } = useTranslation(); |   const { t } = useTranslation(); | ||||||
|   const { widget } = service; |   const { widget } = service; | ||||||
|   const { chart, refreshInterval = defaultInterval, pointsLimit = defaultPointsLimit } = widget; |   const { chart, refreshInterval = defaultInterval, pointsLimit = defaultPointsLimit, version = 3 } = widget; | ||||||
|   const [, gpuName] = widget.metric.split(":"); |   const [, gpuName] = widget.metric.split(":"); | ||||||
| 
 | 
 | ||||||
|   const [dataPoints, setDataPoints] = useState(new Array(pointsLimit).fill({ a: 0, b: 0 }, 0, pointsLimit)); |   const [dataPoints, setDataPoints] = useState(new Array(pointsLimit).fill({ a: 0, b: 0 }, 0, pointsLimit)); | ||||||
| 
 | 
 | ||||||
|   const { data, error } = useWidgetAPI(widget, "gpu", { |   const { data, error } = useWidgetAPI(widget, "gpu", { | ||||||
|     refreshInterval: Math.max(defaultInterval, refreshInterval), |     refreshInterval: Math.max(defaultInterval, refreshInterval), | ||||||
|  |     version, | ||||||
|   }); |   }); | ||||||
| 
 | 
 | ||||||
|   useEffect(() => { |   useEffect(() => { | ||||||
|  | |||||||
| @ -74,14 +74,16 @@ const defaultSystemInterval = 30000; // This data (OS, hostname, distribution) i | |||||||
| 
 | 
 | ||||||
| export default function Component({ service }) { | export default function Component({ service }) { | ||||||
|   const { widget } = service; |   const { widget } = service; | ||||||
|   const { chart, refreshInterval = defaultInterval } = widget; |   const { chart, refreshInterval = defaultInterval, version = 3 } = widget; | ||||||
| 
 | 
 | ||||||
|   const { data: quicklookData, errorL: quicklookError } = useWidgetAPI(service.widget, "quicklook", { |   const { data: quicklookData, errorL: quicklookError } = useWidgetAPI(service.widget, "quicklook", { | ||||||
|     refreshInterval, |     refreshInterval, | ||||||
|  |     version, | ||||||
|   }); |   }); | ||||||
| 
 | 
 | ||||||
|   const { data: systemData, errorL: systemError } = useWidgetAPI(service.widget, "system", { |   const { data: systemData, errorL: systemError } = useWidgetAPI(service.widget, "system", { | ||||||
|     refreshInterval: defaultSystemInterval, |     refreshInterval: defaultSystemInterval, | ||||||
|  |     version, | ||||||
|   }); |   }); | ||||||
| 
 | 
 | ||||||
|   if (quicklookError) { |   if (quicklookError) { | ||||||
|  | |||||||
| @ -17,12 +17,13 @@ export default function Component({ service }) { | |||||||
|   const { t } = useTranslation(); |   const { t } = useTranslation(); | ||||||
|   const { widget } = service; |   const { widget } = service; | ||||||
|   const { chart } = widget; |   const { chart } = widget; | ||||||
|   const { refreshInterval = defaultInterval(chart), pointsLimit = defaultPointsLimit } = widget; |   const { refreshInterval = defaultInterval(chart), pointsLimit = defaultPointsLimit, version = 3 } = widget; | ||||||
| 
 | 
 | ||||||
|   const [dataPoints, setDataPoints] = useState(new Array(pointsLimit).fill({ value: 0 }, 0, pointsLimit)); |   const [dataPoints, setDataPoints] = useState(new Array(pointsLimit).fill({ value: 0 }, 0, pointsLimit)); | ||||||
| 
 | 
 | ||||||
|   const { data, error } = useWidgetAPI(service.widget, "mem", { |   const { data, error } = useWidgetAPI(service.widget, "mem", { | ||||||
|     refreshInterval: Math.max(defaultInterval(chart), refreshInterval), |     refreshInterval: Math.max(defaultInterval(chart), refreshInterval), | ||||||
|  |     version, | ||||||
|   }); |   }); | ||||||
| 
 | 
 | ||||||
|   useEffect(() => { |   useEffect(() => { | ||||||
|  | |||||||
| @ -17,7 +17,10 @@ export default function Component({ service }) { | |||||||
|   const { t } = useTranslation(); |   const { t } = useTranslation(); | ||||||
|   const { widget } = service; |   const { widget } = service; | ||||||
|   const { chart, metric } = widget; |   const { chart, metric } = widget; | ||||||
|   const { refreshInterval = defaultInterval(chart), pointsLimit = defaultPointsLimit } = widget; |   const { refreshInterval = defaultInterval(chart), pointsLimit = defaultPointsLimit, version = 3 } = widget; | ||||||
|  | 
 | ||||||
|  |   const rxKey = version === 3 ? "rx" : "bytes_recv"; | ||||||
|  |   const txKey = version === 3 ? "tx" : "bytes_sent"; | ||||||
| 
 | 
 | ||||||
|   const [, interfaceName] = metric.split(":"); |   const [, interfaceName] = metric.split(":"); | ||||||
| 
 | 
 | ||||||
| @ -25,6 +28,7 @@ export default function Component({ service }) { | |||||||
| 
 | 
 | ||||||
|   const { data, error } = useWidgetAPI(widget, "network", { |   const { data, error } = useWidgetAPI(widget, "network", { | ||||||
|     refreshInterval: Math.max(defaultInterval(chart), refreshInterval), |     refreshInterval: Math.max(defaultInterval(chart), refreshInterval), | ||||||
|  |     version, | ||||||
|   }); |   }); | ||||||
| 
 | 
 | ||||||
|   useEffect(() => { |   useEffect(() => { | ||||||
| @ -36,8 +40,8 @@ export default function Component({ service }) { | |||||||
|           const newDataPoints = [ |           const newDataPoints = [ | ||||||
|             ...prevDataPoints, |             ...prevDataPoints, | ||||||
|             { |             { | ||||||
|               a: (interfaceData.rx * 8) / interfaceData.time_since_update, |               a: (interfaceData[rxKey] * 8) / interfaceData.time_since_update, | ||||||
|               b: (interfaceData.tx * 8) / interfaceData.time_since_update, |               b: (interfaceData[txKey] * 8) / interfaceData.time_since_update, | ||||||
|             }, |             }, | ||||||
|           ]; |           ]; | ||||||
|           if (newDataPoints.length > pointsLimit) { |           if (newDataPoints.length > pointsLimit) { | ||||||
| @ -97,7 +101,7 @@ export default function Component({ service }) { | |||||||
| 
 | 
 | ||||||
|         <div className="text-xs opacity-75"> |         <div className="text-xs opacity-75"> | ||||||
|           {t("common.bitrate", { |           {t("common.bitrate", { | ||||||
|             value: (interfaceData.rx * 8) / interfaceData.time_since_update, |             value: (interfaceData[rxKey] * 8) / interfaceData.time_since_update, | ||||||
|             maximumFractionDigits: 0, |             maximumFractionDigits: 0, | ||||||
|           })}{" "} |           })}{" "} | ||||||
|           {t("docker.rx")} |           {t("docker.rx")} | ||||||
| @ -115,7 +119,7 @@ export default function Component({ service }) { | |||||||
|       <Block position="bottom-3 right-3"> |       <Block position="bottom-3 right-3"> | ||||||
|         <div className="text-xs opacity-75"> |         <div className="text-xs opacity-75"> | ||||||
|           {t("common.bitrate", { |           {t("common.bitrate", { | ||||||
|             value: (interfaceData.tx * 8) / interfaceData.time_since_update, |             value: (interfaceData[txKey] * 8) / interfaceData.time_since_update, | ||||||
|             maximumFractionDigits: 0, |             maximumFractionDigits: 0, | ||||||
|           })}{" "} |           })}{" "} | ||||||
|           {t("docker.tx")} |           {t("docker.tx")} | ||||||
|  | |||||||
| @ -22,10 +22,13 @@ const defaultInterval = 1000; | |||||||
| export default function Component({ service }) { | export default function Component({ service }) { | ||||||
|   const { t } = useTranslation(); |   const { t } = useTranslation(); | ||||||
|   const { widget } = service; |   const { widget } = service; | ||||||
|   const { chart, refreshInterval = defaultInterval } = widget; |   const { chart, refreshInterval = defaultInterval, version = 3 } = widget; | ||||||
|  | 
 | ||||||
|  |   const memoryInfoKey = version === 3 ? 0 : "data"; | ||||||
| 
 | 
 | ||||||
|   const { data, error } = useWidgetAPI(service.widget, "processlist", { |   const { data, error } = useWidgetAPI(service.widget, "processlist", { | ||||||
|     refreshInterval: Math.max(defaultInterval, refreshInterval), |     refreshInterval: Math.max(defaultInterval, refreshInterval), | ||||||
|  |     version, | ||||||
|   }); |   }); | ||||||
| 
 | 
 | ||||||
|   if (error) { |   if (error) { | ||||||
| @ -66,7 +69,7 @@ export default function Component({ service }) { | |||||||
|                 <div className="opacity-25 w-14 text-right">{item.cpu_percent.toFixed(1)}%</div> |                 <div className="opacity-25 w-14 text-right">{item.cpu_percent.toFixed(1)}%</div> | ||||||
|                 <div className="opacity-25 w-14 text-right"> |                 <div className="opacity-25 w-14 text-right"> | ||||||
|                   {t("common.bytes", { |                   {t("common.bytes", { | ||||||
|                     value: item.memory_info[0], |                     value: item.memory_info[memoryInfoKey], | ||||||
|                     maximumFractionDigits: 0, |                     maximumFractionDigits: 0, | ||||||
|                   })} |                   })} | ||||||
|                 </div> |                 </div> | ||||||
|  | |||||||
| @ -16,13 +16,14 @@ const defaultInterval = 1000; | |||||||
| export default function Component({ service }) { | export default function Component({ service }) { | ||||||
|   const { t } = useTranslation(); |   const { t } = useTranslation(); | ||||||
|   const { widget } = service; |   const { widget } = service; | ||||||
|   const { chart, refreshInterval = defaultInterval, pointsLimit = defaultPointsLimit } = widget; |   const { chart, refreshInterval = defaultInterval, pointsLimit = defaultPointsLimit, version = 3 } = widget; | ||||||
|   const [, sensorName] = widget.metric.split(":"); |   const [, sensorName] = widget.metric.split(":"); | ||||||
| 
 | 
 | ||||||
|   const [dataPoints, setDataPoints] = useState(new Array(pointsLimit).fill({ value: 0 }, 0, pointsLimit)); |   const [dataPoints, setDataPoints] = useState(new Array(pointsLimit).fill({ value: 0 }, 0, pointsLimit)); | ||||||
| 
 | 
 | ||||||
|   const { data, error } = useWidgetAPI(service.widget, "sensors", { |   const { data, error } = useWidgetAPI(service.widget, "sensors", { | ||||||
|     refreshInterval: Math.max(defaultInterval, refreshInterval), |     refreshInterval: Math.max(defaultInterval, refreshInterval), | ||||||
|  |     version, | ||||||
|   }); |   }); | ||||||
| 
 | 
 | ||||||
|   useEffect(() => { |   useEffect(() => { | ||||||
|  | |||||||
| @ -1,7 +1,7 @@ | |||||||
| import credentialedProxyHandler from "utils/proxy/handlers/credentialed"; | import credentialedProxyHandler from "utils/proxy/handlers/credentialed"; | ||||||
| 
 | 
 | ||||||
| const widget = { | const widget = { | ||||||
|   api: "{url}/api/3/{endpoint}", |   api: "{url}/api/{version}/{endpoint}", | ||||||
|   proxyHandler: credentialedProxyHandler, |   proxyHandler: credentialedProxyHandler, | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 shamoon
						shamoon