feat: new version dashboard
This commit is contained in:
@@ -25,5 +25,5 @@ EXPOSE 5000
|
||||
HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
|
||||
CMD curl -f http://localhost:5000/health || exit 1
|
||||
|
||||
# Run application
|
||||
CMD ["gunicorn", "--bind", "0.0.0.0:5000", "--workers", "4", "--timeout", "120", "app:app"]
|
||||
# Run application with single worker to allow background threads
|
||||
CMD ["gunicorn", "--bind", "0.0.0.0:5000", "--workers", "1", "--timeout", "120", "app:app"]
|
||||
|
||||
@@ -12,8 +12,9 @@ FLASK_PORT=5000
|
||||
FLASK_HOST=0.0.0.0
|
||||
DEBUG=False
|
||||
|
||||
# Refresh interval (seconds)
|
||||
REFRESH_INTERVAL=30
|
||||
# Refresh intervals (seconds)
|
||||
TICKETS_REFRESH_INTERVAL=5
|
||||
DASHBOARD_REFRESH_INTERVAL=60
|
||||
|
||||
# Queue IDs (comma-separated)
|
||||
QUEUE_IDS=-1,1,2,3,4,5,7
|
||||
|
||||
@@ -41,6 +41,7 @@ services:
|
||||
volumes:
|
||||
- grafana-storage:/var/lib/grafana
|
||||
- ./grafana/provisioning:/etc/grafana/provisioning:ro
|
||||
- ./grafana/images:/usr/share/grafana/public/img/custom:ro
|
||||
networks:
|
||||
- monitoring
|
||||
restart: unless-stopped
|
||||
|
||||
0
grafana/images/.gitkeep
Normal file
0
grafana/images/.gitkeep
Normal file
15
grafana/images/svg/branco-cinza.svg
Executable file
15
grafana/images/svg/branco-cinza.svg
Executable file
@@ -0,0 +1,15 @@
|
||||
<svg width="680" height="49" viewBox="0 0 680 49" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="M102.713 1.90782H65.6562C65.6562 1.90782 56.2328 1.50498 56.2328 10.1555V39.4147C56.2328 39.4147 56.8918 48.2772 65.4146 48.2772H102.713V39.4147H69.3026C69.3026 39.4147 64.8435 37.9729 64.8435 35.1106V27.605H93.6189V18.0216H65.173C65.173 18.0216 63.6793 10.1555 67.8089 10.1555H102.713V1.90782Z" fill="white"/>
|
||||
<path d="M159.099 15.3308C159.099 5.42928 148.028 1.9097 148.028 1.9097H115.782V49H124.217L124.393 27.4585H137.463L148.709 48.3003H159.121L149.039 26.992C149.039 26.992 159.121 25.2322 159.121 15.3308H159.099ZM144.294 18.9139H124.701V9.58493H144.294C146.974 9.58493 149.127 11.684 149.127 14.2494C149.127 16.8149 146.952 18.9139 144.294 18.9139Z" fill="white"/>
|
||||
<path d="M34.0692 0.954516H0V47.8964H9.0939V27.1393H34.0692C34.0692 27.1393 43.4926 24.5951 43.4926 13.8879C43.4926 3.18076 34.0692 0.954516 34.0692 0.954516ZM30.1373 19.0401H10.5437V9.71106H30.1373C32.8171 9.71106 34.9698 11.8101 34.9698 14.3756C34.9698 16.941 32.7952 19.0401 30.1373 19.0401Z" fill="white"/>
|
||||
<path d="M324.152 29.8532L285.118 0.954516V48.2144H294.234V20.4394L333.421 48.9989V0.954516H323.998L324.152 29.8532Z" fill="white"/>
|
||||
<path d="M341.68 48.9985L366.502 0L392.795 48.9985H380.231L366.985 21.0751L352.597 48.9985H341.68Z" fill="white"/>
|
||||
<path d="M459.945 0H449.687V48.9985H459.945V0Z" fill="white"/>
|
||||
<path d="M500.868 10.6224L470.95 48.2989H519.89V39.5H491.115L518.177 4.91902L518.287 1.67507H470.95V10.7709L500.868 10.6224Z" fill="white"/>
|
||||
<path d="M578.451 2.26913H541.395C541.395 2.26913 531.971 1.86628 531.971 10.5168V39.776C531.971 39.776 532.63 48.6385 541.153 48.6385H578.451V39.776H545.041C545.041 39.776 540.582 38.3342 540.582 35.4719V27.9663H569.357V18.3829H540.912C540.912 18.3829 539.418 10.5168 543.547 10.5168H578.451V2.26913Z" fill="white"/>
|
||||
<path d="M398.748 1.67507H408.018V33.6905C408.018 33.6905 407.974 36.0864 409.138 37.5494C410.302 39.0123 412.652 39.2879 412.652 39.2879H438.133V48.2989H410.851C410.851 48.2989 407.425 48.1293 403.295 45.1822C400.461 43.1468 399.275 40.8145 398.88 39.3939C398.748 38.9063 398.704 38.4186 398.704 37.931L398.792 1.67507H398.748Z" fill="white"/>
|
||||
<path d="M251.005 1.18915C237.496 1.18915 226.557 11.7479 226.557 24.7873C226.557 37.8267 237.496 48.3855 251.005 48.3855C264.514 48.3855 275.453 37.8267 275.453 24.7873C275.453 11.7479 264.492 1.18915 251.005 1.18915ZM251.005 39.1201C242.592 39.1201 235.782 32.5473 235.782 24.4269C235.782 16.3064 242.592 9.73368 251.005 9.73368C259.418 9.73368 266.227 16.3064 266.227 24.4269C266.227 32.5473 259.418 39.1201 251.005 39.1201Z" fill="white"/>
|
||||
<path d="M171.466 33.7559V36.6606C171.466 36.6606 172.345 47.5586 181.68 47.5586H205.008C205.008 47.5586 216.914 45.1627 216.914 34.1587C216.914 23.1547 205.162 19.4019 205.162 19.4019H182.998C182.998 19.4019 178.869 18.681 178.869 14.2074C178.869 9.73368 183.745 8.86438 183.745 8.86438H204.086C204.086 8.86438 207.974 9.73368 207.974 13.8045C211.532 13.8893 215.178 13.8045 215.178 13.8045V10.2213C215.178 10.2213 215.091 2.05844 207.908 1.18915H182.427C182.427 1.18915 171.466 3.03375 171.466 14.2498C171.466 25.4658 182.669 27.7768 182.669 27.7768H202.438C202.438 27.7768 207.886 27.8616 207.886 33.9255C207.886 39.9894 202.834 40.8799 202.834 40.8799H185.788C185.788 40.8799 180.318 40.4346 180.318 33.7135C177.419 33.7135 171.444 33.7771 171.444 33.7771L171.466 33.7559Z" fill="white"/>
|
||||
<path d="M620.165 1.59017H611.115V48.6381H620.165V1.59017Z" fill="#E2E2E2"/>
|
||||
<path d="M680 1.59017H631.851V10.5163H651.203V48.6593H660.253V10.5163H680V1.59017Z" fill="#E2E2E2"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 3.5 KiB |
15
grafana/images/svg/laranja-branco.svg
Executable file
15
grafana/images/svg/laranja-branco.svg
Executable file
@@ -0,0 +1,15 @@
|
||||
<svg width="680" height="49" viewBox="0 0 680 49" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="M102.713 1.90782H65.6562C65.6562 1.90782 56.2328 1.50498 56.2328 10.1555V39.4147C56.2328 39.4147 56.8918 48.2772 65.4146 48.2772H102.713V39.4147H69.3026C69.3026 39.4147 64.8435 37.9729 64.8435 35.1106V27.605H93.6189V18.0216H65.173C65.173 18.0216 63.6793 10.1555 67.8089 10.1555H102.713V1.90782Z" fill="#EA4100"/>
|
||||
<path d="M159.099 15.3308C159.099 5.42928 148.028 1.9097 148.028 1.9097H115.782V49H124.217L124.393 27.4585H137.463L148.709 48.3003H159.121L149.039 26.992C149.039 26.992 159.121 25.2322 159.121 15.3308H159.099ZM144.294 18.9139H124.701V9.58493H144.294C146.974 9.58493 149.127 11.684 149.127 14.2494C149.127 16.8149 146.952 18.9139 144.294 18.9139Z" fill="#EA4100"/>
|
||||
<path d="M34.0692 0.954516H0V47.8964H9.0939V27.1393H34.0692C34.0692 27.1393 43.4926 24.5951 43.4926 13.8879C43.4926 3.18076 34.0692 0.954516 34.0692 0.954516ZM30.1373 19.0401H10.5437V9.71106H30.1373C32.8171 9.71106 34.9698 11.8101 34.9698 14.3756C34.9698 16.941 32.7952 19.0401 30.1373 19.0401Z" fill="#EA4100"/>
|
||||
<path d="M324.152 29.8532L285.118 0.954516V48.2144H294.234V20.4394L333.421 48.9989V0.954516H323.998L324.152 29.8532Z" fill="#EA4100"/>
|
||||
<path d="M341.68 48.9985L366.502 0L392.795 48.9985H380.231L366.985 21.0751L352.597 48.9985H341.68Z" fill="#EA4100"/>
|
||||
<path d="M459.945 0H449.687V48.9985H459.945V0Z" fill="#EA4100"/>
|
||||
<path d="M500.868 10.6224L470.95 48.2989H519.89V39.5H491.115L518.177 4.91902L518.287 1.67507H470.95V10.7709L500.868 10.6224Z" fill="#EA4100"/>
|
||||
<path d="M578.451 2.26913H541.395C541.395 2.26913 531.971 1.86628 531.971 10.5168V39.776C531.971 39.776 532.63 48.6385 541.153 48.6385H578.451V39.776H545.041C545.041 39.776 540.582 38.3342 540.582 35.4719V27.9663H569.358V18.3829H540.912C540.912 18.3829 539.418 10.5168 543.548 10.5168H578.451V2.26913Z" fill="#EA4100"/>
|
||||
<path d="M398.748 1.67507H408.018V33.6905C408.018 33.6905 407.974 36.0864 409.138 37.5493C410.302 39.0123 412.652 39.2879 412.652 39.2879H438.133V48.2989H410.851C410.851 48.2989 407.425 48.1293 403.295 45.1822C400.461 43.1468 399.275 40.8145 398.88 39.3939C398.748 38.9063 398.704 38.4186 398.704 37.931L398.792 1.67507H398.748Z" fill="#EA4100"/>
|
||||
<path d="M251.005 1.18915C237.496 1.18915 226.557 11.7479 226.557 24.7873C226.557 37.8267 237.496 48.3855 251.005 48.3855C264.514 48.3855 275.453 37.8267 275.453 24.7873C275.453 11.7479 264.492 1.18915 251.005 1.18915ZM251.005 39.1201C242.592 39.1201 235.782 32.5473 235.782 24.4269C235.782 16.3064 242.592 9.73368 251.005 9.73368C259.418 9.73368 266.227 16.3064 266.227 24.4269C266.227 32.5473 259.418 39.1201 251.005 39.1201Z" fill="#EA4100"/>
|
||||
<path d="M171.466 33.7559V36.6606C171.466 36.6606 172.345 47.5586 181.68 47.5586H205.008C205.008 47.5586 216.914 45.1627 216.914 34.1587C216.914 23.1547 205.162 19.4019 205.162 19.4019H182.998C182.998 19.4019 178.869 18.681 178.869 14.2074C178.869 9.73368 183.745 8.86438 183.745 8.86438H204.086C204.086 8.86438 207.974 9.73368 207.974 13.8045C211.532 13.8893 215.178 13.8045 215.178 13.8045V10.2213C215.178 10.2213 215.091 2.05844 207.908 1.18915H182.427C182.427 1.18915 171.466 3.03375 171.466 14.2498C171.466 25.4658 182.669 27.7768 182.669 27.7768H202.438C202.438 27.7768 207.886 27.8616 207.886 33.9255C207.886 39.9894 202.834 40.8799 202.834 40.8799H185.788C185.788 40.8799 180.318 40.4346 180.318 33.7135C177.419 33.7135 171.444 33.7771 171.444 33.7771L171.466 33.7559Z" fill="#EA4100"/>
|
||||
<path d="M620.165 1.59017H611.115V48.6381H620.165V1.59017Z" fill="white"/>
|
||||
<path d="M680 1.59017H631.851V10.5163H651.203V48.6593H660.253V10.5163H680V1.59017Z" fill="white"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 3.6 KiB |
15
grafana/images/svg/laranja-cinza.svg
Executable file
15
grafana/images/svg/laranja-cinza.svg
Executable file
@@ -0,0 +1,15 @@
|
||||
<svg width="680" height="49" viewBox="0 0 680 49" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="M102.713 1.90782H65.6562C65.6562 1.90782 56.2328 1.50498 56.2328 10.1555V39.4147C56.2328 39.4147 56.8918 48.2772 65.4146 48.2772H102.713V39.4147H69.3026C69.3026 39.4147 64.8435 37.9729 64.8435 35.1106V27.605H93.6189V18.0216H65.173C65.173 18.0216 63.6793 10.1555 67.8089 10.1555H102.713V1.90782Z" fill="#EA4100"/>
|
||||
<path d="M159.099 15.3308C159.099 5.42928 148.028 1.9097 148.028 1.9097H115.782V49H124.217L124.393 27.4585H137.463L148.709 48.3003H159.121L149.039 26.992C149.039 26.992 159.121 25.2322 159.121 15.3308H159.099ZM144.294 18.9139H124.701V9.58493H144.294C146.974 9.58493 149.127 11.684 149.127 14.2494C149.127 16.8149 146.952 18.9139 144.294 18.9139Z" fill="#EA4100"/>
|
||||
<path d="M34.0692 0.954516H0V47.8964H9.0939V27.1393H34.0692C34.0692 27.1393 43.4926 24.5951 43.4926 13.8879C43.4926 3.18076 34.0692 0.954516 34.0692 0.954516ZM30.1373 19.0401H10.5437V9.71106H30.1373C32.8171 9.71106 34.9698 11.8101 34.9698 14.3756C34.9698 16.941 32.7952 19.0401 30.1373 19.0401Z" fill="#EA4100"/>
|
||||
<path d="M324.152 29.8532L285.118 0.954516V48.2144H294.234V20.4394L333.421 48.9989V0.954516H323.998L324.152 29.8532Z" fill="#EA4100"/>
|
||||
<path d="M341.68 48.9985L366.502 0L392.795 48.9985H380.231L366.985 21.0751L352.597 48.9985H341.68Z" fill="#EA4100"/>
|
||||
<path d="M459.945 0H449.687V48.9985H459.945V0Z" fill="#EA4100"/>
|
||||
<path d="M500.868 10.6224L470.95 48.2989H519.89V39.5H491.115L518.177 4.91902L518.287 1.67507H470.95V10.7709L500.868 10.6224Z" fill="#EA4100"/>
|
||||
<path d="M578.451 2.26913H541.395C541.395 2.26913 531.971 1.86628 531.971 10.5168V39.776C531.971 39.776 532.63 48.6385 541.153 48.6385H578.451V39.776H545.041C545.041 39.776 540.582 38.3342 540.582 35.4719V27.9663H569.357V18.3829H540.912C540.912 18.3829 539.418 10.5168 543.547 10.5168H578.451V2.26913Z" fill="#EA4100"/>
|
||||
<path d="M398.748 1.67507H408.018V33.6905C408.018 33.6905 407.974 36.0864 409.138 37.5494C410.302 39.0123 412.652 39.2879 412.652 39.2879H438.133V48.2989H410.851C410.851 48.2989 407.425 48.1293 403.295 45.1822C400.461 43.1468 399.275 40.8145 398.88 39.3939C398.748 38.9063 398.704 38.4186 398.704 37.931L398.792 1.67507H398.748Z" fill="#EA4100"/>
|
||||
<path d="M251.005 1.18915C237.496 1.18915 226.557 11.7479 226.557 24.7873C226.557 37.8267 237.496 48.3855 251.005 48.3855C264.514 48.3855 275.453 37.8267 275.453 24.7873C275.453 11.7479 264.492 1.18915 251.005 1.18915ZM251.005 39.1201C242.592 39.1201 235.782 32.5473 235.782 24.4269C235.782 16.3064 242.592 9.73368 251.005 9.73368C259.418 9.73368 266.227 16.3064 266.227 24.4269C266.227 32.5473 259.418 39.1201 251.005 39.1201Z" fill="#EA4100"/>
|
||||
<path d="M171.466 33.7559V36.6606C171.466 36.6606 172.345 47.5586 181.68 47.5586H205.008C205.008 47.5586 216.914 45.1627 216.914 34.1587C216.914 23.1547 205.162 19.4019 205.162 19.4019H182.998C182.998 19.4019 178.869 18.681 178.869 14.2074C178.869 9.73368 183.745 8.86438 183.745 8.86438H204.086C204.086 8.86438 207.974 9.73368 207.974 13.8045C211.532 13.8893 215.178 13.8045 215.178 13.8045V10.2213C215.178 10.2213 215.091 2.05844 207.908 1.18915H182.427C182.427 1.18915 171.466 3.03375 171.466 14.2498C171.466 25.4658 182.669 27.7768 182.669 27.7768H202.438C202.438 27.7768 207.886 27.8616 207.886 33.9255C207.886 39.9894 202.834 40.8799 202.834 40.8799H185.788C185.788 40.8799 180.318 40.4346 180.318 33.7135C177.419 33.7135 171.444 33.7771 171.444 33.7771L171.466 33.7559Z" fill="#EA4100"/>
|
||||
<path d="M620.165 1.59017H611.115V48.6381H620.165V1.59017Z" fill="#A8A8A8"/>
|
||||
<path d="M680 1.59017H631.851V10.5163H651.203V48.6593H660.253V10.5163H680V1.59017Z" fill="#A8A8A8"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 3.6 KiB |
@@ -3,7 +3,9 @@
|
||||
"list": [
|
||||
{
|
||||
"builtIn": 1,
|
||||
"datasource": "-- Grafana --",
|
||||
"datasource": {
|
||||
"uid": "-- Grafana --"
|
||||
},
|
||||
"enable": true,
|
||||
"hide": true,
|
||||
"iconColor": "rgba(0, 211, 255, 1)",
|
||||
@@ -13,18 +15,250 @@
|
||||
]
|
||||
},
|
||||
"editable": true,
|
||||
"gnetId": null,
|
||||
"fiscalYearStartMonth": 0,
|
||||
"graphTooltip": 0,
|
||||
"id": null,
|
||||
"id": 1,
|
||||
"links": [],
|
||||
"panels": [
|
||||
{
|
||||
"datasource": "Prometheus",
|
||||
"fieldConfig": {
|
||||
"defaults": {},
|
||||
"overrides": []
|
||||
},
|
||||
"gridPos": {
|
||||
"h": 4,
|
||||
"w": 24,
|
||||
"x": 0,
|
||||
"y": 0
|
||||
},
|
||||
"id": 9,
|
||||
"options": {
|
||||
"code": {
|
||||
"language": "plaintext",
|
||||
"showLineNumbers": false,
|
||||
"showMiniMap": false
|
||||
},
|
||||
"content": "<div style=\"\r\n display: flex;\r\n align-items: center;\r\n justify-content: center;\r\n width: 100%;\r\n height: 100%;\r\n\">\r\n <img\r\n src=\"/public/img/custom/svg/branco-cinza.svg\"\r\n alt=\"PersonalizeIT logo\"\r\n style=\"height: 60px;\"\r\n />\r\n</div>\r\n",
|
||||
"mode": "html"
|
||||
},
|
||||
"pluginVersion": "12.3.2",
|
||||
"title": "",
|
||||
"transparent": true,
|
||||
"type": "text"
|
||||
},
|
||||
{
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "PBFA97CFB590B2093"
|
||||
},
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
"color": {
|
||||
"mode": "thresholds"
|
||||
},
|
||||
"mappings": [],
|
||||
"thresholds": {
|
||||
"mode": "absolute",
|
||||
"steps": [
|
||||
{
|
||||
"color": "green",
|
||||
"value": 0
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"overrides": []
|
||||
},
|
||||
"gridPos": {
|
||||
"h": 7,
|
||||
"w": 5,
|
||||
"x": 0,
|
||||
"y": 4
|
||||
},
|
||||
"id": 5,
|
||||
"options": {
|
||||
"colorMode": "background",
|
||||
"graphMode": "none",
|
||||
"justifyMode": "center",
|
||||
"orientation": "auto",
|
||||
"percentChangeColorMode": "standard",
|
||||
"reduceOptions": {
|
||||
"calcs": [
|
||||
"lastNotNull"
|
||||
],
|
||||
"fields": "",
|
||||
"values": false
|
||||
},
|
||||
"showPercentChange": false,
|
||||
"text": {
|
||||
"valueSize": 150
|
||||
},
|
||||
"textMode": "value",
|
||||
"wideLayout": true
|
||||
},
|
||||
"pluginVersion": "12.3.2",
|
||||
"targets": [
|
||||
{
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "PBFA97CFB590B2093"
|
||||
},
|
||||
"expr": "chamados_abertos_hoje",
|
||||
"format": "time_series",
|
||||
"instant": true,
|
||||
"refId": "A"
|
||||
}
|
||||
],
|
||||
"title": "Chamados Abertos Hoje",
|
||||
"type": "stat"
|
||||
},
|
||||
{
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "PBFA97CFB590B2093"
|
||||
},
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
"color": {
|
||||
"mode": "thresholds"
|
||||
},
|
||||
"mappings": [],
|
||||
"thresholds": {
|
||||
"mode": "absolute",
|
||||
"steps": [
|
||||
{
|
||||
"color": "green",
|
||||
"value": 0
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"overrides": []
|
||||
},
|
||||
"gridPos": {
|
||||
"h": 7,
|
||||
"w": 5,
|
||||
"x": 5,
|
||||
"y": 4
|
||||
},
|
||||
"id": 6,
|
||||
"options": {
|
||||
"colorMode": "background",
|
||||
"graphMode": "none",
|
||||
"justifyMode": "center",
|
||||
"orientation": "auto",
|
||||
"percentChangeColorMode": "standard",
|
||||
"reduceOptions": {
|
||||
"calcs": [
|
||||
"lastNotNull"
|
||||
],
|
||||
"fields": "",
|
||||
"values": false
|
||||
},
|
||||
"showPercentChange": false,
|
||||
"text": {
|
||||
"valueSize": 150
|
||||
},
|
||||
"textMode": "value",
|
||||
"wideLayout": true
|
||||
},
|
||||
"pluginVersion": "12.3.2",
|
||||
"targets": [
|
||||
{
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "PBFA97CFB590B2093"
|
||||
},
|
||||
"expr": "chamados_do_mes",
|
||||
"format": "time_series",
|
||||
"instant": true,
|
||||
"refId": "A"
|
||||
}
|
||||
],
|
||||
"title": "Chamados do Mês",
|
||||
"type": "stat"
|
||||
},
|
||||
{
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "PBFA97CFB590B2093"
|
||||
},
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
"color": {
|
||||
"mode": "thresholds"
|
||||
},
|
||||
"mappings": [],
|
||||
"thresholds": {
|
||||
"mode": "absolute",
|
||||
"steps": [
|
||||
{
|
||||
"color": "green",
|
||||
"value": 0
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"overrides": []
|
||||
},
|
||||
"gridPos": {
|
||||
"h": 7,
|
||||
"w": 5,
|
||||
"x": 10,
|
||||
"y": 4
|
||||
},
|
||||
"id": 7,
|
||||
"options": {
|
||||
"colorMode": "background",
|
||||
"graphMode": "none",
|
||||
"justifyMode": "center",
|
||||
"orientation": "auto",
|
||||
"percentChangeColorMode": "standard",
|
||||
"reduceOptions": {
|
||||
"calcs": [
|
||||
"lastNotNull"
|
||||
],
|
||||
"fields": "",
|
||||
"values": false
|
||||
},
|
||||
"showPercentChange": false,
|
||||
"text": {
|
||||
"valueSize": 150
|
||||
},
|
||||
"textMode": "value",
|
||||
"wideLayout": true
|
||||
},
|
||||
"pluginVersion": "12.3.2",
|
||||
"targets": [
|
||||
{
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "PBFA97CFB590B2093"
|
||||
},
|
||||
"expr": "chamados_concluidos",
|
||||
"format": "time_series",
|
||||
"instant": true,
|
||||
"refId": "A"
|
||||
}
|
||||
],
|
||||
"title": "Chamados Concluídos Hoje",
|
||||
"type": "stat"
|
||||
},
|
||||
{
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "PBFA97CFB590B2093"
|
||||
},
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
"custom": {
|
||||
"align": "center",
|
||||
"displayMode": "auto",
|
||||
"cellOptions": {
|
||||
"type": "auto"
|
||||
},
|
||||
"footer": {
|
||||
"reducers": []
|
||||
},
|
||||
"inspect": false
|
||||
},
|
||||
"mappings": [],
|
||||
@@ -33,7 +267,15 @@
|
||||
"steps": [
|
||||
{
|
||||
"color": "green",
|
||||
"value": null
|
||||
"value": 0
|
||||
},
|
||||
{
|
||||
"color": "yellow",
|
||||
"value": 3600
|
||||
},
|
||||
{
|
||||
"color": "red",
|
||||
"value": 7200
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -42,19 +284,137 @@
|
||||
{
|
||||
"matcher": {
|
||||
"id": "byName",
|
||||
"options": "contact_name"
|
||||
"options": "Value"
|
||||
},
|
||||
"properties": [
|
||||
{
|
||||
"id": "custom.displayMode",
|
||||
"value": "color-background"
|
||||
"id": "custom.cellOptions",
|
||||
"value": {
|
||||
"mode": "gradient",
|
||||
"type": "color-background"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "unit",
|
||||
"value": "short"
|
||||
"value": "s"
|
||||
},
|
||||
{
|
||||
"id": "custom.width",
|
||||
"value": 150
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"matcher": {
|
||||
"id": "byName",
|
||||
"options": "duration_formatted"
|
||||
},
|
||||
"properties": [
|
||||
{
|
||||
"id": "custom.width",
|
||||
"value": 150
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"gridPos": {
|
||||
"h": 7,
|
||||
"w": 9,
|
||||
"x": 15,
|
||||
"y": 4
|
||||
},
|
||||
"id": 8,
|
||||
"options": {
|
||||
"cellHeight": "sm",
|
||||
"showHeader": true,
|
||||
"sortBy": [
|
||||
{
|
||||
"desc": true,
|
||||
"displayName": "Value"
|
||||
}
|
||||
]
|
||||
},
|
||||
"pluginVersion": "12.3.2",
|
||||
"targets": [
|
||||
{
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "PBFA97CFB590B2093"
|
||||
},
|
||||
"expr": "longest_ticket_duration_seconds",
|
||||
"format": "table",
|
||||
"instant": true,
|
||||
"refId": "A"
|
||||
}
|
||||
],
|
||||
"title": "Lista de mais tempo em atendimento agora",
|
||||
"transformations": [
|
||||
{
|
||||
"id": "organize",
|
||||
"options": {
|
||||
"excludeByName": {
|
||||
"Time": true,
|
||||
"__name__": true,
|
||||
"instance": true,
|
||||
"job": true,
|
||||
"queue": true,
|
||||
"ticket_id": true,
|
||||
"user_name": true
|
||||
},
|
||||
"includeByName": {},
|
||||
"indexByName": {
|
||||
"Value": 4,
|
||||
"contact_name": 0,
|
||||
"duration_formatted": 3,
|
||||
"queue": 2,
|
||||
"user_name": 1
|
||||
},
|
||||
"renameByName": {
|
||||
"Value": "Segundos",
|
||||
"contact_name": "Usuário",
|
||||
"duration_formatted": "Tempo",
|
||||
"queue": "TAG",
|
||||
"user_name": "Atendente"
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"type": "table"
|
||||
},
|
||||
{
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "PBFA97CFB590B2093"
|
||||
},
|
||||
"fieldConfig": {
|
||||
"defaults": {
|
||||
"custom": {
|
||||
"align": "center",
|
||||
"cellOptions": {
|
||||
"type": "auto"
|
||||
},
|
||||
"footer": {
|
||||
"reducers": []
|
||||
},
|
||||
"inspect": false
|
||||
},
|
||||
"mappings": [],
|
||||
"thresholds": {
|
||||
"mode": "absolute",
|
||||
"steps": [
|
||||
{
|
||||
"color": "green",
|
||||
"value": 0
|
||||
},
|
||||
{
|
||||
"color": "red",
|
||||
"value": 600000
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"overrides": [
|
||||
{
|
||||
"matcher": {
|
||||
"id": "byName",
|
||||
@@ -63,11 +423,35 @@
|
||||
"properties": [
|
||||
{
|
||||
"id": "unit",
|
||||
"value": "durationms"
|
||||
"value": "ms"
|
||||
},
|
||||
{
|
||||
"id": "decimals",
|
||||
"value": 0
|
||||
"id": "custom.cellOptions",
|
||||
"value": {
|
||||
"type": "color-background"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "color",
|
||||
"value": {
|
||||
"mode": "thresholds"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "thresholds",
|
||||
"value": {
|
||||
"mode": "absolute",
|
||||
"steps": [
|
||||
{
|
||||
"color": "green",
|
||||
"value": null
|
||||
},
|
||||
{
|
||||
"color": "red",
|
||||
"value": 60000
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -77,29 +461,26 @@
|
||||
"h": 12,
|
||||
"w": 24,
|
||||
"x": 0,
|
||||
"y": 0
|
||||
"y": 11
|
||||
},
|
||||
"id": 4,
|
||||
"options": {
|
||||
"footer": {
|
||||
"countRows": false,
|
||||
"fields": "",
|
||||
"reducer": [
|
||||
"sum"
|
||||
],
|
||||
"show": false
|
||||
},
|
||||
"cellHeight": "sm",
|
||||
"showHeader": true,
|
||||
"sortBy": [
|
||||
{
|
||||
"displayName": "TEMPO",
|
||||
"desc": true
|
||||
"desc": true,
|
||||
"displayName": "TEMPO"
|
||||
}
|
||||
]
|
||||
},
|
||||
"pluginVersion": "8.0.0",
|
||||
"pluginVersion": "12.3.2",
|
||||
"targets": [
|
||||
{
|
||||
"datasource": {
|
||||
"type": "prometheus",
|
||||
"uid": "PBFA97CFB590B2093"
|
||||
},
|
||||
"expr": "ticket_duration_milliseconds",
|
||||
"format": "table",
|
||||
"instant": true,
|
||||
@@ -113,23 +494,23 @@
|
||||
"options": {
|
||||
"excludeByName": {
|
||||
"Time": true,
|
||||
"__name__": true,
|
||||
"duration_formatted": true,
|
||||
"instance": true,
|
||||
"job": true,
|
||||
"status": true,
|
||||
"ticket_id": true,
|
||||
"__name__": true,
|
||||
"Value": true,
|
||||
"ticket_duration_milliseconds": true
|
||||
"ticket_duration_milliseconds": true,
|
||||
"ticket_id": true
|
||||
},
|
||||
"indexByName": {
|
||||
"contact_name": 0,
|
||||
"queue": 1,
|
||||
"duration_formatted": 2
|
||||
"Value": 2
|
||||
},
|
||||
"renameByName": {
|
||||
"contact_name": "PESSOA",
|
||||
"queue": "TAG",
|
||||
"duration_formatted": "TEMPO"
|
||||
"Value": "TEMPO",
|
||||
"queue": "TAG"
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -144,9 +525,9 @@
|
||||
"type": "table"
|
||||
}
|
||||
],
|
||||
"preload": false,
|
||||
"refresh": "5s",
|
||||
"schemaVersion": 27,
|
||||
"style": "dark",
|
||||
"schemaVersion": 42,
|
||||
"tags": [
|
||||
"monitoring",
|
||||
"tickets",
|
||||
@@ -163,5 +544,5 @@
|
||||
"timezone": "",
|
||||
"title": "Monitoramento de Atendimento",
|
||||
"uid": "monitoring-tickets",
|
||||
"version": 1
|
||||
"version": 2
|
||||
}
|
||||
@@ -8,3 +8,5 @@ datasources:
|
||||
isDefault: true
|
||||
version: 1
|
||||
editable: true
|
||||
|
||||
|
||||
|
||||
@@ -126,7 +126,7 @@ class APIClient:
|
||||
|
||||
def get_all_tickets(self) -> List[Dict[str, Any]]:
|
||||
"""
|
||||
Fetch all pending tickets and group tickets
|
||||
Fetch all pending, open and group tickets
|
||||
|
||||
Returns:
|
||||
list: List of ticket dictionaries
|
||||
@@ -151,6 +151,24 @@ class APIClient:
|
||||
|
||||
logger.info(f"Fetched {len(all_tickets)} pending tickets")
|
||||
|
||||
# Fetch open tickets
|
||||
logger.info("Fetching open tickets...")
|
||||
page = 1
|
||||
while True:
|
||||
result = self.get_tickets(page_number=page, status='open', is_group=False)
|
||||
|
||||
if not result or not result.get('tickets'):
|
||||
break
|
||||
|
||||
all_tickets.extend(result.get('tickets', []))
|
||||
|
||||
if not result.get('hasMore', False):
|
||||
break
|
||||
|
||||
page += 1
|
||||
|
||||
logger.info(f"Fetched {len(all_tickets)} open tickets (total so far: {len(all_tickets)})")
|
||||
|
||||
# Fetch group tickets
|
||||
logger.info("Fetching group tickets...")
|
||||
page = 1
|
||||
@@ -167,5 +185,95 @@ class APIClient:
|
||||
|
||||
page += 1
|
||||
|
||||
logger.info(f"Total tickets fetched (pending + group): {len(all_tickets)}")
|
||||
logger.info(f"Total tickets fetched (pending + open + group): {len(all_tickets)}")
|
||||
return all_tickets
|
||||
def get_dashboard_resume(self, date_from: str, date_to: str) -> Optional[Dict[str, Any]]:
|
||||
"""
|
||||
Fetch dashboard resume data from the API
|
||||
|
||||
Args:
|
||||
date_from: Start date in format YYYY-MM-DD
|
||||
date_to: End date in format YYYY-MM-DD
|
||||
|
||||
Returns:
|
||||
dict: Dashboard resume data if successful, None otherwise
|
||||
"""
|
||||
if not self.token:
|
||||
logger.error("Not authenticated. Please login first.")
|
||||
return None
|
||||
|
||||
try:
|
||||
resume_url = f"{self.base_url}{Config.API_DASHBOARD_RESUME_ENDPOINT}"
|
||||
|
||||
params = {
|
||||
'dateFrom': date_from,
|
||||
'dateTo': date_to
|
||||
}
|
||||
|
||||
logger.info(f"Fetching dashboard resume from {resume_url} with params: {params}")
|
||||
response = self.session.get(
|
||||
resume_url,
|
||||
params=params,
|
||||
timeout=15
|
||||
)
|
||||
|
||||
if response.status_code == 200:
|
||||
logger.info(f"Successfully fetched dashboard resume")
|
||||
return response.json()
|
||||
else:
|
||||
logger.error(f"Failed to fetch dashboard resume: {response.status_code} - {response.text}")
|
||||
return None
|
||||
|
||||
except requests.exceptions.RequestException as e:
|
||||
logger.error(f"Error fetching dashboard resume: {str(e)}")
|
||||
return None
|
||||
|
||||
def get_open_tickets(self) -> List[Dict[str, Any]]:
|
||||
"""
|
||||
Fetch all open tickets sorted by duration (ascending)
|
||||
|
||||
Returns:
|
||||
list: List of open ticket dictionaries
|
||||
"""
|
||||
if not self.token:
|
||||
logger.error("Not authenticated. Please login first.")
|
||||
return []
|
||||
|
||||
all_tickets = []
|
||||
|
||||
try:
|
||||
import json
|
||||
|
||||
queue_ids = Config.get_queue_ids_list()
|
||||
tickets_url = f"{self.base_url}{Config.API_TICKETS_ENDPOINT}"
|
||||
|
||||
# Use showAll=true for open tickets as per API example
|
||||
params = {
|
||||
'pageNumber': 1,
|
||||
'status': 'open',
|
||||
'showAll': 'true',
|
||||
'queueIds': json.dumps(queue_ids),
|
||||
'tagIds': '[]',
|
||||
'isGroup': 'false',
|
||||
'sortDir': 'ASC',
|
||||
'isSearching': 'false'
|
||||
}
|
||||
|
||||
logger.info(f"Fetching open tickets from {tickets_url} with params: {params}")
|
||||
response = self.session.get(
|
||||
tickets_url,
|
||||
params=params,
|
||||
timeout=15
|
||||
)
|
||||
|
||||
if response.status_code == 200:
|
||||
result = response.json()
|
||||
all_tickets = result.get('tickets', [])
|
||||
logger.info(f"Fetched {len(all_tickets)} open tickets")
|
||||
else:
|
||||
logger.error(f"Failed to fetch open tickets: {response.status_code} - {response.text}")
|
||||
|
||||
except requests.exceptions.RequestException as e:
|
||||
logger.error(f"Error fetching open tickets: {str(e)}")
|
||||
|
||||
return all_tickets
|
||||
|
||||
236
src/app.py
236
src/app.py
@@ -1,7 +1,9 @@
|
||||
import logging
|
||||
import os
|
||||
from datetime import datetime, timedelta
|
||||
from flask import Flask, jsonify, Response
|
||||
import threading
|
||||
import time
|
||||
from datetime import datetime
|
||||
from flask import Flask, jsonify, Response, request
|
||||
from api_client import APIClient
|
||||
from data_formatter import DataFormatter
|
||||
from config import Config
|
||||
@@ -16,44 +18,100 @@ logger = logging.getLogger(__name__)
|
||||
app = Flask(__name__)
|
||||
|
||||
# Global variables for caching
|
||||
last_update = None
|
||||
cached_tickets = []
|
||||
cached_json = None
|
||||
cached_metrics = None
|
||||
CACHE_DURATION = timedelta(seconds=Config.REFRESH_INTERVAL)
|
||||
cached_dashboard_resume = None
|
||||
cached_longest_tickets = None
|
||||
last_tickets_update = None
|
||||
last_dashboard_update = None
|
||||
background_thread = None
|
||||
stop_background_thread = False
|
||||
|
||||
def update_tickets():
|
||||
"""Update cached tickets from API"""
|
||||
global last_update, cached_tickets, cached_json, cached_metrics
|
||||
def background_data_updater():
|
||||
"""Background thread that updates data continuously"""
|
||||
global cached_tickets, cached_json, cached_metrics, cached_dashboard_resume, cached_longest_tickets
|
||||
global last_tickets_update, last_dashboard_update, stop_background_thread
|
||||
|
||||
now = datetime.now()
|
||||
tickets_interval = max(1, Config.TICKETS_REFRESH_INTERVAL)
|
||||
dashboard_interval = max(1, Config.DASHBOARD_REFRESH_INTERVAL)
|
||||
|
||||
# Only update if cache is expired or first run
|
||||
if last_update is None or (now - last_update) > CACHE_DURATION:
|
||||
try:
|
||||
logger.info("Updating ticket data from API...")
|
||||
client = APIClient()
|
||||
next_tickets_run = time.monotonic()
|
||||
next_dashboard_run = time.monotonic()
|
||||
|
||||
# Login
|
||||
if not client.login():
|
||||
logger.error("Failed to authenticate with API")
|
||||
return False
|
||||
while not stop_background_thread:
|
||||
now_monotonic = time.monotonic()
|
||||
|
||||
# Fetch tickets
|
||||
cached_tickets = client.get_all_tickets()
|
||||
if now_monotonic >= next_tickets_run:
|
||||
try:
|
||||
logger.info("Background updater: Updating ticket data from API...")
|
||||
client = APIClient()
|
||||
|
||||
# Format data
|
||||
cached_json = DataFormatter.format_tickets_for_json(cached_tickets)
|
||||
cached_metrics = DataFormatter.format_for_prometheus(cached_tickets)
|
||||
# Login
|
||||
if not client.login():
|
||||
logger.error("Background updater: Failed to authenticate with API")
|
||||
else:
|
||||
cached_tickets = client.get_all_tickets()
|
||||
cached_json = DataFormatter.format_tickets_for_json(cached_tickets)
|
||||
cached_metrics = DataFormatter.format_for_prometheus(cached_tickets)
|
||||
last_tickets_update = datetime.now()
|
||||
logger.info(f"Background updater: Successfully updated {len(cached_tickets)} tickets")
|
||||
except Exception as e:
|
||||
logger.error(f"Background updater error (tickets): {str(e)}")
|
||||
|
||||
last_update = now
|
||||
logger.info(f"Successfully updated {len(cached_tickets)} tickets")
|
||||
return True
|
||||
except Exception as e:
|
||||
logger.error(f"Error updating tickets: {str(e)}")
|
||||
return False
|
||||
while next_tickets_run <= now_monotonic:
|
||||
next_tickets_run += tickets_interval
|
||||
|
||||
if now_monotonic >= next_dashboard_run:
|
||||
try:
|
||||
logger.info("Background updater: Updating dashboard metrics from API...")
|
||||
client = APIClient()
|
||||
|
||||
# Login
|
||||
if not client.login():
|
||||
logger.error("Background updater: Failed to authenticate with API")
|
||||
else:
|
||||
now = datetime.now()
|
||||
date_today = now.strftime('%Y-%m-%d')
|
||||
first_day_month = now.replace(day=1).strftime('%Y-%m-%d')
|
||||
|
||||
resume_today = client.get_dashboard_resume(date_today, date_today)
|
||||
resume_month = client.get_dashboard_resume(first_day_month, date_today)
|
||||
cached_dashboard_resume = {
|
||||
'today': resume_today,
|
||||
'month': resume_month
|
||||
}
|
||||
|
||||
open_tickets = client.get_open_tickets()
|
||||
cached_longest_tickets = DataFormatter.format_longest_tickets(open_tickets, limit=5)
|
||||
last_dashboard_update = datetime.now()
|
||||
logger.info("Background updater: Successfully updated dashboard metrics")
|
||||
except Exception as e:
|
||||
logger.error(f"Background updater error (dashboard): {str(e)}")
|
||||
|
||||
while next_dashboard_run <= now_monotonic:
|
||||
next_dashboard_run += dashboard_interval
|
||||
|
||||
sleep_until = min(next_tickets_run, next_dashboard_run)
|
||||
sleep_for = max(0.0, sleep_until - time.monotonic())
|
||||
time.sleep(sleep_for)
|
||||
|
||||
def start_background_updater():
|
||||
"""Start the background data updater thread"""
|
||||
global background_thread, stop_background_thread
|
||||
|
||||
stop_background_thread = False
|
||||
background_thread = threading.Thread(target=background_data_updater, daemon=True)
|
||||
background_thread.start()
|
||||
logger.info("Background data updater thread started")
|
||||
|
||||
def stop_background_updater():
|
||||
"""Stop the background data updater thread"""
|
||||
global stop_background_thread
|
||||
|
||||
stop_background_thread = True
|
||||
logger.info("Background data updater thread stopped")
|
||||
|
||||
return True
|
||||
|
||||
@app.route('/')
|
||||
def index():
|
||||
@@ -66,7 +124,10 @@ def index():
|
||||
'health': '/health',
|
||||
'json': '/api/tickets',
|
||||
'prometheus': '/metrics',
|
||||
'timeseries': '/api/timeseries'
|
||||
'timeseries': '/api/timeseries',
|
||||
'summary': '/api/summary',
|
||||
'dashboard_resume': '/api/dashboard-resume',
|
||||
'longest_tickets': '/api/longest-tickets'
|
||||
}
|
||||
})
|
||||
|
||||
@@ -74,11 +135,11 @@ def index():
|
||||
def health():
|
||||
"""Health check endpoint"""
|
||||
try:
|
||||
update_tickets()
|
||||
return jsonify({
|
||||
'status': 'healthy',
|
||||
'cached_tickets': len(cached_tickets),
|
||||
'last_update': last_update.isoformat() if last_update else None
|
||||
'dashboard_resume_cached': cached_dashboard_resume is not None,
|
||||
'longest_tickets_cached': cached_longest_tickets is not None
|
||||
}), 200
|
||||
except Exception as e:
|
||||
logger.error(f"Health check failed: {str(e)}")
|
||||
@@ -94,9 +155,6 @@ def get_tickets():
|
||||
Useful for displaying data in Grafana tables and dashboards
|
||||
"""
|
||||
try:
|
||||
if not update_tickets():
|
||||
return jsonify({'error': 'Failed to fetch tickets'}), 500
|
||||
|
||||
if cached_json is None:
|
||||
return jsonify({'error': 'No data available'}), 204
|
||||
|
||||
@@ -112,13 +170,28 @@ def metrics():
|
||||
Can be scraped by Prometheus or used directly in Grafana
|
||||
"""
|
||||
try:
|
||||
if not update_tickets():
|
||||
return Response('# Error: Failed to fetch tickets\n', mimetype='text/plain'), 500
|
||||
all_metrics = []
|
||||
|
||||
if cached_metrics is None:
|
||||
# Add ticket metrics
|
||||
if cached_metrics:
|
||||
all_metrics.append(cached_metrics)
|
||||
|
||||
# Add dashboard metrics
|
||||
if cached_dashboard_resume and cached_longest_tickets:
|
||||
resume_today = cached_dashboard_resume.get('today')
|
||||
resume_month = cached_dashboard_resume.get('month')
|
||||
dashboard_metrics = DataFormatter.format_dashboard_metrics(
|
||||
resume_today,
|
||||
resume_month,
|
||||
cached_longest_tickets
|
||||
)
|
||||
if dashboard_metrics:
|
||||
all_metrics.append(dashboard_metrics)
|
||||
|
||||
if not all_metrics:
|
||||
return Response('# No data available\n', mimetype='text/plain'), 204
|
||||
|
||||
return Response(cached_metrics, mimetype='text/plain'), 200
|
||||
return Response('\n\n'.join(all_metrics), mimetype='text/plain'), 200
|
||||
except Exception as e:
|
||||
logger.error(f"Error in /metrics: {str(e)}")
|
||||
return Response(f'# Error: {str(e)}\n', mimetype='text/plain'), 500
|
||||
@@ -129,8 +202,8 @@ def timeseries():
|
||||
Get time series data for Grafana time series visualization
|
||||
"""
|
||||
try:
|
||||
if not update_tickets():
|
||||
return jsonify({'error': 'Failed to fetch tickets'}), 500
|
||||
if not cached_tickets:
|
||||
return jsonify({'error': 'No data available'}), 204
|
||||
|
||||
time_series = DataFormatter.format_for_timeseries(cached_tickets)
|
||||
return jsonify(time_series), 200
|
||||
@@ -144,9 +217,6 @@ def summary():
|
||||
Get summary statistics for tickets
|
||||
"""
|
||||
try:
|
||||
if not update_tickets():
|
||||
return jsonify({'error': 'Failed to fetch tickets'}), 500
|
||||
|
||||
if not cached_tickets:
|
||||
return jsonify({
|
||||
'total_tickets': 0,
|
||||
@@ -170,6 +240,74 @@ def summary():
|
||||
logger.error(f"Error in /api/summary: {str(e)}")
|
||||
return jsonify({'error': str(e)}), 500
|
||||
|
||||
@app.route('/api/dashboard-resume')
|
||||
def dashboard_resume():
|
||||
"""
|
||||
Get dashboard resume with today's opened tickets, month tickets, and closed tickets
|
||||
"""
|
||||
try:
|
||||
client = APIClient()
|
||||
|
||||
# Login
|
||||
if not client.login():
|
||||
return jsonify({'error': 'Failed to authenticate'}), 500
|
||||
|
||||
now = datetime.now()
|
||||
date_today = now.strftime('%Y-%m-%d')
|
||||
first_day_month = now.replace(day=1).strftime('%Y-%m-%d')
|
||||
|
||||
# Fetch dashboard resume for today and month
|
||||
resume_today = client.get_dashboard_resume(date_today, date_today)
|
||||
resume_month = client.get_dashboard_resume(first_day_month, date_today)
|
||||
|
||||
if not resume_today and not resume_month:
|
||||
return jsonify({'error': 'Failed to fetch dashboard resume'}), 500
|
||||
|
||||
# Format the data
|
||||
formatted_resume = DataFormatter.format_dashboard_resume(resume_today, resume_month)
|
||||
|
||||
return jsonify(formatted_resume), 200
|
||||
except Exception as e:
|
||||
logger.error(f"Error in /api/dashboard-resume: {str(e)}")
|
||||
return jsonify({'error': str(e)}), 500
|
||||
|
||||
@app.route('/api/longest-tickets')
|
||||
def longest_tickets():
|
||||
"""
|
||||
Get list of tickets with longest duration (most time in service)
|
||||
"""
|
||||
try:
|
||||
client = APIClient()
|
||||
|
||||
# Login
|
||||
if not client.login():
|
||||
return jsonify({'error': 'Failed to authenticate'}), 500
|
||||
|
||||
# Get limit parameter or use default
|
||||
limit = request.args.get('limit', 5, type=int)
|
||||
|
||||
# Fetch open tickets
|
||||
open_tickets = client.get_open_tickets()
|
||||
|
||||
if not open_tickets:
|
||||
return jsonify({
|
||||
'tickets': [],
|
||||
'count': 0,
|
||||
'timestamp': datetime.now().isoformat()
|
||||
}), 200
|
||||
|
||||
# Format the data
|
||||
formatted_tickets = DataFormatter.format_longest_tickets(open_tickets, limit)
|
||||
|
||||
return jsonify({
|
||||
'tickets': formatted_tickets,
|
||||
'count': len(formatted_tickets),
|
||||
'timestamp': datetime.now().isoformat()
|
||||
}), 200
|
||||
except Exception as e:
|
||||
logger.error(f"Error in /api/longest-tickets: {str(e)}")
|
||||
return jsonify({'error': str(e)}), 500
|
||||
|
||||
@app.errorhandler(404)
|
||||
def not_found(error):
|
||||
"""Handle 404 errors"""
|
||||
@@ -181,6 +319,10 @@ def internal_error(error):
|
||||
logger.error(f"Internal server error: {str(error)}")
|
||||
return jsonify({'error': 'Internal server error'}), 500
|
||||
|
||||
# Initialize background updater when app starts
|
||||
logger.info("Initializing background data updater...")
|
||||
start_background_updater()
|
||||
|
||||
if __name__ == '__main__':
|
||||
try:
|
||||
# Validate configuration
|
||||
@@ -188,9 +330,13 @@ if __name__ == '__main__':
|
||||
|
||||
logger.info("Starting Grafana Monitoring Service...")
|
||||
logger.info(f"API Base URL: {Config.API_BASE_URL}")
|
||||
logger.info(f"Refresh Interval: {Config.REFRESH_INTERVAL} seconds")
|
||||
logger.info(f"Tickets Refresh Interval: {Config.TICKETS_REFRESH_INTERVAL} seconds")
|
||||
logger.info(f"Dashboard Refresh Interval: {Config.DASHBOARD_REFRESH_INTERVAL} seconds")
|
||||
logger.info(f"Queue IDs: {Config.QUEUE_IDS}")
|
||||
|
||||
# Start background data updater
|
||||
start_background_updater()
|
||||
|
||||
# Start Flask app
|
||||
app.run(
|
||||
host=Config.FLASK_HOST,
|
||||
|
||||
@@ -11,6 +11,7 @@ class Config:
|
||||
API_BASE_URL = os.getenv('API_BASE_URL', 'https://api-personalizeit.zapplataforma.chat')
|
||||
API_LOGIN_ENDPOINT = os.getenv('API_LOGIN_ENDPOINT', '/auth/login')
|
||||
API_TICKETS_ENDPOINT = os.getenv('API_TICKETS_ENDPOINT', '/tickets')
|
||||
API_DASHBOARD_RESUME_ENDPOINT = os.getenv('API_DASHBOARD_RESUME_ENDPOINT', '/dashboard/resume/')
|
||||
|
||||
# Login Credentials
|
||||
API_USERNAME = os.getenv('API_USERNAME', '')
|
||||
@@ -21,8 +22,9 @@ class Config:
|
||||
FLASK_HOST = os.getenv('FLASK_HOST', '0.0.0.0')
|
||||
DEBUG = os.getenv('DEBUG', 'False').lower() == 'true'
|
||||
|
||||
# Refresh interval in seconds
|
||||
REFRESH_INTERVAL = int(os.getenv('REFRESH_INTERVAL', 30))
|
||||
# Refresh intervals in seconds
|
||||
TICKETS_REFRESH_INTERVAL = int(os.getenv('TICKETS_REFRESH_INTERVAL', 5))
|
||||
DASHBOARD_REFRESH_INTERVAL = int(os.getenv('DASHBOARD_REFRESH_INTERVAL', 60))
|
||||
|
||||
# Queue IDs
|
||||
QUEUE_IDS = os.getenv('QUEUE_IDS', '-1,1,2,3,4,5,7')
|
||||
|
||||
@@ -24,6 +24,7 @@ class DataFormatter:
|
||||
for ticket in tickets:
|
||||
try:
|
||||
# Handle None values safely
|
||||
ticket_id = ticket.get('id', 'unknown')
|
||||
contact = ticket.get('contact') or {}
|
||||
queue = ticket.get('queue') or {}
|
||||
whatsapp = ticket.get('whatsapp') or {}
|
||||
@@ -72,7 +73,8 @@ class DataFormatter:
|
||||
duration = 0
|
||||
|
||||
# Skip tickets with "EQUIPAMENTO EM MANUTENÇÃO" queue
|
||||
if 'EQUIPAMENTO EM MANUTENÇÃO' in queue_name:
|
||||
if 'EQUIPAMENTO EM MANUTENÇÃO' in queue_name.strip().upper():
|
||||
logger.info(f"Filtering out ticket {ticket.get('id')} with queue: {queue_name}")
|
||||
continue
|
||||
|
||||
# Format duration as HH:MM:SS
|
||||
@@ -154,7 +156,8 @@ class DataFormatter:
|
||||
queue_name = tags
|
||||
|
||||
# Skip tickets with "EQUIPAMENTO EM MANUTENÇÃO" queue
|
||||
if 'EQUIPAMENTO EM MANUTENÇÃO' in queue_name:
|
||||
if 'EQUIPAMENTO EM MANUTENÇÃO' in queue_name.strip().upper():
|
||||
logger.info(f"Prometheus: Filtering out ticket {ticket.get('id')} with queue: {queue_name}")
|
||||
continue
|
||||
|
||||
contact_name = contact.get('name', 'unknown').replace('"', '\\"')
|
||||
@@ -201,6 +204,57 @@ class DataFormatter:
|
||||
|
||||
return "\n".join(metrics)
|
||||
|
||||
@staticmethod
|
||||
def format_dashboard_metrics(resume_today: Dict[str, Any], resume_month: Dict[str, Any], longest_tickets: List[Dict[str, Any]]) -> str:
|
||||
"""
|
||||
Format dashboard data as Prometheus metrics
|
||||
|
||||
Args:
|
||||
resume_today: Dashboard resume data for today from API
|
||||
resume_month: Dashboard resume data for the month from API
|
||||
longest_tickets: List of longest tickets
|
||||
|
||||
Returns:
|
||||
str: Prometheus format metrics
|
||||
"""
|
||||
metrics = []
|
||||
|
||||
# Dashboard resume metrics
|
||||
if resume_today or resume_month:
|
||||
chamados_abertos = (resume_today.get('open', 0) if resume_today else 0)
|
||||
chamados_mes = (resume_month.get('total', 0) if resume_month else 0)
|
||||
chamados_concluidos = (resume_today.get('closed', 0) if resume_today else 0)
|
||||
|
||||
metrics.append("# HELP chamados_abertos_hoje Number of tickets currently open")
|
||||
metrics.append("# TYPE chamados_abertos_hoje gauge")
|
||||
metrics.append(f"chamados_abertos_hoje {chamados_abertos}")
|
||||
|
||||
metrics.append("\n# HELP chamados_do_mes Total tickets this month")
|
||||
metrics.append("# TYPE chamados_do_mes gauge")
|
||||
metrics.append(f"chamados_do_mes {chamados_mes}")
|
||||
|
||||
metrics.append("\n# HELP chamados_concluidos Closed tickets today")
|
||||
metrics.append("# TYPE chamados_concluidos gauge")
|
||||
metrics.append(f"chamados_concluidos {chamados_concluidos}")
|
||||
|
||||
# Longest tickets metrics
|
||||
if longest_tickets:
|
||||
metrics.append("\n# HELP longest_ticket_duration_seconds Duration of longest open tickets")
|
||||
metrics.append("# TYPE longest_ticket_duration_seconds gauge")
|
||||
|
||||
for ticket in longest_tickets:
|
||||
contact_name = ticket.get('contact_name', 'unknown').replace('"', '\\"')
|
||||
user_name = ticket.get('user_name', 'unknown').replace('"', '\\"')
|
||||
queue = ticket.get('queue', 'unknown').replace('"', '\\"')
|
||||
duration_formatted = ticket.get('duration_formatted', '0s')
|
||||
ticket_id = ticket.get('id', 0)
|
||||
duration = ticket.get('duration_seconds', 0)
|
||||
|
||||
labels = f'ticket_id="{ticket_id}",contact_name="{contact_name}",user_name="{user_name}",queue="{queue}",duration_formatted="{duration_formatted}"'
|
||||
metrics.append(f'longest_ticket_duration_seconds{{{labels}}} {duration}')
|
||||
|
||||
return "\n".join(metrics)
|
||||
|
||||
@staticmethod
|
||||
def format_for_timeseries(tickets: List[Dict[str, Any]]) -> List[Dict[str, Any]]:
|
||||
"""
|
||||
@@ -225,7 +279,8 @@ class DataFormatter:
|
||||
queue_name = queue.get('name', 'No Queue')
|
||||
|
||||
# Skip tickets with "EQUIPAMENTO EM MANUTENÇÃO" queue
|
||||
if 'EQUIPAMENTO EM MANUTENÇÃO' in queue_name:
|
||||
if 'EQUIPAMENTO EM MANUTENÇÃO' in queue_name.strip().upper():
|
||||
logger.info(f"Timeseries: Filtering out ticket {ticket.get('id')} with queue: {queue_name}")
|
||||
continue
|
||||
|
||||
contact_name = contact.get('name', 'Unknown')
|
||||
@@ -265,3 +320,133 @@ class DataFormatter:
|
||||
})
|
||||
|
||||
return time_series
|
||||
@staticmethod
|
||||
def format_dashboard_resume(resume_today: Dict[str, Any], resume_month: Dict[str, Any]) -> Dict[str, Any]:
|
||||
"""
|
||||
Format dashboard resume data for display
|
||||
|
||||
Args:
|
||||
resume_today: Dashboard resume data for today from API
|
||||
resume_month: Dashboard resume data for the month from API
|
||||
|
||||
Returns:
|
||||
dict: Formatted dashboard resume data
|
||||
"""
|
||||
if not resume_today and not resume_month:
|
||||
return {
|
||||
'chamados_abertos_hoje': 0,
|
||||
'chamados_do_mes': 0,
|
||||
'chamados_concluidos': 0,
|
||||
'timestamp': datetime.now().isoformat()
|
||||
}
|
||||
|
||||
# Chamados abertos hoje = tickets que estão abertos/em atendimento agora
|
||||
chamados_abertos = (resume_today.get('open', 0) if resume_today else 0)
|
||||
|
||||
# Chamados do mês = total de tickets criados no mês
|
||||
chamados_mes = (resume_month.get('total', 0) if resume_month else 0)
|
||||
|
||||
# Chamados concluídos = tickets fechados HOJE
|
||||
chamados_concluidos = (resume_today.get('closed', 0) if resume_today else 0)
|
||||
|
||||
return {
|
||||
'chamados_abertos_hoje': chamados_abertos,
|
||||
'chamados_do_mes': chamados_mes,
|
||||
'chamados_concluidos': chamados_concluidos,
|
||||
'timestamp': datetime.now().isoformat()
|
||||
}
|
||||
|
||||
@staticmethod
|
||||
def format_longest_tickets(tickets: List[Dict[str, Any]], limit: int = 5) -> List[Dict[str, Any]]:
|
||||
"""
|
||||
Format the tickets with longest duration
|
||||
|
||||
Args:
|
||||
tickets: List of open ticket dictionaries from API
|
||||
limit: Number of tickets to return (default: 5)
|
||||
|
||||
Returns:
|
||||
list: List of formatted tickets sorted by duration (descending)
|
||||
"""
|
||||
formatted_tickets = []
|
||||
now = datetime.now()
|
||||
|
||||
logger.info(f"format_longest_tickets: Processing {len(tickets)} tickets")
|
||||
|
||||
for ticket in tickets:
|
||||
try:
|
||||
# Handle None values safely
|
||||
contact = ticket.get('contact') or {}
|
||||
user = ticket.get('user') or {}
|
||||
queue = ticket.get('queue') or {}
|
||||
tags = ticket.get('tags', [])
|
||||
group_tags = ticket.get('groupTags', [])
|
||||
|
||||
contact_name = contact.get('name', 'Unknown')
|
||||
user_name = user.get('name', 'Sem atendente')
|
||||
ticket_id = ticket.get('id')
|
||||
created_at = ticket.get('createdAt')
|
||||
|
||||
# Try to get queue name, or use tags/groupTags if available
|
||||
queue_name = queue.get('name', 'No Queue')
|
||||
if queue_name == 'No Queue':
|
||||
# Try groupTags first - format is "id||name||color"
|
||||
if group_tags:
|
||||
if isinstance(group_tags, str) and '||' in group_tags:
|
||||
parts = group_tags.split('||')
|
||||
if len(parts) >= 2:
|
||||
queue_name = parts[1]
|
||||
elif isinstance(group_tags, list) and len(group_tags) > 0:
|
||||
if isinstance(group_tags[0], dict):
|
||||
queue_name = group_tags[0].get('tag', {}).get('name', 'No Queue')
|
||||
else:
|
||||
queue_name = str(group_tags[0])
|
||||
# Then try tags
|
||||
elif tags and isinstance(tags, list) and len(tags) > 0:
|
||||
if isinstance(tags[0], dict):
|
||||
queue_name = tags[0].get('name', 'No Queue')
|
||||
else:
|
||||
queue_name = str(tags[0])
|
||||
elif isinstance(tags, str):
|
||||
queue_name = tags
|
||||
|
||||
# Skip tickets with "EQUIPAMENTO EM MANUTENÇÃO" queue
|
||||
if 'EQUIPAMENTO EM MANUTENÇÃO' in queue_name.strip().upper():
|
||||
logger.info(f"Longest: Filtering out ticket {ticket.get('id')} with queue: {queue_name}")
|
||||
continue
|
||||
|
||||
# Calculate duration dynamically from createdAt to now
|
||||
duration = 0
|
||||
if created_at:
|
||||
try:
|
||||
created_datetime = datetime.fromisoformat(created_at.replace('Z', '+00:00'))
|
||||
# If timezone-aware, convert to naive for subtraction
|
||||
if created_datetime.tzinfo is not None:
|
||||
created_datetime = created_datetime.replace(tzinfo=None)
|
||||
duration = int((now - created_datetime).total_seconds())
|
||||
except (ValueError, AttributeError):
|
||||
duration = 0
|
||||
|
||||
# Format duration as HH:MM:SS
|
||||
hours = duration // 3600
|
||||
minutes = (duration % 3600) // 60
|
||||
seconds = duration % 60
|
||||
duration_formatted = f"{hours:02d}h:{minutes:02d}m:{seconds:02d}s"
|
||||
|
||||
formatted_tickets.append({
|
||||
'id': ticket_id,
|
||||
'contact_name': contact_name,
|
||||
'user_name': user_name,
|
||||
'queue': queue_name,
|
||||
'duration_seconds': duration,
|
||||
'duration_formatted': duration_formatted,
|
||||
'created_at': created_at
|
||||
})
|
||||
except Exception as e:
|
||||
logger.error(f"Error formatting ticket {ticket.get('id')}: {str(e)}")
|
||||
continue
|
||||
|
||||
# Sort by duration (descending) and take the top N
|
||||
formatted_tickets.sort(key=lambda x: x['duration_seconds'], reverse=True)
|
||||
|
||||
return formatted_tickets[:limit]
|
||||
Reference in New Issue
Block a user