Cet article présente l’installation d’une stack TICK
permettant d’aggréger des métriques d’un ou plusieurs système, puis de les publier sur un dashboard.
influxdb ./dok.sh enter influxdb influx
1 jour = 65 MB
telegraf
10150 wget https://dl.influxdata.com/telegraf/releases/telegraf-1.1.2_linux_amd64.tar.gzntar xvfz telegraf-1.1.2_linux_amd64.tar.gz
grafana
Connecteurs
Docker
SELECT "total_rss" / (1024*1024) FROM "docker_container_mem" WHERE "host" = 'jupiter' AND $timeFilter GROUP BY "container_name"
SELECT "usage_percent" FROM "docker_container_cpu" WHERE $timeFilter GROUP BY "container_name"
HDDTemp
SMTP
10380 snmpwalk -Os -c public -v1 192.168.8.1 1.3.6.1.2.1.25.1.1.0
Plex
Obtenir un token permanent :
La documentation stipule :
Do a HTTP POST request to https://plex.tv/users/sign_in.json (or https://plex.tv/users/sign_in.xml) with:
user[login] and user[password] form values in the body. For example: user%5Blogin%5D=plexusername&user%5Bpassword%5D=myplexpassword
HTTP header: X-Plex-Client-Identifier: a unique value for your client
HTTP header: X-Plex-Product: the name of your client
HTTP header: X-Plex-Version: the version of your client
Script (à exécuter une seule fois pour avoir un token permanent)
CLIENT_IDENTIFIER=$(uuidgen)
CLIENT_NAME="PLEX-API-CLIENT"
CLIENT_VERSION="1.0.0"
PLEX_USERNAME="sr-g"
PLEX_PASSWORD='mon_password_plex'
curl -X POST \
-u "${PLEX_USERNAME}:${PLEX_PASSWORD}" \
-H "Content-Type: application/xml; charset=utf-8" \
-H "Content-Length: 0" \
-H "X-Plex-Client-Identifier: $CLIENT_IDENTIFIER" \
-H "X-Plex-Product: $CLIENT_NAME" \
-H "X-Plex-Version: $CLIENT_VERSION" \
https://plex.tv/users/sign_in.xml
Le résultat est de la forme :
<?xml version="1.0" encoding="UTF-8"?>
<user email="serge.simon@gmail.com" id="2081414" uuid="2dabe9473fd4d5c5" mailing_list_status="active" thumb="https://plex.tv/users/2dabe9473fd4d5c5/avatar" username="SR-G" title="SR-G" cloudSyncDevice="" locale="" authenticationToken="MzWZxBTaHUqETWwxcsSM" authToken="MzWZxBTaHUqETWwxcsSM" scrobbleTypes="" pin="0f5016991b0c52150bb126b728333583bd1355af502ad8df27ef0f837136190f" restricted="0" home="1" guest="0" queueEmail="queue+ypYthYdYLokcgNCUWHCX@save.plex.tv" queueUid="37c506e6b9001561" homeSize="1" rememberMe="false" secure="1" certificateVersion="2">
<entitlements all="0">
</entitlements>
<profile_settings default_audio_language="fr" default_subtitle_language="fr" auto_select_subtitle="1" auto_select_audio="1"/>
<username>SR-G</username>
<email>serge.simon@gmail.com</email>
<joined-at type="datetime">2014-02-17 00:27:57 UTC</joined-at>
<authentication-token>MzWZxBTaHUqETWwxcsSM</authentication-token>
</user>
Ensuite il est possible de tester l’URL qui donne les sessions PLEX ainsi (format XML) :
curl 'http://192.168.8.4:32400/status/sessions?X-Plex-Token=MzWZxBTaHUqETWwxcsSM'
Et ainsi (format JSON, sera utilisé par Telegraf) :
curl -H "Accept: application/json" 'http://192.168.8.4:32400/status/sessions?X-Plex-Token=MzWZxBTaHUqETWwxcsSM'
Ou :
# http://192.168.8.4:32400/clients?X-Plex-Token=MzWZxBTaHUqETWwxcsSM'
# curl 'ws://localhost:32400/:/websockets/notifications?X-Plex-Token=MzWZxBTaHUqETWwxcsSM'
Résultat :
<?xml version="1.0" encoding="UTF-8"?>
<MediaContainer size="1">
<Video addedAt="1458423319" art="/library/metadata/75109/art/1472505851" contentRating="TV-PG" duration="1462315" grandparentArt="/library/metadata/75109/art/1472505851" grandparentKey="/library/metadata/75109" grandparentRatingKey="75109" grandparentTheme="/library/metadata/75109/theme/1472505851" grandparentThumb="/library/metadata/75109/thumb/1472505851" grandparentTitle="Star Wars - The Clone Wars" guid="com.plexapp.agents.thetvdb://83268/1/2?lang=fr" index="2" key="/library/metadata/75134" librarySectionID="13" originallyAvailableAt="2008-10-03" parentIndex="1" parentKey="/library/metadata/75131" parentRatingKey="75131" parentThumb="/library/metadata/75131/thumb/1472505851" rating="7.2" ratingKey="75134" sessionKey="16" summary=""La foi n'est pas une affaire de choix, mais de conviction."

Le maître jedi Plo Koon et ses hommes sont pris à parti par une nouvelle arme Séparatiste dévastatrice. Ils subissent de lourdes pertes mais ne peuvent battre en retraite. Ils sont tenus de résister jusqu'à l'arrivée d'Anakin et Ahsoka. Mais ces derniers ont du mal à localiser le malheureux Plo Koon..." thumb="/library/metadata/75134/thumb/1472505901" title="L'aube du Malveillant" type="episode" updatedAt="1472505901" viewOffset="5442" year="2008">
<Media aspectRatio="2.35" audioChannels="6" audioCodec="aac" audioProfile="he-aac" bitrate="1615" container="mkv" duration="1462315" height="816" id="68900" videoCodec="hevc" videoFrameRate="24p" videoProfile="main 10" videoResolution="1080" width="1920">
<Part audioProfile="he-aac" container="mkv" deepAnalysisVersion="2" duration="1462315" file="/data1/series-comics/[Star Wars] - The Clone Wars/Star Wars - The Clone Wars, Saison 1/Star.Wars.The.Clone.Wars.S01E02.Rising.Malevolence.MULTi.1080p.BluRay.x265.HEVC-Djona12.mkv" id="70024" key="/library/parts/70024/1458423319/file.mkv" requiredBandwidths="6282,4123,1864,1864,1864,1864,1864,1864" size="295133995" videoProfile="main 10">
<Stream bitDepth="10" bitrate="1615" chromaSubsampling="4:2:0" codec="hevc" codecID="V_MPEGH/ISO/HEVC" colorRange="tv" default="1" duration="1462296" frameRate="23.976" frameRateMode="cfr" height="816" id="99246" index="0" level="120" pixelFormat="yuv420p10" profile="main 10" refFrames="1" requiredBandwidths="5897,3739,1382,1382,1382,1382,1382,1382" streamType="1" title="Star Wars The Clone Wars S01E02" width="1920" />
<Stream audioChannelLayout="5.1" channels="6" codec="aac" codecID="A_AAC" duration="1462315" id="99247" index="1" language="English" languageCode="eng" profile="he-aacv2 / he-aac / lc" requiredBandwidths="192,192,192,192,192,192,192,192" samplingRate="48000" streamType="2" title="VO Surround" />
<Stream audioChannelLayout="5.1" channels="6" codec="aac" codecID="A_AAC" duration="1462315" id="99248" index="2" language="Français" languageCode="fre" profile="he-aac / lc" requiredBandwidths="192,192,192,192,192,192,192,192" samplingRate="48000" selected="1" streamType="2" title="VFF Surround" />
<Stream codec="pgs" codecID="S_HDMV/PGS" format="pgs" id="99249" index="3" language="English" languageCode="eng" requiredBandwidths="92,92,92,92,92,92,92,92" streamType="3" title="Subtitles" />
<Stream codec="pgs" codecID="S_HDMV/PGS" format="pgs" id="99250" index="4" language="Français" languageCode="fre" requiredBandwidths="93,93,93,93,93,93,93,93" streamType="3" title="Sous-titres" />
</Part>
</Media>
<Director id="65152" tag="Dave Filoni" />
<Writer id="65151" tag="Steven Melching" />
<User id="1" thumb="https://plex.tv/users/2dabe9473fd4d5c5/avatar" title="SR-G" />
<Player address="192.168.8.3" device="Windows" machineIdentifier="89zbewhkpgv1gj5um69h8semi" model="" platform="Vivaldi" platformVersion="1.7" product="Plex Web" profile="Web" state="playing" title="Plex Web (Vivaldi)" vendor="" version="2.12.5" />
<Session id="qlhbadviu9zsgh0i90odsfw2" bandwidth="10500000" location="lan" />
<TranscodeSession key="3blbli8nikfem8rg31plyuv7" throttled="0" complete="0" progress="3.7999999523162842" speed="4.8000001907348633" duration="1462315" remaining="327" context="streaming" videoDecision="transcode" audioDecision="copy" protocol="dash" container="mp4" videoCodec="h264" audioCodec="aac" audioChannels="6" width="1280" height="544" />
</Video>
</MediaContainer>
Il suffit ensuite de mapper la configuration Telegraf avec ces données : déclenchement de l’URL en mode “json”, extraction de la valeur “size” qui contient donc le nombre de flux en cours de diffusion depuis le serveur.
[[inputs.httpjson]]
name = "plex"
servers = [ "http://192.168.8.4:32400/status/sessions?X-Plex-Token=MzWZxBTaHUqETWwxcsSM" ]
response_timeout = "5s"
## HTTP method to use: GET or POST (case-sensitive)
method = "GET"
tag_keys = [ "size" ]
[inputs.httpjson.headers]
Accept = "application/json"
Sous Grafana il suffit ensuite d’ajouter un “SingleStat panel” avec la requête suivante (le nom “MediaContainer_plex” vient de la balise du XML de status auquel est concatané le “name” défini en configuration Telegraf ci-dessus) :
SELECT last("MediaContainer_size") FROM "httpjson_plex" WHERE $timeFilter GROUP BY "host"
Ou visuellement :
Référence : https://denlab.io/setup-a-wicked-grafana-dashboard-to-monitor-practically-anything/