23 Commits

Author SHA1 Message Date
Shizun Ge
8e1251ab4f Merge pull request #47 from shizunge/dependabot/github_actions/docker/build-push-action-4.0.0
Bump docker/build-push-action from 3.3.0 to 4.0.0
2023-02-11 01:29:57 -08:00
Shizun Ge
193c34d325 Merge pull request #46 from shizunge/dependabot/github_actions/docker/setup-buildx-action-2.4.0
Bump docker/setup-buildx-action from 2.3.0 to 2.4.0
2023-02-11 01:29:47 -08:00
Shizun Ge
8aeed47955 cleanup unnecessary codes 2023-02-11 01:24:59 -08:00
Shizun Ge
374c2b74ad report unknow location for local ip 2023-02-11 01:06:16 -08:00
Shizun Ge
c50302622e hard coded country to coordinates. update copyright date. 2023-02-11 00:53:31 -08:00
Shizun Ge
144e58aa7a fix using country db. We cannot get coordinates from the country now. 2023-02-10 22:46:45 -08:00
Shizun Ge
81ab381551 use geohash of the country if city is not available. 2023-02-10 22:26:31 -08:00
Shizun Ge
d9202cfca6 remove freegeoip.live as a provider 2023-02-10 22:22:32 -08:00
Shizun Ge
7c55c713a0 update go version to 1.20 2023-02-10 22:10:02 -08:00
dependabot[bot]
5bb568e6e5 Bump docker/build-push-action from 3.3.0 to 4.0.0
Bumps [docker/build-push-action](https://github.com/docker/build-push-action) from 3.3.0 to 4.0.0.
- [Release notes](https://github.com/docker/build-push-action/releases)
- [Commits](https://github.com/docker/build-push-action/compare/v3.3.0...v4.0.0)

---
updated-dependencies:
- dependency-name: docker/build-push-action
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-02-06 08:03:47 +00:00
dependabot[bot]
1ff33d19b7 Bump docker/setup-buildx-action from 2.3.0 to 2.4.0
Bumps [docker/setup-buildx-action](https://github.com/docker/setup-buildx-action) from 2.3.0 to 2.4.0.
- [Release notes](https://github.com/docker/setup-buildx-action/releases)
- [Commits](https://github.com/docker/setup-buildx-action/compare/v2.3.0...v2.4.0)

---
updated-dependencies:
- dependency-name: docker/setup-buildx-action
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-02-06 08:03:42 +00:00
Shizun Ge
41d0618fa2 fix loading variables on time changes 2023-02-01 22:44:57 -08:00
Shizun Ge
0750caa4e9 Merge pull request #44 from shizunge/dependabot/github_actions/docker/setup-buildx-action-2.3.0
Bump docker/setup-buildx-action from 2.2.1 to 2.3.0
2023-01-31 23:37:24 -08:00
dependabot[bot]
ebabfd3790 Bump docker/setup-buildx-action from 2.2.1 to 2.3.0
Bumps [docker/setup-buildx-action](https://github.com/docker/setup-buildx-action) from 2.2.1 to 2.3.0.
- [Release notes](https://github.com/docker/setup-buildx-action/releases)
- [Commits](https://github.com/docker/setup-buildx-action/compare/v2.2.1...v2.3.0)

---
updated-dependencies:
- dependency-name: docker/setup-buildx-action
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-01-30 08:04:56 +00:00
Shizun Ge
fdf9842025 dashboard updates variables on time range change. 2023-01-29 20:59:43 -08:00
Shizun Ge
2773554b0a Merge pull request #43 from shizunge/dependabot/github_actions/docker/build-push-action-3.3.0
Bump docker/build-push-action from 3.2.0 to 3.3.0
2023-01-19 00:05:32 -08:00
dependabot[bot]
288c04f5e8 Bump docker/build-push-action from 3.2.0 to 3.3.0
Bumps [docker/build-push-action](https://github.com/docker/build-push-action) from 3.2.0 to 3.3.0.
- [Release notes](https://github.com/docker/build-push-action/releases)
- [Commits](https://github.com/docker/build-push-action/compare/v3.2.0...v3.3.0)

---
updated-dependencies:
- dependency-name: docker/build-push-action
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-01-16 08:04:23 +00:00
Shizun Ge
2fb8972eb3 Merge pull request #37 from shizunge/dependabot/go_modules/github.com/prometheus/client_golang-1.14.0
Bump github.com/prometheus/client_golang from 1.13.0 to 1.14.0
2022-12-21 00:43:52 -08:00
dependabot[bot]
43cf7695f1 Bump github.com/prometheus/client_golang from 1.13.0 to 1.14.0
Bumps [github.com/prometheus/client_golang](https://github.com/prometheus/client_golang) from 1.13.0 to 1.14.0.
- [Release notes](https://github.com/prometheus/client_golang/releases)
- [Changelog](https://github.com/prometheus/client_golang/blob/main/CHANGELOG.md)
- [Commits](https://github.com/prometheus/client_golang/compare/v1.13.0...v1.14.0)

---
updated-dependencies:
- dependency-name: github.com/prometheus/client_golang
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-11-14 08:05:26 +00:00
Shizun Ge
ae2f8c4baf update screen shot path 2022-10-29 21:36:12 -07:00
Shizun Ge
642ee0513e Merge pull request #35 from shizunge/dependabot/github_actions/docker/setup-buildx-action-2.2.1
Bump docker/setup-buildx-action from 2.1.0 to 2.2.1
2022-10-29 21:34:45 -07:00
dependabot[bot]
7f6b6718e1 Bump docker/setup-buildx-action from 2.1.0 to 2.2.1
Bumps [docker/setup-buildx-action](https://github.com/docker/setup-buildx-action) from 2.1.0 to 2.2.1.
- [Release notes](https://github.com/docker/setup-buildx-action/releases)
- [Commits](https://github.com/docker/setup-buildx-action/compare/v2.1.0...v2.2.1)

---
updated-dependencies:
- dependency-name: docker/setup-buildx-action
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-10-24 08:27:09 +00:00
Shizun Ge
7f0f69d7b5 fix the workflow name 2022-10-12 19:10:41 -07:00
9 changed files with 352 additions and 83 deletions

View File

@@ -1,4 +1,4 @@
name: Build docker image and push to docker hub on release
name: Build docker image and push to docker hub on push
on:
push:
@@ -28,7 +28,7 @@ jobs:
uses: docker/setup-qemu-action@v2
- name: Install buildx
uses: docker/setup-buildx-action@v2.1.0
uses: docker/setup-buildx-action@v2.4.0
- name: Login to docker hub
uses: docker/login-action@v2.1.0
@@ -44,7 +44,7 @@ jobs:
password: ${{ github.token }}
- name: Build and push ${{ github.repository }}:${{ steps.git.outputs.image_tag }}
uses: docker/build-push-action@v3.2.0
uses: docker/build-push-action@v4.0.0
with:
platforms: ${{ env.PLATFORMS }}
push: true

View File

@@ -27,7 +27,7 @@ jobs:
uses: docker/setup-qemu-action@v2
- name: Install buildx
uses: docker/setup-buildx-action@v2.1.0
uses: docker/setup-buildx-action@v2.4.0
- name: Login to docker hub
uses: docker/login-action@v2.1.0
@@ -43,7 +43,7 @@ jobs:
password: ${{ github.token }}
- name: Build and push ${{ github.repository }}:${{ steps.git.outputs.image_tag }}
uses: docker/build-push-action@v3.2.0
uses: docker/build-push-action@v4.0.0
with:
platforms: ${{ env.PLATFORMS }}
push: true

View File

@@ -2,7 +2,7 @@
A golang implementation of [endlessh](https://nullprogram.com/blog/2019/03/22/) exporting Prometheus metrics, visualized by a Grafana dashboard.
![screenshot](https://github.com/shizunge/endlessh-go/raw/master/dashboard/screenshot.png)
![screenshot](https://github.com/shizunge/endlessh-go/raw/main/dashboard/screenshot.png)
## Introduction
@@ -100,7 +100,7 @@ The metrics is off by default, you can turn it via the CLI argument `-enable_pro
It listens to port `2112` and entry point is `/metrics` by default. The port and entry point can be changed via CLI arguments.
The endlessh-go server stores the geohash of attackers as a label on `endlessh_client_open_count`, which is also off by default. You can turn it on via the CLI argument `-geoip_supplier`. The endlessh-go uses service from either [ip-api](https://ip-api.com/) or [freegeoip](https://freegeoip.live/), which may enforce a query rate and limit commercial use. Visit their website for their terms and policies.
The endlessh-go server stores the geohash of attackers as a label on `endlessh_client_open_count`, which is also off by default. You can turn it on via the CLI argument `-geoip_supplier`. The endlessh-go uses service from [ip-api](https://ip-api.com/), which may enforce a query rate and limit commercial use. Visit their website for their terms and policies.
You could also use an offline GeoIP database from [MaxMind](https://www.maxmind.com) by setting `-geoip_supplier` to *max-mind-db* and `-max_mind_db` to the path of the database file.

264
coordinates/country.go Normal file
View File

@@ -0,0 +1,264 @@
// Copyright (C) 2023 Shizun Ge
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//
package coordinates
// Map country's ISO to their capital's latitude and longitude.
// Country's ISO see https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
type Location struct {
Latitude float64
Longitude float64
}
var Country = map[string]Location{
"AD": {42.5, 1.5},
"AE": {24.4511, 54.3969},
"AF": {34.5328, 69.1658},
"AG": {17.1211, -61.8447},
"AI": {18.2167, -63.05},
"AL": {41.33, 19.82},
"AM": {40.1814, 44.5144},
"AO": {-8.8383, 13.2344},
"AR": {-34.5997, -58.3819},
"AS": {-14.274, -170.7046},
"AT": {48.2083, 16.3725},
"AU": {-35.2931, 149.1269},
"AW": {12.5186, -70.0358},
"AZ": {40.3667, 49.8352},
"BA": {43.8563, 18.4132},
"BB": {13.0975, -59.6167},
"BD": {23.7289, 90.3944},
"BE": {50.8353, 4.3314},
"BF": {12.3686, -1.5275},
"BG": {42.6979, 23.3217},
"BH": {26.225, 50.5775},
"BI": {-3.3825, 29.3611},
"BJ": {6.402, 2.518},
"BL": {17.8958, -62.8508},
"BM": {32.2942, -64.7839},
"BN": {4.9167, 114.9167},
"BO": {-16.4942, -68.1475},
"BR": {-15.7939, -47.8828},
"BS": {25.0667, -77.3333},
"BT": {27.4833, 89.6333},
"BW": {-24.6569, 25.9086},
"BY": {53.9022, 27.5618},
"BZ": {17.25, -88.7675},
"CA": {45.4247, -75.695},
"CD": {-4.3317, 15.3139},
"CF": {4.3732, 18.5628},
"CG": {-4.2667, 15.2833},
"CH": {46.948, 7.4474},
"CI": {5.3364, -4.0267},
"CK": {-21.207, -159.771},
"CL": {-33.45, -70.6667},
"CM": {3.8578, 11.5181},
"CN": {39.904, 116.4075},
"CO": {4.6126, -74.0705},
"CR": {9.9333, -84.0833},
"CU": {23.1367, -82.3589},
"CV": {14.9177, -23.5092},
"CW": {12.108, -68.935},
"CX": {-10.4167, 105.7167},
"CY": {35.1725, 33.365},
"CZ": {50.0833, 14.4167},
"DE": {52.5167, 13.3833},
"DJ": {11.595, 43.1481},
"DK": {55.6805, 12.5615},
"DM": {15.3, -61.3833},
"DO": {18.4764, -69.8933},
"DZ": {36.7764, 3.0586},
"EC": {-0.22, -78.5125},
"EE": {59.4372, 24.745},
"EG": {30.0444, 31.2358},
"ER": {15.3333, 38.9167},
"ES": {40.4167, -3.7167},
"ET": {9.0272, 38.7369},
"FI": {60.1756, 24.9342},
"FJ": {-18.1333, 178.4333},
"FK": {-51.7, -57.85},
"FM": {6.9178, 158.185},
"FO": {62, -6.7833},
"FR": {48.8566, 2.3522},
"GA": {0.3901, 9.4544},
"GB": {51.5072, -0.1275},
"GD": {12.0444, -61.7417},
"GE": {41.7225, 44.7925},
"GF": {4.933, -52.33},
"GH": {5.6037, -0.187},
"GI": {36.1324, -5.3781},
"GL": {64.175, -51.7333},
"GM": {13.4531, -16.5775},
"GN": {9.538, -13.6773},
"GP": {16.0104, -61.7055},
"GQ": {3.7521, 8.7737},
"GR": {37.9842, 23.7281},
"GS": {-54.2833, -36.5},
"GT": {14.6099, -90.5252},
"GU": {13.4745, 144.7504},
"GW": {11.8592, -15.5956},
"GY": {6.7833, -58.1667},
"HK": {22.3069, 114.1831},
"HN": {14.0942, -87.2067},
"HR": {45.8131, 15.9772},
"HT": {18.5425, -72.3386},
"HU": {47.4983, 19.0408},
"ID": {-6.2146, 106.8451},
"IE": {53.3497, -6.2603},
"IL": {31.7833, 35.2167},
"IM": {54.15, -4.4819},
"IN": {28.6139, 77.209},
"IQ": {33.35, 44.4167},
"IR": {35.7, 51.4167},
"IS": {64.1475, -21.935},
"IT": {41.8931, 12.4828},
"JE": {49.1858, -2.11},
"JM": {17.9714, -76.7931},
"JO": {31.95, 35.9333},
"JP": {35.6839, 139.7744},
"KE": {-1.2864, 36.8172},
"KG": {42.8667, 74.5667},
"KH": {11.5696, 104.921},
"KI": {1.3382, 173.0176},
"KM": {-11.7036, 43.2536},
"KN": {17.2983, -62.7342},
"KP": {39.03, 125.73},
"KR": {37.56, 126.99},
"KW": {29.375, 47.98},
"KY": {19.2866, -81.3744},
"KZ": {51.1333, 71.4333},
"LA": {17.9667, 102.6},
"LB": {33.8869, 35.5131},
"LC": {14.0167, -60.9833},
"LI": {47.1397, 9.5219},
"LK": {6.9, 79.9164},
"LR": {6.3106, -10.8047},
"LS": {-29.31, 27.48},
"LT": {54.6833, 25.2833},
"LU": {49.6106, 6.1328},
"LV": {56.9475, 24.1069},
"LY": {32.8752, 13.1875},
"MA": {26.0928, -10.6089},
"MC": {43.7396, 7.4069},
"MD": {47.0228, 28.8353},
"ME": {42.4397, 19.2661},
"MF": {18.0706, -63.0847},
"MG": {-18.9386, 47.5214},
"MH": {7.0918, 171.3802},
"MK": {41.9833, 21.4333},
"ML": {12.6458, -7.9922},
"MM": {16.795, 96.16},
"MN": {47.9214, 106.9055},
"MP": {15.2137, 145.7546},
"MQ": {14.6104, -61.08},
"MR": {18.0858, -15.9785},
"MS": {16.7928, -62.2106},
"MT": {35.8978, 14.5125},
"MU": {-20.1667, 57.5},
"MV": {4.175, 73.5083},
"MW": {-13.9833, 33.7833},
"MX": {19.4333, -99.1333},
"MY": {3.1478, 101.6953},
"MZ": {-25.9153, 32.5764},
"NA": {-22.57, 17.0836},
"NC": {-22.2625, 166.4443},
"NE": {13.5086, 2.1111},
"NF": {-29.0569, 167.9617},
"NG": {9.0556, 7.4914},
"NI": {12.15, -86.2667},
"NL": {52.08, 4.31},
"NO": {59.9111, 10.7528},
"NP": {27.7167, 85.3667},
"NR": {-0.5477, 166.9209},
"NU": {-19.056, -169.921},
"NZ": {-41.2889, 174.7772},
"OM": {23.6139, 58.5922},
"PA": {9, -79.5},
"PE": {-12.06, -77.0375},
"PF": {-17.5334, -149.5667},
"PG": {-9.4789, 147.1494},
"PH": {14.6, 120.9833},
"PK": {33.6989, 73.0369},
"PL": {52.23, 21.0111},
"PM": {46.7811, -56.1764},
"PN": {-25.0667, -130.0833},
"PR": {18.4037, -66.0636},
"PT": {38.708, -9.139},
"PW": {7.5006, 134.6242},
"PY": {-25.3, -57.6333},
"QA": {25.3, 51.5333},
"RE": {-20.8789, 55.4481},
"RO": {44.4, 26.0833},
"RS": {44.8167, 20.4667},
"RU": {55.7558, 37.6178},
"RW": {-1.9536, 30.0606},
"SA": {24.65, 46.71},
"SB": {-9.4333, 159.95},
"SC": {-4.6236, 55.4544},
"SD": {15.6031, 32.5265},
"SE": {59.3294, 18.0686},
"SG": {1.3, 103.8},
"SH": {-15.9251, -5.7179},
"SI": {46.05, 14.5167},
"SK": {48.1447, 17.1128},
"SL": {8.4833, -13.2331},
"SM": {43.932, 12.4484},
"SN": {14.7319, -17.4572},
"SO": {2.0408, 45.3425},
"SR": {5.8667, -55.1667},
"SS": {4.85, 31.6},
"ST": {0.3333, 6.7333},
"SV": {13.6989, -89.1914},
"SX": {18.0256, -63.0492},
"SY": {33.5131, 36.2919},
"SZ": {-26.3208, 31.1617},
"TC": {21.4664, -71.136},
"TD": {12.11, 15.05},
"TG": {6.1319, 1.2228},
"TH": {13.75, 100.5167},
"TJ": {38.5731, 68.7864},
"TL": {-8.5536, 125.5783},
"TM": {37.95, 58.3833},
"TN": {36.8008, 10.18},
"TO": {-21.1347, -175.2083},
"TR": {39.93, 32.85},
"TT": {10.6667, -61.5167},
"TV": {-8.5243, 179.1942},
"TZ": {-6.8, 39.2833},
"UA": {50.45, 30.5236},
"UG": {0.3136, 32.5811},
"US": {38.9047, -77.0163},
"UY": {-34.8667, -56.1667},
"UZ": {41.3, 69.2667},
"VA": {41.9033, 12.4534},
"VC": {13.1667, -61.2333},
"VE": {10.5, -66.9333},
"VG": {18.4167, -64.6167},
"VI": {18.3419, -64.9332},
"VN": {21.0245, 105.8412},
"VU": {-17.7333, 168.3167},
"WF": {-13.2825, -176.1736},
"WS": {-13.8333, -171.8333},
"XG": {31.5069, 34.456},
"XK": {42.6633, 21.1622},
"XR": {78.2167, 15.6333},
"XW": {31.7764, 35.2269},
"YE": {15.35, 44.2},
"YT": {-12.7871, 45.275},
"ZA": {-25.7464, 28.1881},
"ZM": {-15.4167, 28.2833},
"ZW": {-17.8292, 31.0522},
}

View File

@@ -9,7 +9,7 @@
"pluginName": "Prometheus"
}
],
"__elements": [],
"__elements": {},
"__requires": [
{
"type": "panel",
@@ -21,7 +21,7 @@
"type": "grafana",
"id": "grafana",
"name": "Grafana",
"version": "8.3.6"
"version": "9.3.6"
},
{
"type": "panel",
@@ -58,7 +58,10 @@
"list": [
{
"builtIn": 1,
"datasource": "-- Grafana --",
"datasource": {
"type": "datasource",
"uid": "grafana"
},
"enable": true,
"hide": true,
"iconColor": "rgba(0, 211, 255, 1)",
@@ -73,13 +76,12 @@
}
]
},
"description": "Dashboard for endlessh",
"editable": true,
"description": "Dashboard for endlessh (Update variables on time range changes)",
"editable": false,
"fiscalYearStartMonth": 0,
"gnetId": 15156,
"graphTooltip": 0,
"id": null,
"iteration": 1645482521172,
"links": [
{
"asDropdown": false,
@@ -153,7 +155,7 @@
"text": {},
"textMode": "auto"
},
"pluginVersion": "8.3.6",
"pluginVersion": "9.3.6",
"targets": [
{
"datasource": {
@@ -277,7 +279,7 @@
"text": {},
"textMode": "auto"
},
"pluginVersion": "8.3.6",
"pluginVersion": "9.3.6",
"targets": [
{
"datasource": {
@@ -402,7 +404,7 @@
"text": {},
"textMode": "auto"
},
"pluginVersion": "8.3.6",
"pluginVersion": "9.3.6",
"targets": [
{
"datasource": {
@@ -465,7 +467,7 @@
"text": {},
"textMode": "auto"
},
"pluginVersion": "8.3.6",
"pluginVersion": "9.3.6",
"targets": [
{
"datasource": {
@@ -578,7 +580,7 @@
"text": {},
"textMode": "value"
},
"pluginVersion": "8.3.6",
"pluginVersion": "9.3.6",
"targets": [
{
"datasource": {
@@ -722,7 +724,7 @@
"text": {},
"textMode": "auto"
},
"pluginVersion": "8.3.6",
"pluginVersion": "9.3.6",
"targets": [
{
"datasource": {
@@ -751,6 +753,8 @@
"mode": "palette-classic"
},
"custom": {
"axisCenteredZero": false,
"axisColorMode": "text",
"axisLabel": "",
"axisPlacement": "auto",
"barAlignment": 0,
@@ -802,15 +806,21 @@
"options": {
"legend": {
"calcs": [],
"displayMode": "hidden",
"placement": "bottom"
"displayMode": "list",
"placement": "bottom",
"showLegend": false
},
"tooltip": {
"mode": "single"
"mode": "single",
"sort": "none"
}
},
"targets": [
{
"datasource": {
"type": "datasource",
"uid": "-- Dashboard --"
},
"panelId": 20,
"refId": "A"
}
@@ -851,6 +861,7 @@
"legend": {
"displayMode": "table",
"placement": "right",
"showLegend": true,
"values": [
"value",
"percent"
@@ -865,7 +876,8 @@
"values": false
},
"tooltip": {
"mode": "single"
"mode": "single",
"sort": "none"
}
},
"targets": [
@@ -961,6 +973,13 @@
"color": {
"mode": "continuous-GrYlRd"
},
"custom": {
"hideFrom": {
"legend": false,
"tooltip": false,
"viz": false
}
},
"mappings": [],
"thresholds": {
"mode": "absolute",
@@ -992,6 +1011,7 @@
"mouseWheelZoom": false,
"showAttribution": false,
"showDebug": false,
"showMeasure": false,
"showScale": false,
"showZoom": true
},
@@ -1037,14 +1057,18 @@
"type": "markers"
}
],
"tooltip": {
"mode": "details"
},
"view": {
"allLayers": true,
"id": "zero",
"lat": 0,
"lon": 0,
"zoom": 1
}
},
"pluginVersion": "8.3.6",
"pluginVersion": "9.3.6",
"targets": [
{
"datasource": {
@@ -1139,6 +1163,7 @@
"align": "auto",
"displayMode": "auto",
"filterable": true,
"inspect": false,
"minWidth": 50
},
"links": [],
@@ -1230,7 +1255,7 @@
}
]
},
"pluginVersion": "8.3.6",
"pluginVersion": "9.3.6",
"targets": [
{
"datasource": {
@@ -1421,7 +1446,7 @@
}
],
"refresh": "",
"schemaVersion": 34,
"schemaVersion": 37,
"style": "dark",
"tags": [
"prometheus"
@@ -1446,7 +1471,7 @@
"query": "label_values(endlessh_client_open_count_total, job)",
"refId": "StandardVariableQuery"
},
"refresh": 1,
"refresh": 2,
"regex": "",
"skipUrlSync": false,
"sort": 1,
@@ -1470,7 +1495,7 @@
"query": "label_values(endlessh_client_open_count_total{job=~\"$job\"}, instance)",
"refId": "StandardVariableQuery"
},
"refresh": 1,
"refresh": 2,
"regex": "",
"skipUrlSync": false,
"sort": 1,
@@ -1486,6 +1511,6 @@
"timezone": "",
"title": "Endlessh",
"uid": "ATIxYkO7k",
"version": 8,
"version": 10,
"weekStart": ""
}

View File

@@ -1,4 +1,4 @@
// Copyright (C) 2021 Shizun Ge
// Copyright (C) 2021-2023 Shizun Ge
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
@@ -24,6 +24,8 @@ import (
"net/http"
"strings"
"endlessh-go/coordinates"
"github.com/oschwald/geoip2-golang"
"github.com/pierrre/geohash"
)
@@ -53,45 +55,6 @@ func composeCountry(country string) string {
return country
}
type freegeoip struct {
Ip string `json:"ip"`
CountryCode string `json:"country_code"`
CountryName string `json:"country_name"`
RegionCode string `json:"region_code"`
RegionName string `json:"region_name"`
City string `json:"city"`
Zipcode string `json:"zipcode"`
Latitude float64 `json:"latitude"`
Longitude float64 `json:"longitude"`
MetroCode int `json:"metro_code"`
AreaCode int `json:"area_code"`
}
func geohashAndLocationFromFreegeoip(address string) (string, string, string, error) {
var geo freegeoip
response, err := http.Get("https://freegeoip.live/json/" + address)
if err != nil {
return "s000", "Unknown", "Unknown", err
}
defer response.Body.Close()
body, err := ioutil.ReadAll(response.Body)
if err != nil {
return "s000", "Unknown", "Unknown", err
}
err = json.Unmarshal(body, &geo)
if err != nil {
return "s000", "Unknown", "Unknown", err
}
gh := geohash.EncodeAuto(geo.Latitude, geo.Longitude)
country := composeCountry(geo.CountryName)
location := composeLocation(geo.CountryName, geo.RegionName, geo.City)
return gh, country, location, nil
}
type ipapi struct {
Status string `json:"status"`
Message string `json:"message"`
@@ -143,13 +106,31 @@ func geohashAndLocationFromMaxMindDb(address string) (string, string, string, er
defer db.Close()
// If you are using strings that may be invalid, check that ip is not nil
ip := net.ParseIP(address)
record, err := db.City(ip)
cityRecord, err := db.City(ip)
if err != nil {
return "s000", "Unknown", "Unknown", err
}
gh := geohash.EncodeAuto(record.Location.Latitude, record.Location.Longitude)
country := composeCountry(record.Country.Names["en"])
location := composeLocation(record.Country.Names["en"], "", record.City.Names["en"])
countryName := cityRecord.Country.Names["en"]
cityName := cityRecord.City.Names["en"]
latitude := cityRecord.Location.Latitude
longitude := cityRecord.Location.Longitude
iso := cityRecord.Country.IsoCode
if latitude == 0 && longitude == 0 {
// In case of using Country DB, city is not available.
loc, ok := coordinates.Country[iso]
if ok {
latitude = loc.Latitude
longitude = loc.Longitude
} else {
if iso != "" {
// For debugging, adding the iso to the country name.
countryName = countryName + " (" + iso + ")"
}
}
}
gh := geohash.EncodeAuto(latitude, longitude)
country := composeCountry(countryName)
location := composeLocation(countryName, "", cityName)
return gh, country, location, nil
}
@@ -160,8 +141,6 @@ func geohashAndLocation(address string, geoipSupplier string) (string, string, s
return "s000", "Geohash off", "Geohash off", nil
case "ip-api":
return geohashAndLocationFromIpapi(address)
case "freegeoip":
return geohashAndLocationFromFreegeoip(address)
case "max-mind-db":
return geohashAndLocationFromMaxMindDb(address)
default:

6
go.mod
View File

@@ -1,12 +1,12 @@
module endlessh-go
go 1.18
go 1.20
require (
github.com/golang/glog v1.0.0
github.com/oschwald/geoip2-golang v1.8.0
github.com/pierrre/geohash v1.1.0
github.com/prometheus/client_golang v1.13.0
github.com/prometheus/client_golang v1.14.0
)
require (
@@ -15,7 +15,7 @@ require (
github.com/golang/protobuf v1.5.2 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
github.com/oschwald/maxminddb-golang v1.10.0 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/client_model v0.3.0 // indirect
github.com/prometheus/common v0.37.0 // indirect
github.com/prometheus/procfs v0.8.0 // indirect
golang.org/x/sys v0.0.0-20220804214406-8e32c043e418 // indirect

7
go.sum
View File

@@ -176,13 +176,14 @@ github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5Fsn
github.com/prometheus/client_golang v1.7.1/go.mod h1:PY5Wy2awLA44sXw4AOSfFBetzPP4j5+D6mVACh+pe2M=
github.com/prometheus/client_golang v1.11.0/go.mod h1:Z6t4BnS23TR94PD6BsDNk8yVqroYurpAkEiz0P2BEV0=
github.com/prometheus/client_golang v1.12.1/go.mod h1:3Z9XVyYiZYEO+YQWt3RD2R3jrbd179Rt297l4aS6nDY=
github.com/prometheus/client_golang v1.13.0 h1:b71QUfeo5M8gq2+evJdTPfZhYMAU0uKPkyPJ7TPsloU=
github.com/prometheus/client_golang v1.13.0/go.mod h1:vTeo+zgvILHsnnj/39Ou/1fPN5nJFOEMgftOUOmlvYQ=
github.com/prometheus/client_golang v1.14.0 h1:nJdhIvne2eSX/XRAFV9PcvFFRbrjbcTUj0VP62TMhnw=
github.com/prometheus/client_golang v1.14.0/go.mod h1:8vpkKitgIVNcqrRBWh1C4TIUQgYNtG/XQE4E/Zae36Y=
github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=
github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
github.com/prometheus/client_model v0.2.0 h1:uq5h0d+GuxiXLJLNABMgp2qUWDPiLvgCzz2dUR+/W/M=
github.com/prometheus/client_model v0.2.0/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
github.com/prometheus/client_model v0.3.0 h1:UBgGFHqYdG/TPFD1B1ogZywDqEkwp3fBMvqdiQ7Xew4=
github.com/prometheus/client_model v0.3.0/go.mod h1:LDGWKZIo7rky3hgvBe+caln+Dr3dPggB5dvjtD7w9+w=
github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4=
github.com/prometheus/common v0.10.0/go.mod h1:Tlit/dnDKsSWFlCLTWaA1cyBgKHSMdTB80sz/V91rCo=
github.com/prometheus/common v0.26.0/go.mod h1:M7rCNAaPfAosfx8veZJCuw84e35h3Cfd9VFqTh1DIvc=

View File

@@ -1,4 +1,4 @@
// Copyright (C) 2021 Shizun Ge
// Copyright (C) 2021-2023 Shizun Ge
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
@@ -115,7 +115,7 @@ func main() {
prometheusHost := flag.String("prometheus_host", "0.0.0.0", "The address for prometheus")
prometheusPort := flag.String("prometheus_port", "2112", "The port for prometheus")
prometheusEntry := flag.String("prometheus_entry", "metrics", "Entry point for prometheus")
geoipSupplier := flag.String("geoip_supplier", "off", "Supplier to obtain Geohash of IPs. Possible values are \"off\", \"ip-api\", \"freegeoip\", \"max-mind-db\"")
geoipSupplier := flag.String("geoip_supplier", "off", "Supplier to obtain Geohash of IPs. Possible values are \"off\", \"ip-api\", \"max-mind-db\"")
maxMindDbFileName = flag.String("max_mind_db", "", "Path to the MaxMind DB file.")
flag.Usage = func() {