mirror of
				https://github.com/karl0ss/homepage.git
				synced 2025-11-04 00:10:57 +00:00 
			
		
		
		
	Merge pull request #1056 from tristo7/prometheus-widget
add prometheus service widget
This commit is contained in:
		
						commit
						102ce2b1fe
					
				@ -521,5 +521,10 @@
 | 
			
		||||
    "pterodactyl": {
 | 
			
		||||
        "servers": "Servers",
 | 
			
		||||
        "nodes": "Nodes"
 | 
			
		||||
    },
 | 
			
		||||
    "prometheus": {
 | 
			
		||||
        "targets_up": "Targets Up",
 | 
			
		||||
        "targets_down": "Targets Down",
 | 
			
		||||
        "targets_total": "Total Targets"
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -75,6 +75,7 @@ const components = {
 | 
			
		||||
  xteve: dynamic(() => import("./xteve/component")),
 | 
			
		||||
  immich: dynamic(() => import("./immich/component")),
 | 
			
		||||
  uptimekuma: dynamic(() => import("./uptimekuma/component")),
 | 
			
		||||
  prometheus: dynamic(() => import("./prometheus/component")),
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
export default components;
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										38
									
								
								src/widgets/prometheus/component.jsx
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										38
									
								
								src/widgets/prometheus/component.jsx
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,38 @@
 | 
			
		||||
import { useTranslation } from "next-i18next";
 | 
			
		||||
 | 
			
		||||
import Container from "components/services/widget/container";
 | 
			
		||||
import Block from "components/services/widget/block";
 | 
			
		||||
import useWidgetAPI from "utils/proxy/use-widget-api";
 | 
			
		||||
 | 
			
		||||
export default function Component({ service }) {
 | 
			
		||||
  const { t } = useTranslation();
 | 
			
		||||
 | 
			
		||||
  const { widget } = service;
 | 
			
		||||
  const { data: targetsData, error: targetsError } = useWidgetAPI(widget, "targets");
 | 
			
		||||
 | 
			
		||||
  if (targetsError) {
 | 
			
		||||
    return <Container error={targetsError} />;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  if (!targetsData) {
 | 
			
		||||
    return (
 | 
			
		||||
      <Container service={service}>
 | 
			
		||||
        <Block label="prometheus.targets_up" />
 | 
			
		||||
        <Block label="prometheus.targets_down" />
 | 
			
		||||
        <Block label="prometheus.targets_total" />
 | 
			
		||||
      </Container>
 | 
			
		||||
    );
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  const upCount = targetsData.data.activeTargets.filter(a => a.health === "up").length;
 | 
			
		||||
  const downCount = targetsData.data.activeTargets.filter(a => a.health === "down").length;
 | 
			
		||||
  const totalCount = targetsData.data.activeTargets.length;
 | 
			
		||||
 | 
			
		||||
  return (
 | 
			
		||||
    <Container service={service}>
 | 
			
		||||
      <Block label="prometheus.targets_up" value={t("common.number", { value: upCount })} />
 | 
			
		||||
      <Block label="prometheus.targets_down" value={t("common.number", { value: downCount })} />
 | 
			
		||||
      <Block label="prometheus.targets_total" value={t("common.number", { value: totalCount })} />
 | 
			
		||||
    </Container>
 | 
			
		||||
  );
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										17
									
								
								src/widgets/prometheus/widget.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								src/widgets/prometheus/widget.js
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,17 @@
 | 
			
		||||
import genericProxyHandler from "utils/proxy/handlers/generic";
 | 
			
		||||
 | 
			
		||||
const widget = {
 | 
			
		||||
  api: "{url}/api/v1/{endpoint}",
 | 
			
		||||
  proxyHandler: genericProxyHandler,
 | 
			
		||||
 | 
			
		||||
  mappings: {
 | 
			
		||||
    targets: {
 | 
			
		||||
      endpoint: "targets",
 | 
			
		||||
      validate: [
 | 
			
		||||
        "data"
 | 
			
		||||
      ]
 | 
			
		||||
    },
 | 
			
		||||
  },
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
export default widget;
 | 
			
		||||
@ -69,6 +69,7 @@ import xteve from "./xteve/widget";
 | 
			
		||||
import immich from "./immich/widget";
 | 
			
		||||
import uptimekuma from "./uptimekuma/widget";
 | 
			
		||||
import unmanic from "./unmanic/widget";
 | 
			
		||||
import prometheus from "./prometheus/widget";
 | 
			
		||||
 | 
			
		||||
const widgets = {
 | 
			
		||||
  adguard,
 | 
			
		||||
@ -144,6 +145,7 @@ const widgets = {
 | 
			
		||||
  xteve,
 | 
			
		||||
  immich,
 | 
			
		||||
  uptimekuma,
 | 
			
		||||
  prometheus
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
export default widgets;
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user