kopia lustrzana https://github.com/bugout-dev/moonstream
useQuery for Status page
rodzic
1534230b75
commit
1b1169882e
Plik diff jest za duży
Load Diff
|
@ -30,18 +30,12 @@ const Status = () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const {
|
const {
|
||||||
apiServerStatus,
|
apiServerStatusCache,
|
||||||
apiServerData,
|
ethereumClusterServerStatusCache,
|
||||||
crawlersServerStatus,
|
gethStatusCache,
|
||||||
crawlersServerData,
|
crawlersStatusCache,
|
||||||
gethStatus,
|
dbServerStatusCache,
|
||||||
gethData,
|
latestBlockDBStatusCache,
|
||||||
crawlersStatus,
|
|
||||||
crawlersData,
|
|
||||||
dbServerStatus,
|
|
||||||
dbServerData,
|
|
||||||
latestBlockDBStatus,
|
|
||||||
latestBlockDBData,
|
|
||||||
} = useStatus();
|
} = useStatus();
|
||||||
|
|
||||||
const [background, setBackground] = useState("background720");
|
const [background, setBackground] = useState("background720");
|
||||||
|
@ -63,13 +57,6 @@ const Status = () => {
|
||||||
]);
|
]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
apiServerStatus();
|
|
||||||
crawlersServerStatus();
|
|
||||||
crawlersStatus();
|
|
||||||
gethStatus();
|
|
||||||
dbServerStatus();
|
|
||||||
latestBlockDBStatus();
|
|
||||||
|
|
||||||
assets[
|
assets[
|
||||||
"background720"
|
"background720"
|
||||||
] = `${AWS_ASSETS_PATH}/product-background-720x405.png`;
|
] = `${AWS_ASSETS_PATH}/product-background-720x405.png`;
|
||||||
|
@ -175,12 +162,14 @@ const Status = () => {
|
||||||
<Spacer />
|
<Spacer />
|
||||||
<Text
|
<Text
|
||||||
color={
|
color={
|
||||||
apiServerData?.data?.status == "ok"
|
!apiServerStatusCache.isLoading &&
|
||||||
|
apiServerStatusCache?.data?.status == "ok"
|
||||||
? healthyStatusColor
|
? healthyStatusColor
|
||||||
: downStatusColor
|
: downStatusColor
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
{apiServerData?.data?.status == "ok"
|
{!apiServerStatusCache.isLoading &&
|
||||||
|
apiServerStatusCache?.data?.status == "ok"
|
||||||
? healthyStatusText
|
? healthyStatusText
|
||||||
: downStatusText}
|
: downStatusText}
|
||||||
</Text>
|
</Text>
|
||||||
|
@ -191,12 +180,14 @@ const Status = () => {
|
||||||
<Spacer />
|
<Spacer />
|
||||||
<Text
|
<Text
|
||||||
color={
|
color={
|
||||||
crawlersServerData?.data?.status == "ok"
|
!ethereumClusterServerStatusCache.isLoading &&
|
||||||
|
ethereumClusterServerStatusCache?.data?.status == "ok"
|
||||||
? healthyStatusColor
|
? healthyStatusColor
|
||||||
: downStatusColor
|
: downStatusColor
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
{crawlersServerData?.data?.status == "ok"
|
{!ethereumClusterServerStatusCache.isLoading &&
|
||||||
|
ethereumClusterServerStatusCache?.data
|
||||||
? healthyStatusText
|
? healthyStatusText
|
||||||
: downStatusText}
|
: downStatusText}
|
||||||
</Text>
|
</Text>
|
||||||
|
@ -205,15 +196,21 @@ const Status = () => {
|
||||||
<Text>Latest block in Geth</Text>
|
<Text>Latest block in Geth</Text>
|
||||||
<Spacer />
|
<Spacer />
|
||||||
<Text>
|
<Text>
|
||||||
{gethData?.data?.current_block ? gethData.data.current_block : 0}
|
{!gethStatusCache.isLoading &&
|
||||||
|
gethStatusCache?.data?.current_block
|
||||||
|
? gethStatusCache.data.current_block
|
||||||
|
: 0}
|
||||||
</Text>
|
</Text>
|
||||||
</Flex>
|
</Flex>
|
||||||
<Flex mb={3}>
|
<Flex mb={3}>
|
||||||
<Text>Txpool latest record ts</Text>
|
<Text>Txpool latest record ts</Text>
|
||||||
<Spacer />
|
<Spacer />
|
||||||
<Text>
|
<Text>
|
||||||
{crawlersData?.data?.ethereum_txpool_timestamp
|
{!crawlersStatusCache.isLoading &&
|
||||||
? shortTimestamp(crawlersData?.data?.ethereum_txpool_timestamp)
|
crawlersStatusCache?.data?.ethereum_txpool_timestamp
|
||||||
|
? shortTimestamp(
|
||||||
|
crawlersStatusCache?.data?.ethereum_txpool_timestamp
|
||||||
|
)
|
||||||
: downStatusText}
|
: downStatusText}
|
||||||
</Text>
|
</Text>
|
||||||
</Flex>
|
</Flex>
|
||||||
|
@ -221,9 +218,10 @@ const Status = () => {
|
||||||
<Text>Trending latest record ts</Text>
|
<Text>Trending latest record ts</Text>
|
||||||
<Spacer />
|
<Spacer />
|
||||||
<Text>
|
<Text>
|
||||||
{crawlersData?.data?.ethereum_trending_timestamp
|
{!crawlersStatusCache.isLoading &&
|
||||||
|
crawlersStatusCache?.data?.ethereum_trending_timestamp
|
||||||
? shortTimestamp(
|
? shortTimestamp(
|
||||||
crawlersData?.data?.ethereum_trending_timestamp
|
crawlersStatusCache?.data?.ethereum_trending_timestamp
|
||||||
)
|
)
|
||||||
: downStatusText}
|
: downStatusText}
|
||||||
</Text>
|
</Text>
|
||||||
|
@ -234,12 +232,14 @@ const Status = () => {
|
||||||
<Spacer />
|
<Spacer />
|
||||||
<Text
|
<Text
|
||||||
color={
|
color={
|
||||||
dbServerData?.data?.status == "ok"
|
!dbServerStatusCache.isLoading &&
|
||||||
|
dbServerStatusCache?.data?.status == "ok"
|
||||||
? healthyStatusColor
|
? healthyStatusColor
|
||||||
: downStatusColor
|
: downStatusColor
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
{dbServerData?.data?.status == "ok"
|
{!dbServerStatusCache.isLoading &&
|
||||||
|
dbServerStatusCache?.data?.status == "ok"
|
||||||
? healthyStatusText
|
? healthyStatusText
|
||||||
: downStatusText}
|
: downStatusText}
|
||||||
</Text>
|
</Text>
|
||||||
|
@ -248,8 +248,9 @@ const Status = () => {
|
||||||
<Text>Latest block in Database</Text>
|
<Text>Latest block in Database</Text>
|
||||||
<Spacer />
|
<Spacer />
|
||||||
<Text>
|
<Text>
|
||||||
{latestBlockDBData?.data?.block_number
|
{!latestBlockDBStatusCache.isLoading &&
|
||||||
? latestBlockDBData.data.block_number
|
latestBlockDBStatusCache?.data?.block_number
|
||||||
|
? latestBlockDBStatusCache.data.block_number
|
||||||
: 0}
|
: 0}
|
||||||
</Text>
|
</Text>
|
||||||
</Flex>
|
</Flex>
|
||||||
|
|
|
@ -1,90 +1,67 @@
|
||||||
import { useMutation } from "react-query";
|
import { useQuery } from "react-query";
|
||||||
import { useToast } from "./";
|
import { queryCacheProps } from "./hookCommon";
|
||||||
import { AuthService } from "../../core/services";
|
import { StatusService } from "../../core/services";
|
||||||
|
|
||||||
const useStatus = () => {
|
const useStatus = () => {
|
||||||
const toast = useToast();
|
const getAPIServerStatus = async () => {
|
||||||
|
const response = await StatusService.apiServerStatus();
|
||||||
|
return response.data;
|
||||||
|
};
|
||||||
|
const getEthereumClusterServerStatus = async () => {
|
||||||
|
const response = await StatusService.ethereumClusterServerStatus();
|
||||||
|
return response.data;
|
||||||
|
};
|
||||||
|
const getGethStatus = async () => {
|
||||||
|
const response = await StatusService.gethStatus();
|
||||||
|
return response.data;
|
||||||
|
};
|
||||||
|
const getCrawlersStatus = async () => {
|
||||||
|
const response = await StatusService.crawlersStatus();
|
||||||
|
return response.data;
|
||||||
|
};
|
||||||
|
const getDBServerStatus = async () => {
|
||||||
|
const response = await StatusService.dbServerStatus();
|
||||||
|
return response.data;
|
||||||
|
};
|
||||||
|
const getLatestBlockDBStatus = async () => {
|
||||||
|
const response = await StatusService.latestBlockDBStatus();
|
||||||
|
return response.data;
|
||||||
|
};
|
||||||
|
|
||||||
const { mutate: apiServerStatus, data: apiServerData } = useMutation(
|
const apiServerStatusCache = useQuery("apiServer", getAPIServerStatus, {
|
||||||
AuthService.apiServerStatus,
|
...queryCacheProps,
|
||||||
{
|
|
||||||
onError: (error) => {
|
|
||||||
// toast(error, "error");
|
|
||||||
},
|
|
||||||
onSuccess: () => {
|
|
||||||
// toast("Status received", "success");
|
|
||||||
},
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
const { mutate: crawlersServerStatus, data: crawlersServerData } =
|
|
||||||
useMutation(AuthService.crawlersServerStatus, {
|
|
||||||
onError: (error) => {
|
|
||||||
// toast(error, "error");
|
|
||||||
},
|
|
||||||
onSuccess: () => {
|
|
||||||
// toast("Status received", "success");
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
const { mutate: gethStatus, data: gethData } = useMutation(
|
const ethereumClusterServerStatusCache = useQuery(
|
||||||
AuthService.gethStatus,
|
"ethereumClusterServer",
|
||||||
|
getEthereumClusterServerStatus,
|
||||||
{
|
{
|
||||||
onError: (error) => {
|
...queryCacheProps,
|
||||||
// toast(error, "error");
|
|
||||||
},
|
|
||||||
onSuccess: () => {
|
|
||||||
// toast("Status received", "success");
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
const { mutate: crawlersStatus, data: crawlersData } = useMutation(
|
const gethStatusCache = useQuery("geth", getGethStatus, {
|
||||||
AuthService.crawlersStatus,
|
...queryCacheProps,
|
||||||
|
});
|
||||||
|
const crawlersStatusCache = useQuery("crawlers", getCrawlersStatus, {
|
||||||
|
...queryCacheProps,
|
||||||
|
});
|
||||||
|
const dbServerStatusCache = useQuery("dbServer", getDBServerStatus, {
|
||||||
|
...queryCacheProps,
|
||||||
|
});
|
||||||
|
const latestBlockDBStatusCache = useQuery(
|
||||||
|
"latestBlockDB",
|
||||||
|
getLatestBlockDBStatus,
|
||||||
{
|
{
|
||||||
onError: (error) => {
|
...queryCacheProps,
|
||||||
// toast(error, "error");
|
|
||||||
},
|
|
||||||
onSuccess: () => {
|
|
||||||
// toast("Status received", "success");
|
|
||||||
},
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
const { mutate: dbServerStatus, data: dbServerData } = useMutation(
|
|
||||||
AuthService.dbServerStatus,
|
|
||||||
{
|
|
||||||
onError: (error) => {
|
|
||||||
// toast(error, "error");
|
|
||||||
},
|
|
||||||
onSuccess: () => {
|
|
||||||
// toast("Status received", "success");
|
|
||||||
},
|
|
||||||
}
|
|
||||||
);
|
|
||||||
const { mutate: latestBlockDBStatus, data: latestBlockDBData } = useMutation(
|
|
||||||
AuthService.latestBlockDBStatus,
|
|
||||||
{
|
|
||||||
onError: (error) => {
|
|
||||||
// toast(error, "error");
|
|
||||||
},
|
|
||||||
onSuccess: () => {
|
|
||||||
// toast("Status received", "success");
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
apiServerStatus,
|
apiServerStatusCache,
|
||||||
apiServerData,
|
ethereumClusterServerStatusCache,
|
||||||
crawlersServerStatus,
|
gethStatusCache,
|
||||||
crawlersServerData,
|
crawlersStatusCache,
|
||||||
gethStatus,
|
dbServerStatusCache,
|
||||||
gethData,
|
latestBlockDBStatusCache,
|
||||||
crawlersStatus,
|
|
||||||
crawlersData,
|
|
||||||
dbServerStatus,
|
|
||||||
dbServerData,
|
|
||||||
latestBlockDBStatus,
|
|
||||||
latestBlockDBData,
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
import { http } from "../utils";
|
import { http } from "../utils";
|
||||||
|
|
||||||
const API_URL = process.env.NEXT_PUBLIC_MOONSTREAM_API_URL;
|
const API_URL = process.env.NEXT_PUBLIC_MOONSTREAM_API_URL;
|
||||||
const DB_URL = process.env.NEXT_PUBLIC_MOONSTREAM_DB_URL;
|
|
||||||
const CRAWLERS_URL = process.env.NEXT_PUBLIC_MOONSTREAM_ETHEREUM_CLUSTER_URL;
|
|
||||||
export const AUTH_URL = `${API_URL}/users`;
|
export const AUTH_URL = `${API_URL}/users`;
|
||||||
|
|
||||||
export const login = ({ username, password, token_note }) => {
|
export const login = ({ username, password, token_note }) => {
|
||||||
|
@ -103,45 +101,3 @@ export const revokeToken = (token) => {
|
||||||
url: `${AUTH_URL}/revoke/${token}`,
|
url: `${AUTH_URL}/revoke/${token}`,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export const apiServerStatus = () => {
|
|
||||||
return http({
|
|
||||||
method: "GET",
|
|
||||||
url: `${API_URL}/ping`,
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
export const crawlersServerStatus = () => {
|
|
||||||
return http({
|
|
||||||
method: "GET",
|
|
||||||
url: `${CRAWLERS_URL}/ping`,
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
export const gethStatus = () => {
|
|
||||||
return http({
|
|
||||||
method: "GET",
|
|
||||||
url: `${CRAWLERS_URL}/status`,
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
export const crawlersStatus = () => {
|
|
||||||
return http({
|
|
||||||
method: "GET",
|
|
||||||
url: `${API_URL}/status`,
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
export const dbServerStatus = () => {
|
|
||||||
return http({
|
|
||||||
method: "GET",
|
|
||||||
url: `${DB_URL}/ping`,
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
export const latestBlockDBStatus = () => {
|
|
||||||
return http({
|
|
||||||
method: "GET",
|
|
||||||
url: `${DB_URL}/block/latest`,
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ import * as GroupService from "./group.service";
|
||||||
import * as PreferencesService from "./preferences.service";
|
import * as PreferencesService from "./preferences.service";
|
||||||
import * as HumbugService from "./humbug.service";
|
import * as HumbugService from "./humbug.service";
|
||||||
import * as InvitesService from "./invites.service";
|
import * as InvitesService from "./invites.service";
|
||||||
|
import * as StatusService from "./status.service";
|
||||||
import * as SubscriptionsService from "./subscriptions.service";
|
import * as SubscriptionsService from "./subscriptions.service";
|
||||||
import * as StreamService from "./stream.service";
|
import * as StreamService from "./stream.service";
|
||||||
import * as TxInfoService from "./txinfo.service";
|
import * as TxInfoService from "./txinfo.service";
|
||||||
|
@ -18,6 +19,7 @@ export {
|
||||||
PreferencesService,
|
PreferencesService,
|
||||||
HumbugService,
|
HumbugService,
|
||||||
InvitesService,
|
InvitesService,
|
||||||
|
StatusService,
|
||||||
SubscriptionsService,
|
SubscriptionsService,
|
||||||
StreamService,
|
StreamService,
|
||||||
TxInfoService,
|
TxInfoService,
|
||||||
|
|
|
@ -0,0 +1,48 @@
|
||||||
|
import { http } from "../utils";
|
||||||
|
|
||||||
|
const API_URL = process.env.NEXT_PUBLIC_MOONSTREAM_API_URL;
|
||||||
|
const DB_URL = process.env.NEXT_PUBLIC_MOONSTREAM_DB_URL;
|
||||||
|
const ETHEREUM_CLUSTER_URL =
|
||||||
|
process.env.NEXT_PUBLIC_MOONSTREAM_ETHEREUM_CLUSTER_URL;
|
||||||
|
|
||||||
|
export const apiServerStatus = () => {
|
||||||
|
return http({
|
||||||
|
method: "GET",
|
||||||
|
url: `${API_URL}/ping`,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export const ethereumClusterServerStatus = () => {
|
||||||
|
return http({
|
||||||
|
method: "GET",
|
||||||
|
url: `${ETHEREUM_CLUSTER_URL}/ping`,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export const gethStatus = () => {
|
||||||
|
return http({
|
||||||
|
method: "GET",
|
||||||
|
url: `${ETHEREUM_CLUSTER_URL}/status`,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export const crawlersStatus = () => {
|
||||||
|
return http({
|
||||||
|
method: "GET",
|
||||||
|
url: `${API_URL}/status`,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export const dbServerStatus = () => {
|
||||||
|
return http({
|
||||||
|
method: "GET",
|
||||||
|
url: `${DB_URL}/ping`,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export const latestBlockDBStatus = () => {
|
||||||
|
return http({
|
||||||
|
method: "GET",
|
||||||
|
url: `${DB_URL}/block/latest`,
|
||||||
|
});
|
||||||
|
};
|
Ładowanie…
Reference in New Issue