From 963faf46271e01457779e76e83c9158592663857 Mon Sep 17 00:00:00 2001 From: Vincent Riquer Date: Wed, 26 Nov 2014 11:24:25 +0100 Subject: [PATCH 1/3] Add Missions completed --- add | 14 +++++++++++++ add.html | 1 + dsaddtor.pl | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++ index | 25 +---------------------- lib/globals | 27 ++++++++++++++++++++++++ settings | 2 ++ 6 files changed, 104 insertions(+), 24 deletions(-) create mode 100755 dsaddtor.pl diff --git a/add b/add index a7ba04e..753e013 100755 --- a/add +++ b/add @@ -59,6 +59,20 @@ else exit fi +while read ds junk +do + ds="${ds//ds[/}" + ds="${ds//]*/}" + datasets+=("$ds") +done < <(rrdtool info ingress.rrd |grep index) +for ds in ${dsnames[@]} +do + if [[ ! ${datasets[@]} =~ $ds ]] + then + cp -f ingress.rrd ingress.rrd.bak_add_$ds + ./dsaddtor.pl ingress.rrd $ds GAUGE $((48*60*60)) 0 NaN + fi +done data=N for dsname in "${dsnames[@]}" do diff --git a/add.html b/add.html index d74c359..565f39e 100755 --- a/add.html +++ b/add.html @@ -67,6 +67,7 @@ then DS:Link_Length_x_Days:GAUGE:$((48*60*60)):0:NaN \ DS:Field_Held:GAUGE:$((48*60*60)):0:NaN \ DS:Field_x_Days:GAUGE:$((48*60*60)):0:NaN \ + DS:Mercenary:GAUGE:$((48*60*60)):0:NaN \ RRA:HWPREDICT:8760:8e-1:8e-1:$((24)) \ RRA:AVERAGE:99e-2:1:$((24*15)) \ RRA:MAX:99e-2:1:$((24*15)) \ diff --git a/dsaddtor.pl b/dsaddtor.pl new file mode 100755 index 0000000..051bd9c --- /dev/null +++ b/dsaddtor.pl @@ -0,0 +1,59 @@ +#!/usr/bin/perl + +# dsaddtor.pl, Program to add datasources to an existing RRD +# +# Copyright (C) 2010 R. Sandevoir remi.sandevoir(at)gmail.com +# +# 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 + +use strict; +use warnings; + +use RRD::Simple (); + +my $rrdfile = shift || &Usage; +if ($rrdfile eq '-h') { + &Usage; + exit 0; +} + +my $name = shift || &Usage; +my $type = shift || 'COUNTER'; +my $heartbeat = shift || '600'; +my $min = shift || 'NaN'; +my $max = shift || 'NaN'; + +my $rrd = RRD::Simple->new( + file => $rrdfile, + rrdtool => "/usr/bin/rrdtool", +); + +print "Adding DS $name on $rrdfile\n"; +$rrd->add_source($rrdfile, $name => $type); + +print "Heartbeat : $heartbeat\nMinimum value : $min\nMaximum value : $max\n"; +RRDs::tune ($rrdfile, "-h","$name:$heartbeat"); +RRDs::tune ($rrdfile, "-i","$name:$min"); +RRDs::tune ($rrdfile, "-a","$name:$max"); + +sub Usage { + print "dsaddtor.pl [type] [heartbeat] [rrdmin] [rrdmax]\n"; + print "\t\tSource RRD file\n"; + print "\t\tDatasource name to add\n"; + print "\t[type]\t\tType of datasource (i.e. COUNTER, GAUGE...). Default : COUNTER\n"; + print "\t[heartbeat]\tLength of time in seconds before RRD thinks your DS is dead. Default : 600\n"; + print "\t[rrdmin]\tMinimum value allowed for each datasource. Default : NaN\n"; + print "\t[rrdmax]\tMax value allowed for each datasource. Default : NaN\n"; + exit 0 +} diff --git a/index b/index index 48574d2..90b5b2a 100755 --- a/index +++ b/index @@ -331,30 +331,7 @@ then if (( show_all )) then stats=( - AP - Explorer - Seer - XM - Hacker - Builder - Connector - Mind_Controller - MU - Longest_Link - Largest_Field - Recharger - Liberator - Pioneer - Purifier - Neutralized - Links_Destroyed - Fields_Destroyed - Walked - Guardian - Link_Maintained - Link_Length_x_Days - Field_Held - Field_x_Days + "${dsnames[@]}" ) else stats=( diff --git a/lib/globals b/lib/globals index c45e2a4..f4eb12f 100644 --- a/lib/globals +++ b/lib/globals @@ -34,3 +34,30 @@ declare \ start \ end \ +want_ds=( + AP + Explorer + Seer + XM + Hacker + Builder + Connector + Mind_Controller + MU + Longest_Link + Largest_Field + Recharger + Liberator + Pioneer + Purifier + Neutralized + Links_Destroyed + Fields_Destroyed + Walked + Guardian + Link_Maintained + Link_Length_x_Days + Field_Held + Field_x_Days + Mercenary +) diff --git a/settings b/settings index 14ac58f..0e3309b 100644 --- a/settings +++ b/settings @@ -60,6 +60,7 @@ uinames=( "Max Link Length x Days" "Max Time Field Held" "Largest Field MUs x Days" + "Unique missions completed" ) dsnames=( AP @@ -86,6 +87,7 @@ dsnames=( Link_Length_x_Days Field_Held Field_x_Days + Mercenary ) medals=( Explorer From 337014794bc22cf779f22ae9706c93d0de853815 Mon Sep 17 00:00:00 2001 From: Vincent Riquer Date: Wed, 26 Nov 2014 11:25:42 +0100 Subject: [PATCH 2/3] Add Innovator --- add | 2 ++ add.html | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ lib/medals | 41 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 99 insertions(+) diff --git a/add b/add index 753e013..5761467 100755 --- a/add +++ b/add @@ -79,6 +79,8 @@ do data+=:${POST["$dsname"]:=U} echo "$dsname....${POST["$dsname"]}" done + +echo ${POST["innovator"]} > .innovator rrdtool update ingress.rrd "$data" if [ -n "$CACHE_DIR" ] diff --git a/add.html b/add.html index 565f39e..95a15aa 100755 --- a/add.html +++ b/add.html @@ -95,6 +95,62 @@ cat <<-EOHTML
    EOHTML +case $innovator in + 1) + echo "
  • No Innovator medal
  • " + echo "
  • Innovator Bronze
  • " + echo "
  • Innovator Silver
  • " + echo "
  • Innovator Gold
  • " + echo "
  • Innovator Platinum
  • " + echo "
  • Innovator Onyx
  • " + ;; + 2) + echo "
  • No Innovator medal
  • " + echo "
  • Innovator Bronze
  • " + echo "
  • Innovator Silver
  • " + echo "
  • Innovator Gold
  • " + echo "
  • Innovator Platinum
  • " + echo "
  • Innovator Onyx
  • " + ;; + 3) + echo "
  • No Innovator medal
  • " + echo "
  • Innovator Bronze
  • " + echo "
  • Innovator Silver
  • " + echo "
  • Innovator Gold
  • " + echo "
  • Innovator Platinum
  • " + echo "
  • Innovator Onyx
  • " + ;; + 4) + echo "
  • No Innovator medal
  • " + echo "
  • Innovator Bronze
  • " + echo "
  • Innovator Silver
  • " + echo "
  • Innovator Gold
  • " + echo "
  • Innovator Platinum
  • " + echo "
  • Innovator Onyx
  • " + ;; + 5) + echo "
  • No Innovator medal
  • " + echo "
  • Innovator Bronze
  • " + echo "
  • Innovator Silver
  • " + echo "
  • Innovator Gold
  • " + echo "
  • Innovator Platinum
  • " + echo "
  • Innovator Onyx
  • " + ;; + 0) + echo "
  • No Innovator medal
  • " + echo "
  • Innovator Bronze
  • " + echo "
  • Innovator Silver
  • " + echo "
  • Innovator Gold
  • " + echo "
  • Innovator Platinum
  • " + echo "
  • Innovator Onyx
  • " + ;; +esac + +cat <<-EOHTML +
+
    +EOHTML + for indice in ${!uinames[@]} do echo "
  • ${uinames[indice]}
  • " diff --git a/lib/medals b/lib/medals index d96a712..d6d4131 100644 --- a/lib/medals +++ b/lib/medals @@ -4,6 +4,47 @@ medals() { local \ stat \ + if [[ -f .innovator ]] + then + innovator=$(<.innovator) + else + innovator=0 + fi + if (( innovator >= 1 )) + then + (( bronzecount++ )) + bronzes+=( innovator ) + else + nosilver["Innovator"]=1 + fi + if (( innovator >= 2 )) + then + (( silvercount++ )) + silvers+=( innovator ) + else + nobronze["Innovator"]=1 + fi + if (( innovator >= 3 )) + then + (( goldcount++ )) + golds+=( innovator ) + else + nogold["Innovator"]=1 + fi + if (( innovator >= 4 )) + then + (( platinumcount++ )) + platinums+=( innovator ) + else + noplatinum["Innovator"]=1 + fi + if (( innovator == 5 )) + then + (( blackcount++ )) + blacks+=( innovator ) + else + noblack["Innovator"]=1 + fi for stat in "${medals[@]}" do if (( last["$stat"] >= bronze["$stat"] )) From a7b970f39b06cd36785d75860ba312298c724c4f Mon Sep 17 00:00:00 2001 From: Vincent Riquer Date: Wed, 26 Nov 2014 11:26:13 +0100 Subject: [PATCH 3/3] Import from ingress-stats --- add.html | 18 +++- import | 252 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ index | 36 +++++++- 3 files changed, 303 insertions(+), 3 deletions(-) create mode 100755 import diff --git a/add.html b/add.html index 95a15aa..c19ab32 100755 --- a/add.html +++ b/add.html @@ -220,7 +220,23 @@ cat <<-EOHTML - Add data + + + + + + + + + + + EOHTML diff --git a/import b/import new file mode 100755 index 0000000..1950c7a --- /dev/null +++ b/import @@ -0,0 +1,252 @@ +#!/bin/bash + +# IngRRD (https://forge.riquer.fr/p/ingrrd/) +# Copyright (C) 2014 Vincent Riquer +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero 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 Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +. settings + +for lib in lib/* +do + source $lib +done +read_query_string + +if [[ $REQUEST_METHOD == POST ]] +then +# refresh: 0,url=/cgi/$webuser/?start=${POST["start"]}&end=${POST["end"]} + cat <<-EOHead + Content-type: text/plain + Last-Modified: $(LC_ALL=C TZ=GMT date +'%a, %d %b %Y %X %Z') + Expires: $(LC_ALL=C TZ=GMT date +'%a, %d %b %Y %X %Z') + + EOHead + if [[ $webuser == $AUTH_USER || $webuser == dev ]] + then + echo "Welcome agent $webuser"$'!\n\n' + else + echo 'Nice try!' + exit + fi + + while read ds junk + do + ds="${ds//ds[/}" + ds="${ds//]*/}" + datasets+=("$ds") + done < <(rrdtool info ingress.rrd |grep index) + for ds in ${dsnames[@]} + do + if [[ ! ${datasets[@]} =~ $ds ]] + then + cp -f ingress.rrd ingress.rrd.bak_add_$ds + ./dsaddtor.pl ingress.rrd $ds GAUGE $((48*60*60)) 0 NaN + fi + done + + declare -A POST + exprdsname='^[[:upper:][:lower:]_]+$' + while read dsname value + do + if [[ $dsname =~ $exprdsname ]] + then + POST["$dsname"]="$value" + fi + done < <( + sed 's/&/\n/g;s/=/ /g' + ) + POST["data"]="${POST["data"]//%0D%0A/ +}" + POST["data"]="${POST["data"]//%3A/:}" + POST["data"]="${POST["data"]//+/ }" + echo "${POST["data"]}" + while read date hour data + do + data=$(date -d "$date $hour" +%s):${data// /:} + rrdtool update ingress.rrd "$data" 2>&1 + done <<<"${POST["data"]}" + + if [ -n "$CACHE_DIR" ] + then + find "$CACHE_DIR" -type f -delete + echo $'\nCache cleared!' + fi +else + cat <<-EOHTML + content-type: text/xml + Last-Modified: $(LC_ALL=C TZ=GMT date +'%a, %d %b %Y %X %Z') + Expires: $(LC_ALL=C TZ=GMT date +'%a, %d %b %Y %X %Z') + + + + + + IngRRD - $webuser - Import Data + + + +
    + EOHTML + if ! [ -w "$rrdfile" ] + then + rrdtool create ingress.rrd -s $((60*60)) \ + DS:AP:GAUGE:$((2*24*60*60)):0:NaN \ + DS:Explorer:GAUGE:$((48*60*60)):0:NaN \ + DS:Seer:GAUGE:$((48*60*60)):0:NaN \ + DS:XM:GAUGE:$((48*60*60)):0:NaN \ + DS:Hacker:GAUGE:$((48*60*60)):0:NaN \ + DS:Builder:GAUGE:$((48*60*60)):0:NaN \ + DS:Connector:GAUGE:$((48*60*60)):0:NaN \ + DS:Mind_Controller:GAUGE:$((48*60*60)):0:NaN \ + DS:MU:GAUGE:$((48*60*60)):0:NaN \ + DS:Longest_Link:GAUGE:$((48*60*60)):0:NaN \ + DS:Largest_Field:GAUGE:$((48*60*60)):0:NaN \ + DS:Recharger:GAUGE:$((48*60*60)):0:NaN \ + DS:Liberator:GAUGE:$((48*60*60)):0:NaN \ + DS:Pioneer:GAUGE:$((48*60*60)):0:NaN \ + DS:Purifier:GAUGE:$((48*60*60)):0:NaN \ + DS:Neutralized:GAUGE:$((48*60*60)):0:NaN \ + DS:Links_Destroyed:GAUGE:$((48*60*60)):0:NaN \ + DS:Fields_Destroyed:GAUGE:$((48*60*60)):0:NaN \ + DS:Walked:GAUGE:$((48*60*60)):0:NaN \ + DS:Guardian:GAUGE:$((48*60*60)):0:NaN \ + DS:Link_Maintained:GAUGE:$((48*60*60)):0:NaN \ + DS:Link_Length_x_Days:GAUGE:$((48*60*60)):0:NaN \ + DS:Field_Held:GAUGE:$((48*60*60)):0:NaN \ + DS:Field_x_Days:GAUGE:$((48*60*60)):0:NaN \ + DS:Mercenary:GAUGE:$((48*60*60)):0:NaN \ + RRA:HWPREDICT:8760:8e-1:8e-1:$((24)) \ + RRA:AVERAGE:99e-2:1:$((24*15)) \ + RRA:MAX:99e-2:1:$((24*15)) \ + RRA:AVERAGE:99e-2:4:$((24*180)) \ + RRA:MAX:99e-2:4:$((24*180)) \ + RRA:AVERAGE:99e-2:24:$(((4*365)+1)) \ + RRA:MAX:99e-2:24:$(((4*365)+1)) \ + RRA:AVERAGE:99e-2:$((24*30)):$(((32*365)+8)) \ + RRA:MAX:99e-2:$((24*30)):$(((32*365)+8)) \ + || { + cat <<-EOHTML +

    Cannot create $rrdfile

    + + + EOHTML + exit + } + fi + readlast + medals + get_current_level + cat <<-EOHTML +
    +

    Import data from e.g. https://www.agent-stats.com/
    + Expected format: YYYY-MM-DD hh:mm:ss AP Explorer Seer XM Hacker + Builder Connector Mind_Controller MU Longest_Link Largest_Field + Recharger Liberator Pioneer Purifier Neutralized Links_Destroyed + Fields_Destroyed Walked Guardian Link_Maintained + Link_Length_x_Days Field_Held Field_x_Days + Mercenary

    +
    + + +